Пример #1
0
 def dataset_savepath_var(self, var_name, case_name, model_name):
     """
     Returns filename of dataset
     :param var_name:
     :param case_name:
     :param model_name:
     :return:
     """
     fn = self.coll_mod.savepath_coll_ds(
         var_name
     )  #(out_varn, self.model_name, self.case_name, self.from_time, self.to_time)
     make_folders(fn)
     return fn
Пример #2
0
outpaths['levlat_means'] = path_outdata + '/means/levlat_means/'
outpaths['profile_means'] = path_outdata + '/means/profile_means/'
outpaths['sizedistrib_files'] = path_outdata + '/sizedistrib_files'
outpaths['collocated'] = path_outdata + '/collocated_ds/'
outpaths['eusaar'] = path_outdata + '/eusaar/'


def get_outdata_path(key):
    if key in outpaths:
        return outpaths[key]
    else:
        print('WARNING: key not found in outpaths, constants.py')
        return path_outdata + '/' + key


make_folders(path_outdata)

# data info
path_data_info = project_base_path + 'OAS-DEV/oas_dev/data_info/'

# output locations:
locations = [
    'LON_116e_LAT_40n', 'LON_24e_LAT_62n', 'LON_63w_LAT_3s', 'LON_13e_LAT_51n'
]
path_locations_file = path_data_info + 'locations.csv'

if os.path.isfile(path_locations_file):
    collocate_locations = pd.read_csv(path_locations_file, index_col=0)
else:
    _dic = dict(Hyytiala={
        'lat': 61.51,
df_merged = pd.merge(df_obs_time.reset_index(), df_mod_time, how='outer')
df_merged

# %% [markdown]
# ## Construnc N30-100 and N50-100
# Mark that N50=N50-500 and N100=N100-500, so 
# $$N_{50-100}=N_{50}-N_{100}$$

# %%
df_merged['N30-100'] = df_merged['N30-50']+ df_merged['N50']-df_merged['N100']
df_merged['N50-100'] =df_merged['N50']-df_merged['N100']


# %%
from useful_scit.util.make_folders import make_folders
make_folders(file_out)
df_merged.to_csv(file_out)

# %%
df_merged

# %%
df_merged['source'].unique()

# %%
df_merged#[df_merged['source']=='SECTv11_ctrl_fbvoc']#.unique()

# %%

# %%
Пример #4
0
    if os.path.isfile(fn) and not reload:
        ds = xr.open_dataset(fn)
        #print(f'found contants file {fn}')
        return ds
    from_time = '1900-01'
    to_time = '2100-02'
    fl = filelist_NorESM(case, path, from_time, to_time, model)
    file = fl[0]
    ds = xr.open_dataset(file)
    drop_l = list(set(ds.data_vars) - set(include)) + ['PS']
    ds = ds.drop_vars(drop_l)  # [include]

    ds = xr_fix(ds)
    ds = ds.isel(time=0)
    ds.squeeze()
    make_folders(fn)
    ds.to_netcdf(fn)
    return ds


def get_vars_for_computed_vars(varNames, model):
    """
    Terribly formatted function for adding needed fields to varlist for my self defined variables.
    :param varNames:
    :param model:
    :return:
    """
    varnames_mod = []
    if model == 'NorESM':
        for var in varNames:
            if 'SW_rest_Ghan' == var:
Пример #5
0
            case,
            from_t,
            to_t, [minDiameter, maxDiameter],
            False,
            time_resolution,
            history_field=history_field)
        ds_conc = s.get_collocated_dataset()
        dic_mod_all[case] = ds_conc
        dic_orig[case] = ds_conc  #redo=True)
        dic_sized[case] = s

# %%
from useful_scit.util.make_folders import make_folders
from dask.diagnostics import ProgressBar

make_folders(path_tmp)
for case in cases_loaded:
    ds_case = dic_mod_all[case]
    for station in ds_case['station'].values:
        fn = get_fn_tmp_station(case, station, from_t, to_t)
        ds_ca_st = ds_case.sel(station=station)
        #fn = path_tmp + '%s_concat_dNdlogDs.nc'%case
        delayed_obj = ds_ca_st.to_netcdf(fn, compute=False)
        with ProgressBar():
            results = delayed_obj.compute()
    dic_mod_all[case].close()
# %%
make_folders(path_tmp)
for case in cases_loaded:
    fn = get_fn_tmp(case, from_t, to_t)
    #fn = path_tmp + '%s_concat_dNdlogDs.nc'%case
Пример #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()