#!/usr/bin/env python # Wenchang Yang (wenchang@princeton.edu) # Wed May 11 10:45:08 EDT 2022 if __name__ == '__main__': import sys from misc.timer import Timer tt = Timer('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 import salem # if __name__ == '__main__': tt.check('end import') # #start from here ifile = 't_ref_max_FLOR_HistRCP45_tigercpu_intelmpi_18_576PE_5ens_1860-2100_SouthAsia.nc' ofile = ifile.replace('.nc', '_masked.nc') if os.path.exists(ofile): da = xr.open_dataarray(ofile) print('[loaded]:', ofile) else: shapefile = 'mask_version2/mask_shapev2.shp' shdf = salem.read_shapefile(shapefile) da = xr.open_dataarray(ifile) da = da.salem.subset(shape=shdf, margin=1)\ .salem.roi(shape=shdf) print('saving...') da.to_dataset().to_netcdf(ofile) print('[saved]:', ofile) if __name__ == '__main__': from wyconfig import * #my plot settings da.isel(ens=0, time=0).plot() #savefig if len(sys.argv)>1 and 'savefig' in sys.argv[1:]: figname = __file__.replace('.py', f'.png') if 'overwritefig' in sys.argv[1:]: wysavefig(figname, overwritefig=True) else: wysavefig(figname) tt.check(f'**Done**') print() if 'notshowfig' in sys.argv: pass else: plt.show()