예제 #1
0
def plot_jointplot(ddic, eusaar, nsec, unit, var, xl, ul=1.5, ll=4.):
    data = ddic[nsec]  # ".keys()
    data = data['log']
    # fi, axs = plt.subplots(2, sharex=True)
    xl = var + '_' + eusaar
    yl = var + '_' + nsec
    g = sns.jointplot(x=xl, y=yl, data=data, kind="hex", gridsize=20)
    # x0, x1 = g.ax_joint.get_xlim()
    # y0, y1 = g.ax_joint.get_ylim()
    # ul = 3.8#max(x0, y0)
    # ll = 1#min(x1, y1)
    lims = [ul, ll]
    ul_int = np.floor(ul)
    ll_int = np.ceil(ll) + 1
    g.ax_joint.set_yticks(np.arange(ul_int, ll_int))
    g.ax_joint.set_xticks(np.arange(ul_int, ll_int))
    g.ax_joint.set_yticklabels(10 ** np.arange(ul_int, ll_int))  # np.arange(1,6))
    g.ax_joint.set_xticklabels(10 ** np.arange(ul_int, ll_int))  # np.arange(1,6))
    g.ax_joint.set_xlabel('%s: %s %s' % (var, get_nice_name_case(eusaar), unit))  # np.arange(1,6))
    g.ax_joint.set_ylabel('%s: %s %s' % (var, get_nice_name_case(nsec), unit))  # np.arange(1,6))
    g.ax_joint.plot(lims, lims, ':k')
    g.ax_joint.set_xlim(lims)  # , lims)#, ':k')
    g.ax_joint.set_ylim(lims)  # , lims)#, ':k')
    plt.plot()
    plt.tight_layout()
    fp = plot_path + '/%s_jointplot_%s_allstations_%s' % (var, nsec, version)
    print(fp)

    plt.savefig(fp + '.png')
    plt.savefig(fp + '.pdf')
    plt.show()
    return xl
예제 #2
0
def set_title_diff(case_ctrl, case_oth, relative, glob_diff=''):
    nn_ctrl = get_nice_name_case(case_ctrl)
    nn_oth = get_nice_name_case(case_oth)
    if relative:
        return f'{nn_oth} to {nn_ctrl}{glob_diff}'
    else:
        return f'{nn_oth}-{nn_ctrl}{glob_diff}'
예제 #3
0
def plt_station(_df, _df_16, _df_84, ax, st, var, ylim,
               yscale='linear'):
    ax.set_xticks(range(1, 12, 2))
    _df_s = _df[_df['station'] == st]
    _df_s16 = _df_16[_df_16['station'] == st]
    _df_s84 = _df_84[_df_84['station'] == st]
    x = _df_s['month']
    y = _df_s
    lines = []
    labels = []
    for source in _df_s['source'].unique():
        _df_ss16 = _df_s16[_df_s16['source'] == source].set_index('month').reindex(range(1, 13))
        _df_ss84 = _df_s84[_df_s84['source'] == source].set_index('month').reindex(range(1, 13))
        ax.fill_between(_df_ss16.index, _df_ss16[var], _df_ss84[var], color=get_case_col(source), alpha=0.3)

    for source in _df_s['source'].unique():
        _df_ss = _df_s[_df_s['source'] == source].set_index('month').reindex(range(1, 13))  
        # print(_df_ss[var])
        line = ax.plot(_df_ss.index, _df_ss[var], color=get_case_col(source), label=source, marker='*', markersize=4)
        lines = lines + line  # s[0]
        labels.append(get_nice_name_case(source))
    ax.set_yscale(yscale)
    ca = coll_ltr.loc[st, dall_c]
    
    ax.set_title(st)#+',' +ca)
    if ylim is not None:
        ax.set_ylim(ylim)
    ax.set_xlim([.8,12.2])
    return labels, lines
예제 #4
0
def corr_plt_latlon(var_c, varl_to, cases_ctrl=cases_orig, case_oth=cases_sec[0], cmap='RdBu_r', pmin=850.):
    # %%
    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 = subplots_map(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]
            _ds = _ds.sel(lev=slice(pmin,None))
            _da_corr = corr(_ds[var],_ds[var_c], dim=['time','lev'])
            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)

            plt_map(_da_corr, ax=ax, cmap=cmap,
            #            cbar_orientation='vertical',
            #            #ax=ax,
            #            #norm=norm_dic[var],
            #            #relative=False,
            #            #ylim=[1e3, 200],
                **plt_kwargs)
            
            ax.set_title(title)

    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}'
    #plt.savefig(fn + '.pdf')
    #plt.savefig(fn + '.png')
    plt.show()
    # %%
    return _da_corr
예제 #5
0
def set_title_abs(case_ctrl, glob_diff=''):
    nn_ctrl = get_nice_name_case(case_ctrl)
    return f'{nn_ctrl}{glob_diff}'
예제 #6
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()