#!/usr/bin/env python # Wenchang Yang (wenchang@princeton.edu) # Mon Jul 19 21:37:14 EDT 2021 if __name__ == '__main__': from misc.timer import Timer tt = Timer(f'start {__file__}') import sys, os.path, os, glob, datetime import xarray as xr, numpy as np, pandas as pd, matplotlib.pyplot as plt #more imports # if __name__ == '__main__': tt.check('end import') # #start from here daname = 'precip' maskfile = 'mask_p5_3E7E48N52N.nc' ifile = 'data_precip_FLOR_histRCP45_5ens_1860-2100.nc' ofile = ifile.replace('.nc', '.masked.nc') if os.path.exists(ofile): print('[exists]:', ofile) sys.exit() mask = xr.open_dataarray(maskfile) ds = xr.open_dataset(ifile).where(mask==1) encoding = {daname: dict(zlib=True, complevel=1)} ds.to_netcdf(ofile, encoding=encoding) print('[saved]:', ofile) if __name__ == '__main__': #from wyconfig import * #my plot settings #savefig if 'savefig' in sys.argv: figname = __file__.replace('.py', f'.png') wysavefig(figname) tt.check(f'**Done**') plt.show()