コード例 #1
0
def corr_plt():
    # %%
    var_c = 'AWNC_incld'
    varl_to = ['NCONC01','NMR01']
    cbar_orientation = 'vertical'
    cases_ctrl = cases_orig
    case_oth = cases_sec[0]
    ncol = len(cases_ctrl)
    nrow = len(varl_to)
    subfig_size = 2.6
    asp_ratio = 1.6
    figsize = [subfig_size * ncol * asp_ratio, subfig_size * nrow]
    # noinspection PyTypeChecker
    fig, axs = plt.subplots(nrow, ncol, figsize=figsize, sharex=True, sharey=True)

    norm_dic = dict(
        NCONC01=colors.SymLogNorm(vmin=-1e3, vmax=1e3, linthresh=10),
        NMR01=colors.SymLogNorm(vmin=-10, vmax=10, linthresh=.1),
        AWNC_incld=colors.SymLogNorm(vmin=-20, vmax=20, linthresh=.1),
        AREL_incld=colors.SymLogNorm(vmin=-5, vmax=5, linthresh=.1)
    )
    for j, var in enumerate(varl_to):
        saxs = axs[j, :]
        for i, case in enumerate(cases_ctrl):
            ax = saxs[i]
            _vars = [var, var_c]
            _ds = cases_dic[case_oth][_vars]- cases_dic[case][_vars]
            _da_corr = corr(_ds[var],_ds[var_c], dim=['time','lon'])
            nn_ctrl = get_nice_name_case(case)
            nn_oth = get_nice_name_case(case_oth)
            title = f'Correlation $\Delta V = V_x - V_y$),\n x={nn_oth}, y={nn_ctrl}'
            _da_corr.load()
            label = f'corr($\Delta${get_fancy_var_name(var)},$\Delta${get_fancy_var_name(var_c)})'#)
            plt_kwargs ={}
            plt_kwargs = make_cbar_kwargs(label, plt_kwargs, cbar_orientation)
            

            plot_levlat(ax, 'RdBu_r', _da_corr, title, [1e3,200],
            #            cbar_orientation='vertical',
            #            #ax=ax,
            #            #norm=norm_dic[var],
            #            #relative=False,
            #            #ylim=[1e3, 200],
                        yscale='log', **plt_kwargs)


    for ax in axs.flatten():
        ax.set_ylabel('')
        ax.set_xlabel('')
    for ax in axs[:, 0]:
        ax.set_ylabel('Pressure [hPa]')
    for ax in axs[-1, :]:
        ax.set_xlabel('Latitude [$^\circ$N]')
    fig.tight_layout()
    fn = filen_base + f'corr_NMR_N_clouds_{case_oth}' + '_'.join(cases_ctrl) + f'{startyear}-{endyear}'
    subp_insert_abc(axs, pos_x=1.1,pos_y=1.1)
    plt.savefig(fn + '.pdf')
    plt.savefig(fn + '.png')
    plt.show()
コード例 #2
0
ファイル: sizedist_area.py プロジェクト: sarambl/OAS-DEV
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 = Sizedistribution
    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
sns.despine(ax=ax)
ax.set_yscale('log')
set_scalar_formatter(ax)
    
ax.grid(False, which='both')

subp_insert_abc(np.array(axs_all[:-1]))
plt.tight_layout()

vars_n = '_'.join(varl)
fn_figure = '%s%s_%s-%s.'%(fn_base,vars_n,startyear, endyear)
print(fn_figure)
#axs_prof[0].set_xlim([1e-13,5e-11])
#axs_prof[1].set_xlim([1e-13,5e-11])
#plt.savefig(fn_figure + 'png')
plt.savefig(fn_figure + 'pdf', dpi=300)

plt.show()


# %%
from matplotlib.colors import LogNorm
varl = ['nrSEC_tot','N_secmod']
vmin=1e2
vmax=1e4
norm=LogNorm(vmin=vmin, vmax=vmax)
map_kwargs=dict(norm=norm)
fig, axs_maps, axs_prof, axs_all = plt_prof_map_together_ls(*varl, areas, [case_sec], asp_rat=.6, width=5.5, map_kwargs=map_kwargs)
plt.tight_layout()
vars_n = '_'.join(varl)
fn_figure = '%s%s_%s-%s.'%(fn_base,vars_n,startyear, endyear)
コード例 #4
0
                          norm=norm_dic[var],
                          relative=False,
                          ylim=[1e3, 200],
                          yscale='log')
for ax in axs.flatten():
    ax.set_ylabel('')
    ax.set_xlabel('')
for ax in axs[:, 0]:
    ax.set_ylabel('Pressure [hPa]')
for ax in axs[-1, :]:
    ax.set_xlabel('Latitude [$^\circ$N]')
fig.tight_layout()
fn = filen_base + f'N_clouds_{case_oth}' + '_'.join(cases_ctrl) + f'{startyear}-{endyear}'

subp_insert_abc(axs)
plt.savefig(fn + '.pdf')
plt.savefig(fn + '.png')
plt.show()

# %% [markdown]
# varlist = ['FREQL']
# cases_dic = get_averaged_fields.get_levlat_cases(cases, varlist, startyear, endyear,
#                                                  pressure_adjust=pressure_adjust)
#

# %%
# correlation:
# %%
var_subl = ['NCONC01','AWNC_incld','AREL_incld','NMR01','HYGRO01','N_AER']
cases_dic = {}
for case in cases:
コード例 #5
0
#plot_diff(maps_dic, varl, cases[::-1],nr_cols=1, relative=relative)
load_and_plot_diff_mm(varl,
                      to_case,
                      from_cases,
                      startyear,
                      endyear,
                      avg_over_lev,
                      pmin=pmin,
                      relative=relative,
                      pressure_adjust=pressure_adjust,
                      nr_cols=1,
                      width=4)
fn = filen_base + '_'.join(varl) + f'{relative}.'

plt.tight_layout()
plt.savefig(fn + 'png')
plt.savefig(fn + 'pdf')
print(fn)

# %%

varl = [
    'DIR_Ghan'
]  #,'LWDIR_Ghan']#'LWDIR_Ghan']#, 'SO4_NAcondTend']#, 'leaveSecH2SO4','leaveSecSOA']#,'TGCLDCWP']

relative = False
#plot_diff(maps_dic, varl, cases[::-1],nr_cols=1, relative=relative)
load_and_plot_diff_mm(varl,
                      to_case,
                      from_cases,
                      startyear,
コード例 #6
0
ファイル: levlats_abs.py プロジェクト: sarambl/OAS-DEV
                              cbar_orientation='vertical',
                              axs=saxs,
                              norm=norm_dic[var],
                              ylim=[1e3, 200],
                              yscale='log')
for ax in axs.flatten():
    ax.set_ylabel('')
    ax.set_xlabel('')
for ax in axs[:, 0]:
    ax.set_ylabel('Pressure [hPa]')
for ax in axs[-1, :]:
    ax.set_xlabel('Latitude [$^\circ$N]')
fig.tight_layout()
fn = filen_base + f'N_clouds_{case_oth}' + '_'.join(
    cases_ctrl) + f'{startyear}-{endyear}'
plt.savefig(fn + '.pdf')
#plt.savefig(fn + '.png')
plt.show()

# %% [markdown]
# ## Gases:

# %%
varlist = ['H2SO4', 'SOA_LV', 'SOA_SV']  # 'SOA_NA','SO4_NA']
cbar_orientation = 'vertical'
cases_ctrl = cases_orig
case_oth = cases_sec[0]
ncol = len(cases)
nrow = len(varlist)
subfig_size = 2.6
asp_ratio = 1.6
コード例 #7
0
for i in np.arange(nr_subp):
    axs[i].set_ylabel('Diameter [nm]')
    axs[i].get_xaxis().get_label().set_visible(False)  # .get_xlabel().set_visible(False)
    # axs[i].get_xlabel().set_visible(False)

plotpath = 'plots/time_sizedist/'
plotpath = plotpath + '/lat%.1f_lon%.1f_pres%.1f/' % (latitude_coord, longitude_coord, pressure_coord)
plotpath = plotpath + dummy1.case_name + '_' + dummy2.case_name
plotpath = plotpath + 'time_%s-%s' % (from_time, to_time)
if nodiff:
    plotpath = plotpath + 'nodiff'
plotpath = plotpath + '.png'
practical_functions.make_folders(plotpath)
print(plotpath)
plt.tight_layout()
plt.savefig(plotpath, dpi=300)
plt.show()


# %%
s = s_list[1]
s.case_name

# %%
a_list = []
varl_sec = ['nrSOA_SEC_tot', 'nrSO4_SEC_tot', 'SOA_SEC_tot', 'SO4_SEC_tot', 'NCONC01', 'NNAT_1', 'N_AER', 'NUCLRATE_pbl','NUCLRATE','FORMRATE']
varl_orig = [ 'NCONC01', 'NNAT_1', 'N_AER', 'NUCLRATE_pbl','NUCLRATE','FORMRATE']
for s in s_list:
    if s.isSectional:
        a_list.append( s.get_input_data(varl_sec))
    else:
コード例 #8
0
def corr_plt(var_c=None, varl_to=None,cases_ctrl=None,
             case_oth = None):
    # %%
    if var_c is None:
        var_c = 'AWNC_incld'
    if varl_to is None:
        varl_to = ['NCONC01','NMR01']
    cbar_orientation = 'vertical'
    if cases_ctrl is None:
        cases_ctrl = cases_orig
    if case_oth is None:
        case_oth = cases_sec[0]
    ncol = len(cases_ctrl)
    nrow = len(varl_to)
    subfig_size = 2.5
    asp_ratio = 1.6
    figsize = [subfig_size * ncol * asp_ratio, subfig_size * nrow]
    # noinspection PyTypeChecker
    fig, axs = plt.subplots(nrow, ncol, figsize=figsize, sharex=True, sharey=True)

    for j, var in enumerate(varl_to):
        saxs = axs[j, :]
        for i, case in enumerate(cases_ctrl):
            ax = saxs[i]
            _vars = [var, var_c]
            _ds = cases_dic[case_oth][_vars]- cases_dic[case][_vars]
            _da_corr = corr(_ds[var],_ds[var_c], dim=['time','lon'])
            nn_ctrl = get_nice_name_case(case)
            nn_oth = get_nice_name_case(case_oth)
            title =f'x={nn_oth}, y={nn_ctrl}'# f'Correlation $\Delta V = V_x - V_y$),\n x={nn_oth}, y={nn_ctrl}'
            _da_corr.load()
            label = f'corr($\Delta${get_fancy_var_name(var)},$\Delta${get_fancy_var_name(var_c)})'#)
            plt_kwargs ={}
            plt_kwargs = make_cbar_kwargs(label, plt_kwargs, cbar_orientation)
            

            plot_levlat(ax, 'RdBu_r', _da_corr, title, [1e3,200],
            #            cbar_orientation='vertical',
            #            #ax=ax,
            #            #norm=norm_dic[var],
            #            #relative=False,
            #            #ylim=[1e3, 200],
                        yscale='log', **plt_kwargs)
            ax.yaxis.set_major_formatter(mtick.FormatStrFormatter('%.0f'))
            ax.yaxis.set_minor_formatter(mtick.FormatStrFormatter('%.0f'))

    title = f'Correlations $\Delta V = V_x - V_y$'#' x={nn_oth}, y={nn_ctrl}'

    stit = plt.suptitle(title,y = 1.03)
    for ax in axs.flatten():
        ax.set_ylabel('')
        ax.set_xlabel('')
    for ax in axs[:, 0]:
        ax.set_ylabel('Pressure [hPa]')
    for ax in axs[-1, :]:
        ax.set_xlabel('Latitude [$^\circ$N]')
    fig.tight_layout()
    fn = filen_base + f'corr_NMR_N_clouds_{var_c}{case_oth}' + '_'.join(cases_ctrl) + f'{startyear}-{endyear}'
    subp_insert_abc(axs, pos_x=1.13,pos_y=1.01)
    print(fn)
    plt.savefig(fn + '.pdf', bbox_extra_artists=(stit,),bbox_inches='tight')
    plt.savefig(fn + '.png',bbox_extra_artists=(stit,),bbox_inches='tight')
    plt.show()
コード例 #9
0
ファイル: maps_N_AER_both2.py プロジェクト: sarambl/OAS-DEV
relative = False
#plot_diff(maps_dic, varl, cases[::-1],nr_cols=1, relative=relative)
load_and_plot_diff_mm(varl,
                      to_case,
                      from_cases,
                      startyear,
                      endyear,
                      avg_over_lev,
                      pmin=pmin,
                      relative=relative,
                      pressure_adjust=pressure_adjust,
                      nr_cols=1,
                      width=5.5)
fn = filen_base + '_'.join(varl) + f'{relative}.'
plt.tight_layout()
plt.savefig(fn + 'png')
plt.savefig(fn + 'pdf')

# %%

varl = [
    'SOA_NA_totLossR', 'SOA_NA_lifetime'
]  #'LWDIR_Ghan']#, 'SO4_NAcondTend']#, 'leaveSecH2SO4','leaveSecSOA']#,'TGCLDCWP']

relative = False
#plot_diff(maps_dic, varl, cases[::-1],nr_cols=1, relative=relative)
load_and_plot_diff_mm(varl,
                      to_case,
                      from_cases,
                      startyear,
                      endyear,