#!/usr/bin/env python # Wenchang Yang (wenchang@princeton.edu) # Thu Nov 28 10:06:59 PM EST 2024 if __name__ == '__main__': import sys,os try: from misc.timer import Timer tt = Timer(f'[{os.getcwd()}] start ' + ' '.join(sys.argv)) except: pass import sys, os.path, os, glob, datetime import xarray as xr, numpy as np, pandas as pd, matplotlib.pyplot as plt #more imports wython = '/tigress/wenchang/wython' if wython not in sys.path: sys.path.append(wython); print('added to python path:', wython) #from misc import get_kws_from_argv from misc.seasons import sel_season from xtc import wherebasin from misc.landmask import whereocean from geoplots.cartopy.api import cartoproj # if __name__ == '__main__': try: tt.check('end import') except: pass # #start from here #ifile = 'Vshear_HIRAM_amipLMR2019SST0850ic_tigercpu_intelmpi_18_540PE_ens01_0850-1999.nc' #ifile = '/projects/w/wenchang/analysis/TC/HIRAM/amipLMR2019SST0850ic_tigercpu_intelmpi_18_540PE/netcdf/tc_density.seeds.ens01.0850-1999.minohour12.nc' #ifile = '/projects/w/wenchang/analysis/TC/HIRAM/amipLMR2019SST0850ic_tigercpu_intelmpi_18_540PE/netcdf/tc_density.TS30.ens01.0850-1999.nc' ifile = '/projects/w/wenchang/analysis/TC/HIRAM/amipLMR2019SST0850ic_tigercpu_intelmpi_18_540PE/netcdf/tc_density.TS30.ens01.0850-1999.yearly.nc' da = xr.open_dataset(ifile)['density'].load() timeslice_early = slice('1351', '1450') timeslice_late = slice('1451', '1550') yearslice_early = slice(int(timeslice_early.start), int(timeslice_early.stop)) yearslice_late = slice(int(timeslice_late.start), int(timeslice_late.stop)) basin = 'NA' #season = 'ASO' season = 'annual' with xr.set_options(keep_attrs=True): #da_ref = da.sel(time=timeslice_early).mean('en')#.pipe(sel_season, season).mean('time').mean('en') da_ref = da.sel(year=yearslice_early).mean('year').mean('en')#.pipe(sel_season, season).mean('time').mean('en') #da_ref = da_ref.pipe(whereocean).pipe(wherebasin, basin).sel(lon=slice(250,360), lat=slice(0,60)) #da_ref = da_ref.pipe(wherebasin, basin).sel(lon=slice(250,360), lat=slice(0,60)) da_ref = da_ref.pipe(wherebasin, basin).sel(lon=slice(250,360), lat=slice(0,40)) #daa = da.sel(time=timeslice_late).pipe(sel_season, season).mean('time').mean('en') \ # - da.sel(time=timeslice_early).pipe(sel_season, season).mean('time').mean('en') daa = da.sel(year=yearslice_late).mean('year').mean('en') \ - da.sel(year=yearslice_early).mean('year').mean('en') #daa = daa.pipe(whereocean).pipe(wherebasin, basin).sel(lon=slice(250,360), lat=slice(0,60)) #daa = daa.pipe(wherebasin, basin).sel(lon=slice(250,360), lat=slice(0,60)) daa = daa.pipe(wherebasin, basin).sel(lon=slice(250,360), lat=slice(0,40)) #daa = daa.assign_attrs(long_name=daa.attrs['long_name']+' change') daa = daa.assign_attrs(long_name='track density change', units=daa.attrs['units'].replace('TC', 'HU')) def wyplot(ax=None, **kws): proj = cartoproj('cyl') dproj = cartoproj('cyl') if ax is None: fig = plt.figure(figsize=(6,4)) ax = fig.add_subplot(projection=proj) daa.plot.contourf(levels=21, ax=ax, trasnform=dproj, cbar_kwargs=dict(orientation='horizontal', shrink=0.8), **kws) cs = da_ref.plot.contour(levels=9, ax=ax, colors='gray', linewidths=0.5, transform=dproj) ax.clabel(cs) #mapplot(fill_continents=True) #mapplot(coastlines_width=1) ax.coastlines(color='0.33') gl = ax.gridlines(crs=dproj, draw_labels=True, linewidth=0.5) gl.xlabels_top = False # Hide labels on the top x-axis gl.ylabels_right = False # Hide labels on the right y-axis ax.set_extent([260,360,0,40], crs=dproj) ax.set_title(f'HiRAM {season} HU density change from {timeslice_early.start}-{timeslice_early.stop} to {timeslice_late.start}-{timeslice_late.stop}') #ax.set_xlim(260,360) if __name__ == '__main__': from wyconfig import * #my plot settings #from geoplots import mapplot #fig, ax = plt.subplots() wyplot() #savefig if 'savefig' in sys.argv or 's' in sys.argv: figname = __file__.replace('.py', f'.png') if 'overwritefig' in sys.argv or 'o' in sys.argv: wysavefig(figname, overwritefig=True) else: wysavefig(figname) try: tt.check(f'**Done**') except: pass print() if 'notshowfig' in sys.argv or 'n' in sys.argv: pass else: if 'plt' in globals(): plt.show()