#!/usr/bin/env python # Wenchang Yang (wenchang@princeton.edu) # Thu May 21 11:24:22 EDT 2020 if __name__ == '__main__': from misc.timer import Timer tt = Timer(f'start {__file__}') import sys, os.path, os, glob import xarray as xr, numpy as np, pandas as pd #import matplotlib.pyplot as plt #more imports #from xtc import tc_count maindir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) if maindir not in sys.path: sys.path.append(maindir) from AM2p5C360.data_ntc_mh import get_ntc_mh from misc.cim import cim, sem #confidence interval of the mean # if __name__ == '__main__': tt.check('end import') #start from here """ source = 'HiRAM_amipHadISST' ifile = '/tigress/wenchang/analysis/TC/HIRAM/amipHadISST_tigercpu_intelmpi_18_540PE/netcdf/HIRAM.amipHadISST_tigercpu_intelmpi_18_540PE.tc_tracks.TS.1971-2018.nc' basin = 'NA' def get_ntc(basin='NA'):"""""" ds = xr.open_dataset(ifile) if 'vmax' in ds and 'windmax' not in ds: ds = ds.rename(vmax='windmax') da = ds.pipe(tc_count, basin=basin, ws=17) return da """ #annual cycle def get_cycle(basin='NA', years=None): if years is None: years = slice('1980', '2018') da = get_ntc_mh(basin=basin) da = da.sel(time=years) # stack dims of ['en', 'time'] and use the stacked 'time' as the new coord if 'en' in da.dims: da = da.stack(s=[...]).pipe(lambda x: x.assign_coords(s=x.time)).rename(s='time') da_mclim = da.groupby('time.month').mean('time') da_cim = da.groupby('time.month').map(cim, dim='time') da_sem = da.groupby('time.month').map(sem, dim='time') ds_mclim = xr.Dataset(dict( mclim=da_mclim, cim=da_cim, sem=da_sem )) return ds_mclim if __name__ == '__main__': from wyconfig import * #my plot settings basin = 'NA' source = 'AM2.5C360_amipHadISST' figname = __file__.replace('.py', f'_{basin}_{tt.today()}.png') years = slice('1980', '2018') ds_ = get_cycle(basin=basin, years=years) long_name = f'N_MH({basin}, {source})' ax = ds_.rename(mclim=long_name).to_dataframe().plot.bar(y=long_name, yerr='sem', rot=0) ax.legend(loc='upper left') plt.savefig(figname) print('[saved]:', figname) tt.check(f'**Done**') plt.show()