コード例 #1
0
ファイル: sec_imp_map_prof.py プロジェクト: sarambl/OAS-DEV
def plt_prof_map_together(var, areas, cases, asp_rat=1, width=6):
    fig = plt.figure(figsize=[width, asp_rat * width])
    gs = gridspec.GridSpec(2, 2, height_ratios=[1, 1.],
                           width_ratios=[5, 1])  #width_ratios=[2, 1])
    ax1 = plt.subplot(gs[1, 0])
    ax2 = plt.subplot(gs[1, 1])
    ax3 = plt.subplot(gs[0, :], projection=ccrs.Robinson())
    ax2.axis('off')

    cmapd = get_cmap_dic(areas)

    linestd = dict()
    linestd_nn = dict()
    for case, ls in zip(cases, linests):
        linestd[case] = ls
        linestd_nn[get_nice_name_case(case)] = ls
    ax = ax1  # plt.subplots(1, figsize=[6,8])

    for area in areas:
        prof_dic = get_averaged_fields.get_profiles(
            cases, [var],
            startyear,
            endyear,
            area=area,
            pressure_adjust=pressure_adjust)

        for case in cases:
            kwargs = dict(color=get_area_col(area), linestyle=linestd[case])
            plot_profile(prof_dic[case][var],
                         ax=ax,
                         kwargs=kwargs,
                         xscale='log',
                         label=case + ', ' + area,
                         ylim=[1000, 200])  #,
    ax.grid(False, which='both')
    sns.despine(ax=ax)
    ax.set_yscale('log')

    set_scalar_formatter(ax)
    cases_nn = [get_nice_name_case(case) for case in cases]
コード例 #2
0
def plot_seasonal_surface_loc_sizedistributions(cases_sec, cases_orig, from_t, to_t,
                                                variables=['dNdlogD'],
                                                minDiameter=5., maxDiameter=39.6, resolution='month',
                                                history_field='.h0.',
                                                figsize= [12,6], locations=constants.collocate_locations.keys()):
    cl = SizedistributionSurface
    s_list = []
    for case in cases_sec:
        s1 = cl(case, from_t, to_t,
            [minDiameter, maxDiameter], True, resolution,
            history_field=history_field)
        s_list.append(s1)
    for case in cases_orig:
        s1 = cl(case, from_t, to_t,
            [minDiameter, maxDiameter], False, resolution,
            history_field=history_field)
        s_list.append(s1)
    cmap_dic = get_cmap_dic(cases_sec+cases_orig)

    for loc in locations:
        fig, axs = plt.subplots(2, 2, figsize=figsize)
        axs = axs.flatten()
        for s in s_list:
            ls = variables
            #if s.isSectional:
            #    ls = ls + ['dNdlogD_sec']
            s.plot_location(variables=ls,
                        c=cmap_dic[s.case_name],
                        axs=axs,
                        loc=loc,
                        ylim=[10,1e4])
        fig.tight_layout()
        savepath = constants.paths_plotsave['sizedist'] +'/season/'
        _cas = '_'.join(cases_sec) + '_'+'_'.join(cases_orig)
        savepath = savepath +loc+ _cas + 'mean_%s-%s_%s.png'%(from_t, to_t, resolution)
        make_folders(savepath)
        plt.savefig(savepath, dpi=200)
        plt.show()
コード例 #3
0
 if axs is None:
     fig = plt.figure(figsize = [width,asp_rat*width])
     gs = gridspec.GridSpec(2, 2,height_ratios=[1,1.], width_ratios=[5,1])#width_ratios=[2, 1]) 
     ax1 = plt.subplot(gs[1,0])
     ax2 = plt.subplot(gs[1,1])
     ax3 = plt.subplot(gs[0,:], projection=ccrs.Robinson())
     axs=[ax1,ax2,ax3]
     ax2.axis('off')
     cases_nn = [get_nice_name_case(case) for case in cases]
     
     set_legend_area_profs(ax2, areas,cases_nn, linestd_nn)
 ax1 = axs[0]
 ax3 = axs[1]
 
 
 cmapd = get_cmap_dic(areas)
 
 ax =ax1# plt.subplots(1, figsize=[6,8])
 
 for area in areas:
     prof_dic = get_averaged_fields.get_profiles(cases,varl,startyear, endyear,area=area,
                                               pressure_adjust=pressure_adjust)
 
     for case in cases:
         kwargs = dict(color=get_area_col(area), linestyle=linestd[case])
         plot_profile(prof_dic[case][var], 
                      ax=ax, 
                      kwargs=kwargs, 
                      xscale='log', 
                      label=case+', '+ area,
                      ylim=[1000,200])#, 
コード例 #4
0
ファイル: code_usage.py プロジェクト: sarambl/OAS-DEV
from sectional_v2.util.eusaar_data.histc_vars import load_var_as_dtframe
from sectional_v2.util.eusaar_data import  distc_var, histc_vars, histsc_hists # import load_var_as_dtframe
import matplotlib.pyplot as plt
from useful_scit.plot import get_cmap_dic

# %% [markdown]
# ## distc_var

# %%
a = distc_var.get_distc_xarray_all()

# %%
sts = a['station'].values[:4]
year='BOTH'
subs='TOT'
cma = get_cmap_dic(sts)
da = a.sel(year=year,subset=subs)
for st in sts:
    _da50 = da.sel(station=st, percentile='50th percentile')#
    _da50.plot(yscale='log',xscale='log', label='50th perc, %s'%st, color = cma[st])
    _da95 = da.sel(station=st, percentile='95th percentile')
    _da5 = da.sel(station=st, percentile='5th percentile')
    plt.fill_between(da.diameter, _da5,_da95, alpha=.2 , color = cma[st])
plt.ylim(1,3e4)
plt.xlim(5,1e3)
plt.legend()
plt.title('Test sizedistributions')

# %% [markdown]
# ### Conversion dN/dlog10D to dN/dlnD:
# $$ ln(x) = ln(10)\cdot log10(x)$$
コード例 #5
0
def plot_grid(dic_finish,
              subs='TOT',
              st_ls=None,
              name='all_stations',
              ylim=[5, 8.8e3],
              yscale='linear',
              plot_sec=True,
              nr_col=4,
              figsize=None,
              ylim_ZEP=[0, 500]):

    colors_source = get_cmap_dic(dic_finish.keys())
    colors_source['EUSAAR'] = 'k'

    dic_ds = dic_finish
    t_cs = dic_ds[list(dic_ds.keys())[0]]
    st_ls = list(get_ordered_stations())
    #    st_ls = list(loc_tr[loc_tr['Region']==reg].index)
    print(list(st_ls))
    if len(st_ls) > nr_col:
        nr_row = int(np.ceil(len(st_ls) / nr_col))
    else:
        nr_row = 1
        nr_col = len(st_ls)

    if figsize is None:
        figsize = [10 / 4 * nr_col, 10 / 6 * nr_row]

    fig, axs = plt.subplots(nr_row,
                            nr_col,
                            sharex=True,
                            sharey=True,
                            figsize=figsize)
    axs_nf = axs
    if nr_row > 1: axs = axs.flatten()
    for station, ax in zip(st_ls, axs):
        lines = []
        labels = []
        for key in dic_finish.keys():
            _ds = dic_finish[key]
            #if 'dNdlog10dp_sec' in _ds:
            #    plt_perc(dic_finish[key]['dNdlog10dp_sec'], station, key,
            #            color=get_case_col(key),
            #            ax=ax,
            #            subs=subs, percs=[16,84], yscale=yscale, ylim=ylim)
            ##    plt_perc(dic_finish[key]['dNdlog10dp_mod'], station, key,
            #            color=get_case_col(key),
            #            ax=ax,
            #            subs=subs, percs=[16,84], yscale=yscale, ylim=ylim)
            #else:

            plt_perc(dic_finish[key]['dNdlog10dp'],
                     station,
                     key,
                     color=get_case_col(key),
                     ax=ax,
                     subs=subs,
                     percs=[16, 84],
                     yscale=yscale,
                     ylim=ylim)
        for key in dic_finish.keys():
            _ds = dic_finish[key]
            #if 'dNdlog10dp_sec' in _ds:
            #    line =plt_median(dic_finish[key]['dNdlog10dp_sec'], station, key,
            #            color=get_case_col(key),
            #            ax=ax,
            #            subs=subs, percs=[16,84], yscale=yscale, ylim=ylim)
            #    line =plt_median(dic_finish[key]['dNdlog10dp_mod'], station, key,
            #            color=get_case_col(key),
            #            ax=ax,
            #            subs=subs, percs=[16,84], yscale=yscale, ylim=ylim)

            #else:
            if 'dNdlog10dp_sec' in _ds:
                line = plt_median(dic_finish[key]['dNdlog10dp_sec'].where(
                    dic_finish[key]['dNdlog10dp_sec'] > 0),
                                  station,
                                  key,
                                  color=get_case_col(key),
                                  ax=ax,
                                  subs=subs,
                                  percs=[16, 84],
                                  yscale=yscale,
                                  ylim=ylim,
                                  plt_kwargs={'linestyle': 'dashed'})

            line = plt_median(dic_finish[key]['dNdlog10dp'],
                              station,
                              key,
                              color=get_case_col(key),
                              ax=ax,
                              subs=subs,
                              percs=[16, 84],
                              yscale=yscale,
                              ylim=ylim)

            lines = lines + line
            labels.append(get_nice_name_case(key))
        if station == 'ZEP':
            axins = insert_ZEP(ax)
            for key in dic_finish.keys():
                plt_perc(dic_finish[key]['dNdlog10dp'],
                         station,
                         key,
                         color=get_case_col(key),
                         ax=axins,
                         subs=subs,
                         percs=[16, 84],
                         yscale=yscale,
                         ylim=ylim_ZEP)
            for key in dic_finish.keys():
                plt_median(dic_finish[key]['dNdlog10dp'],
                           station,
                           key,
                           color=get_case_col(key),
                           ax=axins,
                           subs=subs,
                           percs=[16, 84],
                           yscale=yscale,
                           ylim=ylim_ZEP)
                if 'dNdlog10dp_sec' in _ds:

                    plt_median(dic_finish[key]['dNdlog10dp_sec'],
                               station,
                               key,
                               color=get_case_col(key),
                               ax=axins,
                               subs=subs,
                               percs=[16, 84],
                               yscale=yscale,
                               ylim=ylim_ZEP)

            ax.indicate_inset_zoom(
                axins,
                edgecolor='r',
            )
            fix_ins(axins)
        if subs == 'TOT':
            cat = coll_ltr.loc[station, dall_c]
            ax.set_title(station)  #+' '+cat)
        else:
            cat = coll_ltr.loc[station, dall_c]
            ax.set_title(station + ' ' + subs)  #+', '+cat)
        ax.grid(True)
        ax.spines['left'].set_visible(False)
        ax.spines['right'].set_visible(False)
        ax.spines['top'].set_visible(False)
        ax.tick_params(axis=u'y', which=u'both', length=0)

    if nr_row > 1:
        for ii in range(nr_row):
            for jj in range(nr_col):
                if ii != nr_row - 1:
                    axs_nf[ii, jj].set_xlabel('')
                if jj != 0:
                    axs_nf[ii, jj].set_ylabel('')
                else:
                    axs_nf[ii, jj].set_ylabel('dN/dlog$_{10}$D [cm$^{-3}$]')

    fig.tight_layout()
    lgn = fig.legend(
        lines,
        labels,
        bbox_to_anchor=(0, 1., 1, 0.5),  # (0, -0.04, 1., .1),
        loc='lower center',
        ncol=4,
        # mode="expand",
        borderaxespad=0.,
        fontsize=11,
        frameon=False)  # bbox_to_anchor=(0, 1., 1, 0.5))

    #fig.legend(lines, labels, bbox_to_anchor=(0,1.,1,0.5),#(0, -0.04, 1., .1),
    #       loc='lower center', ncol=4,
    #       #mode="expand",
    #       borderaxespad=0., fontsize=11, frameon=False)# bbox_to_anchor=(0, 1., 1, 0.5))

    fn = paths_plotsave[
        'eusaar'] + '/sizedist/%s_overview_yscale_%s_sec%s_%s.' % (
            name.replace(' ', '-'), yscale, plot_sec, subs)
    print(fn)
    make_folders(fn)
    plt.savefig(fn + 'png', bbox_extra_artists=(lgn, ), bbox_inches='tight')
    plt.savefig(fn + 'pdf', bbox_extra_artists=(lgn, ), bbox_inches='tight')
    plt.show()
コード例 #6
0
# %%
plot_grid(dic_finish, subs='SUM', ylim=[0, 1e4])

# %%
plot_grid(dic_finish, subs='WIN', ylim=[0, 8e3])

# %%
plot_grid(dic_finish, subs='SPR', ylim=[0, 8e3])

# %%
plot_grid(dic_finish, subs='AUT', ylim=[0, 8e3])

# %%
from sectional_v2.constants import collocate_locations
station = 'ASP'
colors_source = get_cmap_dic(dic_finish.keys())
colors_source['EUSAAR'] = 'k'
for station in dic_finish[cases[0]].coords['station'].values:
    fig, axs = plt.subplots(2, 2)
    seasons = ['SPR', 'SUM', 'AUT', 'WIN']
    for seas, ax in zip(seasons, axs.flatten()):
        for key in dic_finish.keys():
            plt_median_perc(dic_clean[key]['dNdlog10dp'],
                            station,
                            key,
                            color=get_case_col(key),
                            ax=ax,
                            subs=seas,
                            percs=[16, 84],
                            yscale='log',
                            ylim=[10, 1e4])
コード例 #7
0
    s_list.append(s1)
    #s1.compute_sizedist_mod_tot()
    #s.compute_sizedist_sec_tot()
#a1 = s1.get_collocated_dataset()

case = cases_sec[1]

s2 = cl(case,
        from_t,
        to_t, [minDiameter, maxDiameter],
        True,
        'month',
        history_field='.h0.')
#a2 = s1.get_collocated_dataset()
from useful_scit.plot import get_cmap_dic
cmap_dic = get_cmap_dic(cases_sec + cases_orig)

for loc in constants.collocate_locations.keys():
    print(loc, '***********************************************')
    fig, axs = plt.subplots(2, 2)
    axs = axs.flatten()

    for s in s_list:
        ls = ['dNdlogD_mode01']
        if s.isSectional:
            ls = ls + ['dNdlogD_sec']
        a = s.get_collocated_dataset(variables=ls)
        print(a)
        b = a['dNdlogD_mode01']  # + a['dNdlogD_sec']
        c = b.mean('lev').groupby('time.season').mean('time')