#!/usr/bin/env python # Wenchang Yang (wenchang@princeton.edu) # Wed Sep 18 23:01:01 EDT 2019 #import os.path, sys, os import matplotlib.pyplot as plt import xarray as xr, numpy as np, pandas as pd import geoxarray figname = 'fig.cycle.png' figsize = None#(8,4) savefig = [False, True][1] ylabel = 'mm/day' title = 'Mozambique annual cycle of spatial-mean daily precip' plt.figure(figsize=figsize) # obs label = 'CHIRPS' ifile = 'data/chirps.p05.Mozambique.masked.fldmean.nc' da = xr.open_dataarray(ifile) ts = da.groupby('time.dayofyear').mean('time') ts.plot(label=label, color='k') # flor1860 label = 'FLOR-1860' scale = 24*3600 ifile = 'data/FLOR.CTL1860_newdiag_tigercpu_intelmpi_18_576PE.precip.Mozambique.masked.fldmean.nc' da = xr.open_dataarray(ifile).sel(time=slice('0101', '1000')) ts = da.groupby('time.dayofyear').mean('time').pipe(lambda x: x*scale) ts.plot(label=label) # flor1990 label = 'FLOR-1990' scale = 24*3600 ifile = 'data/FLOR.CTL1990_newdiag_tigercpu_intelmpi_18_576PE.precip.Mozambique.masked.fldmean.nc' da = xr.open_dataarray(ifile).sel(time=slice('0101', '1000')) ts = da.groupby('time.dayofyear').mean('time').pipe(lambda x: x*scale) ts.plot(label=label) plt.legend() if title is not None: plt.title(title) if ylabel is not None: plt.ylabel(ylabel) plt.tight_layout() if savefig: plt.savefig(figname, dpi=128)