#!/usr/bin/env python # Wenchang Yang (wenchang@princeton.edu) # Sun Apr 7 17:00:19 EDT 2024 if __name__ == '__main__': import sys,os from misc.timer import Timer tt = Timer(f'[{os.getcwd()}] start ' + ' '.join(sys.argv)) import sys, os.path, os, glob, datetime import xarray as xr, numpy as np, pandas as pd, matplotlib.pyplot as plt #more imports wython = '/tigress/wenchang/wython' if wython not in sys.path: sys.path.append(wython); print('added to python path:', wython) #from misc import get_kws_from_argv from misc import roll_lon import salem from modelout import get_modelout_data # if __name__ == '__main__': tt.check('end import') # #start from here daname ="""' rh_ref q_ref ps t_ref """.split()[-1] dsname = 'atmos_month' if daname == 'q_ref': dsname = 'atmos_daily' model = 'AM2.5C360' #expname = 'amipHadISSTlong_chancorr_tigercpu_intelmpi_18_1080PE' expname = 'amipHadISSTlong_chancorr_tigercpu_intelmpi_18_1080PE_extend2020' ens = range(1,10+1) #ens = range(6,6+1) years = range(1980,2019+1) if expname.endswith('extend2020'): years = range(2020,2020+1) #shape of the 6 western states shapefile = '/tigress/wenchang/analysis/climate_and_disease/data/US_states/cb_2016_us_state_5m/cb_2016_us_state_5m.shp' dfsh = salem.read_shapefile(shapefile) states = 'CA','NV','AZ','NM','UT','CO' dfsh = dfsh[dfsh['STUSPS'].isin(states)] #data over the selected states def sel_states(da): if daname == 'q_ref' and dsname == 'atmos_daily': #no direct montly q_ref: estimate it from daily data return da.resample(time='MS').mean().rename(grid_xt='lon', grid_yt='lat').pipe(roll_lon).salem.subset(shape=dfsh, margin=1).salem.roi(shape=dfsh) else: return da.rename(grid_xt='lon', grid_yt='lat').pipe(roll_lon).salem.subset(shape=dfsh, margin=1).salem.roi(shape=dfsh) funcname = 'westUS' if __name__ == '__main__': #from wyconfig import * #my plot settings get_modelout_data(daname=daname, model=model, expname=expname, dsname=dsname, ens=ens, years=years, func=sel_states, funcname=funcname) #savefig if 'savefig' in sys.argv or 's' in sys.argv: figname = __file__.replace('.py', f'.png') if 'overwritefig' in sys.argv or 'o' in sys.argv: wysavefig(figname, overwritefig=True) else: wysavefig(figname) tt.check(f'**Done**') print() if 'notshowfig' in sys.argv or 'n' in sys.argv: pass else: if 'plt' in globals(): plt.show()