#!/usr/bin/env python # Wenchang Yang (wenchang@princeton.edu) # Fri Aug 5 11:50:49 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 # if __name__ == '__main__': tt.check('end import') # #start from here #ifile = 'era5.2m_temperature.monthly.200001-202204.nc' ifile = 'era5.mx2t.daily.200001-202203.nc' ofile = ifile.replace('.nc', f'.gps_facilities_all.nc') if os.path.exists(ofile): print('[exists]:', ofile) sys.exit() #load data da = xr.open_dataarray(ifile).load() df = pd.read_csv('gps_facilities_all.csv', index_col=0) ds = xr.Dataset(df) #nearest interp #daa = da.sel(longitude=ds.longitude, latitude=ds.latitude, method='nearest') #interp daa = da.interp(longitude=ds.longitude, latitude=ds.latitude) #save data #df['latitude_clim'] = daa.latitude.values #df['longitude_clim'] = daa.longitude.values #df.to_csv(ofile) #ncfile daa.to_dataset().to_netcdf(ofile) print('[saved]:', ofile) #csv file csvfile = ofile.replace('.nc', '.degC.csv') (daa - 273.15).to_pandas().to_csv(csvfile) print('[saved]:', csvfile) if __name__ == '__main__': #from wyconfig import * #my plot settings #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()