def data2tiles_southtrac(): tag = 'stratospheric' df = southtrac.read(strat=1).set_index(target).sort_index() relative_count, total_count = group(df) return relative_count, total_count, tag
res=res ) ace = xr.open_dataset(dircInput2+f'ACE_OCS_{target}_{postfix}.nc').to_dataframe() ace, _ = group( ace[ace['air'] >= 1].reset_index(), group='OCS', groupby_v=target, vmin=vmin, vmax=vmax, res=res ) southtrac = southtrac.read(strat=1) southtrac, _ = group( southtrac.reset_index(), group='OCS', groupby_v=target, vmin=vmin, vmax=vmax, res=res ) ############################################################################### colors = {'MIPAS' : 'firebrick', 'ACE': 'orangered', 'SOUTHTRAC': 'teal' } fig = plt.figure(figsize=(10,50))
import clean.clean_03 as southtrac from matplotlib import gridspec from scipy import stats import plotly.io as pio import plotly.express as px pio.renderers.default='browser' def group(df): df = df[['ALT', 'LAT', 'OCS']] alt_range = np.arange(9, 14+0.5, 0.5) lat_range = [-70, -60, -50, -40] output = df['OCS'].groupby([pd.cut(df['ALT'], alt_range), pd.cut(df['LAT'], lat_range)]).agg(['count', 'mean', 'std']) output = output[output['count']>=3] return output df = southtrac.read(strat=1, local=1) plot_data_p1 = group(df[(df.index.month==9) | (df.index.month==10)]) plot_data_p2 = group(df[(df.index.month==11)]) plot_data_dif = plot_data_p1['mean'] - plot_data_p2['mean'] index = [pd.Interval(-70, -60, closed='right'), pd.Interval(-60, -50, closed='right'), pd.Interval(-50, -40, closed='right'),] tro_hs_v = [ dict(sep = 10.4, nov = 9.1), dict(sep = 9.8, nov = 9.5), dict(sep = 10.1, nov = 10.6), ] trp_hs = dict(zip(index, tro_hs_v))
# 'p75': group.quantile(0.75), # 'p90': group.quantile(0.9)} groupby = 'LAT' vmin = -90#-90 vmax = 90#90 res = 5#5 def group(df, group='OCS', groupby=groupby, vmin=vmin, vmax=vmax, res=res): vrange = np.arange(vmin, vmax+res, res) output = df[group].groupby([pd.cut(df[groupby], vrange)]).describe().reset_index() #apply(get_stats) .unstack() output[groupby.casefold()] = output.apply(lambda x: x[groupby].left+res/2,axis=1) return output # amica df = southtrac.read(strat=0,LAT=[-90, 90], ALT=9) df_9oct = df[(df['flight']=='2019-10-09') | (df['flight']=='2019-10-09')] #SAL - OPH super high ocs_9oct = group(df_9oct) df_2nov = df[df['flight']=='2019-11-02'] #OPH - SAL super low ocs_2nov = group(df_2nov) def plot(df=None, ax=None, shift=0, **kwargs): if ax is None: ax = plt.gca() ax.errorbar(df[groupby.casefold()]+shift, df['mean'], yerr=df['std'], capsize=4,
# 'SD': group.std(), # 'p10': group.quantile(0.1), # 'p25': group.quantile(0.25), # 'p75': group.quantile(0.75), # 'p90': group.quantile(0.9)} def group(df): lat_range = np.arange(-60, 60+10, 10) output = df['OCS'].groupby([pd.cut(df['LAT'], lat_range)]).describe().reset_index() #apply(get_stats) .unstack() print(output.head()) output['lat'] = output.apply(lambda x: x['LAT'].left+5/2,axis=1) return output # amica df = southtrac.read(strat=0, transfer=1, ALT=11) def plot(label=None, df=None, ax=None, shift=0, **kwargs): if ax is None: ax = plt.gca() ax.errorbar(y=df['mean'], x=df['lat']+shift, yerr=df['std'], capsize=4, label=label, fmt='s', #ecolor='#BDBDBD', **kwargs ) return ax
target = 'AGE' vmin = 0 vmax = 60 res = 5 ace = xr.open_dataset(dircInput2+f'ACE_N2O_{target}_{postfix}.nc').to_dataframe() ace, _ = group( ace.reset_index(), group='N2O', groupby_v=target, vmin=vmin, vmax=vmax, res=res ) southtrac = southtrac.read(local=1) southtrac, _ = group( southtrac[southtrac.air >= 1].reset_index(), group='UMAQS_N2O', groupby_v=target, vmin=vmin, vmax=vmax, res=res ) ############################################################################### fig = plt.figure(figsize=(10,50)) spec = gridspec.GridSpec(nrows=2, ncols=2,height_ratios=[15,1],width_ratios=[9,1])#,height_ratios=[15,1]) width_ratios=[9,1] ax = fig.add_subplot(spec[0,0]) # x = df.OCS # y = df[target]
plt.rc('font', **font) ax1 = fig.add_subplot() plot(label='AMICA', df=stats_amica) plot(label='MIPAS', df=stats_mipas) plot(label='ACE', df=stats_ace) ax1.set_xlim((0, 600) if species == 'OCS' else (0, 350)) ax1.set_ylim((vmin,vmax)) ax1.set_xlabel('OCS [ppt]' if species == 'OCS' else 'N2O [ppb]', fontweight='bold') ax1.set_ylabel(f'{target} [month]' if target in ('AGE', 'p50') else f'{target} [%]', fontweight='bold') plt.legend() #plt.title(f'{tag}') plt.show() ##########plotting########## for target in np.intersect1d(c.ALL_AGEV_SOUTHTRAC, c.ALL_AGEV): vrange = c.VRANGE_AGE if target == 'AGE' else c.VRANGE vmin, vmax, res = c.VMIN, c.VMAX_AGE if target== 'AGE' else c.VMAX, c.VRES ##########data processing########## stats_ace, tag = data2plot('ACE') stats_mipas, tag = data2plot('MIPAS') data_southtrac = southtrac.read(strat=1).set_index(target)[species] data_southtrac.dropna(inplace=True) data_southtrac.index = pd.IntervalIndex(pd.cut(data_southtrac.index, vrange)) data_southtrac.rename_axis(target, inplace=True) stats_amica = data_southtrac.groupby(target).agg({'mean', 'std', 'count'}) plot_age() winsound.Beep(freq, duration)