#!/usr/bin/env python # Wenchang Yang (wenchang@princeton.edu) # Tue Jun 29 16:14:32 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 import geoxarray from misc.landmask import flagland # if __name__ == '__main__': tt.check('end import') # #start from here if len(sys.argv)>1: ifile = sys.argv[1] else: ifile = 'data_precip_AM2.5C360_amip_5ens_1871-202107.nc' ofile = ifile.replace('.nc', '.masked.nc') if os.path.exists(ofile): print('[exists]', ofile) sys.exit() ds = xr.open_dataset(ifile) #land only landflag = flagland(ds) ds = ds.where(landflag>0.5) #encoding daname = list(ds.data_vars)[0] encoding = {daname: dict(zlib=True, complevel=1)} print('saving...') ds.to_netcdf(ofile, encoding=encoding, unlimited_dims='time') 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()