#!/usr/bin/env python # Wenchang Yang (wenchang@princeton.edu) # Thu Dec 30 12:45:38 EST 2021 if __name__ == '__main__': import sys from misc.timer import Timer s = ' ' tt = Timer(f'start {s.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 xfilter # if __name__ == '__main__': tt.check('end import') # #start from here #ifile = sys.argv[1] if len(sys.argv)>1 else 'LMR2018_ssttc_rMDRtransformed18702000.nc' ifile = 'LMRseasonal_ssttc_rMDRtransformed18702000.nc' daname = 'HU' n_window = 40 #lowpass cutoff window lowpass = lambda da: da.filter.lowpass(1/n_window, dim='year', padtype='even') ofile = ifile.replace('.nc', f'_{daname}_lp{n_window}.nc') if os.path.exists(ofile): ds = xr.open_dataset(ofile) print('[loaded]:', ofile) else: da = xr.open_dataset(ifile)[daname] attrs = da.attrs da = da.pipe(lowpass) da.attrs = attrs da.attrs['note'] = f'{daname} from {ifile}, lowpass{n_window}' ds = da.to_dataset(name=daname) ds.to_netcdf(ofile) print('[saved]:', ofile) if __name__ == '__main__': from wyconfig import * #my plot settings fig, ax = plt.subplots() da = ds[daname] da.plot() ax.set_title(f'{ifile[:7]} {daname} lowpass{n_window}') #savefig if len(sys.argv)>1 and 'savefig' in sys.argv[1:]: #figname = __file__.replace('.py', f'.png') figname = ofile.replace('.nc', f'.png') wysavefig(figname) tt.check(f'**Done**') plt.show()