示例#1
0
                                'col_dim': 'tfreq',
                                'x_ticks': np.arange(240, 300, 20),
                                'y_ticks': np.arange(0, 61, 10)
                            })
f_name = 'clustering_dendogram_{}'.format(xrclustered.attrs['hash']) + '.pdf'
path_fig = os.path.join(rg.path_outmain, f_name)
fig.savefig(path_fig, bbox_inches='tight')  # dpi auto 600

#%%
if region != 'init':
    # try:
    # ds_cl_ts = core_pp.get_selbox(ds_cl['xrclusteredall'].sel(q=q, n_clusters=c),
    #                           selbox)
    # ds_new = cl.spatial_mean_clusters(var_filename,
    #                               ds_cl_ts,
    #                               selbox=selbox)
    # ds_new['xrclusteredall'] = xrclustered
    # f_name = 'q{}_nc{}'.format(int(q), int(c))
    # except:
    ds_cl_ts = core_pp.get_selbox(
        ds_cl['xrclusteredall'].sel(tfreq=t, n_clusters=c), selbox)
    ds_new = cl.spatial_mean_clusters(var_filename, ds_cl_ts, selbox=selbox)
    ds_new['xrclusteredall'] = xrclustered
    f_name = 'tf{}_nc{}'.format(int(t), int(c))
    filepath = os.path.join(rg.path_outmain, f_name)
    cl.store_netcdf(ds_new,
                    filepath=filepath,
                    append_hash='dendo_' + xrclustered.attrs['hash'])

    TVpath = filepath + '_' + 'dendo_' + xrclustered.attrs['hash'] + '.nc'
示例#2
0
#                                                kwrgs_clust={#'eps':.05,
#                                                             'min_samples':5,
#                                                             'metric':'minkowski',
#                                                              'n_jobs':-1})

# plot_maps.plot_labels(xrclustered)
# print(f'{round(time()-t0, 2)}')

#%%
q_list = [75, 82.5, 90, 95]
for q in q_list:
    for c in n_clusters:
        q = 95
        c = 5
        xrclust = xrclustered.sel(q=q, n_clusters=c)
        ds = cl.spatial_mean_clusters(var_filename, xrclust, selbox=selbox)

        ds[f'q{95}'] = cl.percentile_cluster(var_filename,
                                             xrclust,
                                             q=95,
                                             tailmean=False,
                                             selbox=selbox)

        q_sp = 50
        ds[f'q{q_sp}tail'] = cl.percentile_cluster(var_filename,
                                                   xrclust,
                                                   q=q_sp,
                                                   tailmean=True,
                                                   selbox=selbox)

        q_sp = 65
示例#3
0
# t = 10 ; c = 5
# ds = cl.spatial_mean_clusters(var_filename,
#                              xrclustered.sel(tfreq=t, n_clusters=c),
#                              selbox=selbox)
# ds['xrclusteredall'] = xrclustered
# f_name = 'tf{}_nc{}'.format(int(t), int(c))
# filepath = os.path.join(rg.path_outmain, f_name)
# cl.store_netcdf(ds, filepath=filepath, append_hash='dendo_'+xrclustered.attrs['hash'])

# TVpath = filepath + '_' + 'dendo_'+xrclustered.attrs['hash'] + '.nc'
if type(tfreq) is list:
    t = 15
    c = 7
    ds = cl.spatial_mean_clusters(var_filename,
                                  xrclustered.sel(tfreq=t, n_clusters=c),
                                  selbox=selbox)
    f_name = 'tfreq{}_nc{}'.format(int(t), int(c))
else:
    c = 11
    q = 65
    ds = cl.spatial_mean_clusters(var_filename,
                                  xrclustered.sel(q=q, n_clusters=c),
                                  selbox=selbox)
    f_name = 'q{}_nc{}'.format(int(q), int(c))

ds['xrclusteredall'] = xrclustered
filepath = os.path.join(rg.path_outmain, f_name)
cl.store_netcdf(ds,
                filepath=filepath,
                append_hash='dendo_' + xrclustered.attrs['hash'])
示例#4
0
ds_raw['time'] = pd.to_datetime(
    [f'{y+1949}-01-01' for y in ds_raw.time.values])
ds_raw = ds_raw.sel(time=core_pp.get_oneyr(ds_raw, *years))

ds_avail = (70 - np.isnan(ds_raw).sum(axis=0))
ds_avail = ds_avail.where(ds_avail.values != 0)
ds_avail.plot(vmin=30)
ds_avail.min()

ds_std = (ds_raw - ds_raw.mean(dim='time')) / ds_raw.std(dim='time')

linkage = 'ward'
c = 2
xrclustered = xrclusteredall.sel(linkage=linkage, n_clusters=c)

ds = cl.spatial_mean_clusters(ds_std, xrclustered)
df = ds.ts.to_dataframe().pivot_table(index='time', columns='cluster')['ts']

f_name = 'linkage_{}_nc{}'.format(linkage, int(c))
filepath = os.path.join(path_outmain, f_name)
cl.store_netcdf(ds,
                filepath=filepath,
                append_hash='dendo_' + xrclustered.attrs['hash'])

#%% Soy bean USDA

raw_filename = '/Users/semvijverberg/Dropbox/VIDI_Coumou/Paper3_Sem/GDHY_MIRCA2000_Soy/USDA/usda_soy.nc'

selbox = [250, 290, 28, 50]
ds = core_pp.import_ds_lazy(raw_filename, var='variable',
                            selbox=selbox).rename({'z': 'time'})