#!/usr/bin/env python # Wenchang Yang (wenchang@princeton.edu) # Tue Jun 30 21:30:24 EDT 2020 if __name__ == '__main__': from misc.timer import Timer tt = Timer(f'start {__file__}') import sys, os.path, os, glob import xarray as xr, numpy as np, pandas as pd #import matplotlib.pyplot as plt #more imports from misc.landmask import flagland # if __name__ == '__main__': tt.check('end import') # #start from here daname = 'ts' ifile = sys.argv[1] print('[ifile]:', ifile) #ifile = '/tigress/wenchang/data/cmip6/variables/ts/past1000/wy_ens/ts.past1000.0850-1849.ens02.nc' ofile = ifile.replace(f'{daname}.', f'{daname}.ocean.') print('[ofile]:', ofile) if os.path.exists(ofile): print('[exists]:', ofile) sys.exit() nc_encoding = {daname: dict( zlib=True, complevel=1,)} #reading... with xr.open_dataset(ifile) as ds: da = ds[daname] gattrs = ds.attrs landflag = flagland(da) da = da.where(landflag==0) ds_o = da.to_dataset(name=daname) ds_o.attrs = gattrs print('saving...') ds_o.to_netcdf(ofile, encoding=nc_encoding) print('[saved]:', ofile) if __name__ == '__main__': #from wyconfig import * #my plot settings tt.check(f'**Done**')