#!/usr/bin/env python # Wenchang Yang (wenchang@princeton.edu) # Fri May 3 15:59:59 EDT 2024 if __name__ == '__main__': import sys,os from misc.timer import Timer tt = Timer(f'[{os.getcwd()}] 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 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 import xtc # if __name__ == '__main__': tt.check('end import') # #start from here ifile = 'IBTrACS.ALL.v04r00.2022-01-25.tracksByYear.1980-2021.nc' yearspan = slice(1980,2021) ds = xr.open_dataset(ifile).sel(year=yearspan).load() #sel TS ds = ds.where(ds.windmax.max('stage')>=17) #roll lon ds['lon'] = ds['lon'].where(ds['lon'].isel(stage=0)>0, other=ds['lon']+360) #interpolate windmax for NaNa values da = ds['windmax'] #prepare data for interpolate_na: need at least two valid values along each track da = da.where((da.stage>da.stage.min().item())|(da*0==0), other=da.min('stage')) #set the first track point, if NaN, to be the min value along the track da = da.where((da.stageda.stage.min().item())|(da*0==0), other=15) #set the first track point, if still NaN, to be 15 da = da.where((da.stage2 else np.arange(0, ds_cycle[basin].max(), 1) if basin == 'global': yticks = np.arange(0, ds_cycle[basin].max(), 4) #exception: higherinterval for global basin axin.set_yticks(yticks) ntc = ds_cycle[basin].sum().item() axin.set_title(f'{basin} ({ntc:.1f})', color='C1') #axin color axcolor = 'gray' axin.spines['bottom'].set_color(axcolor) axin.spines['left'].set_color(axcolor) axin.tick_params(axis='x', colors=axcolor) axin.tick_params(axis='y', colors=axcolor) if __name__ == '__main__': from wyconfig import * #my plot settings from geoplots import mapplot fig,ax = plt.subplots(figsize=(11,6)) ezplot = True if 'ezplot' in sys.argv else False alpha = 0.2 if ezplot else 1 #0.8 ds.pipe(xtc.trackplot, ezplot=ezplot, alpha=alpha, lw=0.5) ds.isel(stage=0).plot.scatter('lon', 'lat', c='k', s=0.3, zorder=10) ax.set_xticks(range(0, 361, 30)) #mapplot(coastlines_width=1) mapplot(fill_continents=True, alpha=0.5) wyplot_basin_boundary(ax=ax) basin = 'NA' wyplot_bars_cycle(basin=basin, ax=ax) basin = 'EP' wyplot_bars_cycle(basin=basin, ax=ax) basin = 'WP' wyplot_bars_cycle(basin=basin, ax=ax) basin = 'NI' wyplot_bars_cycle(basin=basin, ax=ax) basin = 'SI' wyplot_bars_cycle(basin=basin, ax=ax) basin = 'AU' wyplot_bars_cycle(basin=basin, ax=ax) basin = 'SP' wyplot_bars_cycle(basin=basin, ax=ax) basin = 'global' wyplot_bars_cycle(basin=basin, ax=ax) ax.set_title(f'Observed TC genesis locations, tracks, intensities and frequency annual cycles over {yearspan.start}-{yearspan.stop}') ax.set_xlabel('') ax.set_ylabel('') ax.set_xlim(0,361) #edit colorbar if not ezplot: cbar = fig.axes[1] yticks = cbar.get_yticks() yy = (yticks[1:]+yticks[:-1])/2 storm_types = ['TD', 'TS', 'CAT1', 'CAT2', 'CAT3', 'CAT4', 'CAT5'] for y,storm in zip(yy, storm_types): cbar.text(110, y, storm, color='gray') #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) tt.check(f'**Done**') print() if 'notshowfig' in sys.argv or 'n' in sys.argv: pass else: if 'plt' in globals(): plt.show()