Ejemplo n.º 1
0
                area, reg, seas)
            ctl.plot_map_contour(pval_map,
                                 lat,
                                 lon,
                                 filename=fnam,
                                 cbar_range=(0., 0.1),
                                 plot_anomalies=False,
                                 extend_opt='neither',
                                 draw_grid=True,
                                 cb_label='P-value',
                                 title='area: {}, regime: {}, seas: {}'.format(
                                     area, reg_names_area[area][reg], seas))

        cmape = [corrmaps[('corr', area, reg)] for reg in range(4)]
        pvlep = [corrmaps[('pval', area, reg)] <= 0.05 for reg in range(4)]

        fnam = cart_out_wcmip5 + 'tas_corrmap_{}_allregs_{}.pdf'.format(
            area, seas)
        ctl.plot_multimap_contour(cmape,
                                  lat,
                                  lon,
                                  filename=fnam,
                                  add_hatching=pvlep,
                                  cbar_range=(-1, 1),
                                  cb_label='Correlation',
                                  title='area: {}, seas: {}'.format(
                                      area, seas),
                                  subtitles=reg_names_area[area],
                                  draw_grid=True,
                                  figsize=(18, 12))
Ejemplo n.º 2
0
titlefont = 24
plt.rcParams['figure.titlesize'] = titlefont
plt.rcParams['axes.titlesize'] = 18
plt.rcParams['axes.labelsize'] = 18
#############################################################################

cart_out = '/home/fedef/Research/lavori/CMIP6/Clusters_of_regime_hist/'
ctl.mkdir(cart_out)

for area in ['EAT', 'PNA']:
    filox = '/home/fedef/Research/lavori/CMIP6/cmip6_hist/out_cmip6_hist_NDJFM_{}_4clus_4pcs_1964-2014_refEOF_dtr.p'.format(
        area)
    coso, coso_ref = ctl.load_wrtool(filox)

    lat = coso['BCC-CSM2-MR_r1i1p1f1']['lat']
    lon = coso['BCC-CSM2-MR_r1i1p1f1']['lon']

    for reg in range(4):
        cluspatterns = [coso[mo]['cluspattern'][reg] for mo in coso.keys()]

        centroids, labels, patts, repres, distances = cd.EnsClus_light(
            cluspatterns, lat, numclus=4, numpcs=4, flag_perc=False, perc=None)

        filename = cart_out + 'clu2_{}_{}.pdf'.format(area, reg)
        ctl.plot_multimap_contour(patts,
                                  lat,
                                  lon,
                                  filename,
                                  plot_margins=area,
                                  title='{} - reg {}'.format(area, reg))
Ejemplo n.º 3
0
    allmaps[('ERA',
             'full')], lato, lono = ctl.sel_area(lat, lon, ERA_map_full, 'EAT')

    ERA_allmaps = []
    for reg in range(4):
        okind = wri == reg
        okblo_map = np.mean(blok[okind, ...], axis=0) - ERA_map_full
        ERA_allmaps.append(okblo_map)
        allmaps[('ERA',
                 reg)], lato, lono = ctl.sel_area(lat, lon, okblo_map, 'EAT')
        allsums[('ERA', reg)] = np.sum(allmaps[('ERA', reg)])

    ERA_allmaps = np.stack(ERA_allmaps)
    ctl.plot_multimap_contour(ERA_allmaps,
                              lat,
                              lon,
                              filename=cart_out_maps + 'map_regs_ERA.pdf',
                              visualization='Nstereo')

    for mod in model_names:
        filok = [fi for fi in all_fils_bloc if mod == fi.split('.')[5]]
        all_mems = [fi.split('.')[7] for fi in filok]
        print(filok)

        for filo, mem in zip(filok, all_mems):
            if 'EC-Earth' in mod and mem == 'r1i1p1f1':
                continue
            if mod == 'HadGEM3-GC31-LL' and mem == 'r1i1p2f1':
                continue
            blocked_days, datacoords, aux_info = ctl.readxDncfield(cart_bloc +
                                                                   filo)
Ejemplo n.º 4
0
#### Figurez
# only stab
fig, ax = ctl.get_cartopy_fig_ax(coast_lw=0.1)
proj = ccrs.PlateCarree()

for ru, col in zip(allru, colors):
    coso = monreg[(ru, 'stab')]
    ctl.plot_mapc_on_ax(ax,
                        coso.values,
                        coso.lat.values,
                        coso.lon.values,
                        proj,
                        None, (0, 1),
                        plot_type='binary_contour',
                        lw_contour=2.,
                        line_color=col)

ctl.custom_legend(fig, colors, allru, ncol=4)
fig.savefig(cart_out + 'monsoon_stab.pdf')

cosi = [mpi[(ru, 'stab')] for ru in allru]
for co in cosi:
    co.values[co < 0.5] = np.nan

ctl.plot_multimap_contour(cosi,
                          filename=cart_out + 'monsoon_all.pdf',
                          cbar_range=(0.5, 1.),
                          subtitles=allru,
                          cmap='viridis')
Ejemplo n.º 5
0
    c5 = np.percentile(figtrend, 5)
    c95 = np.percentile(figtrend, 95)

    if var == 'pr_rel':
        c5 = -0.1
        c95 = 0.3
    divnorm = colors.TwoSlopeNorm(vmin=c5, vcenter=vcen, vmax=c95)

    ctl.plot_multimap_contour(figtrend,
                              coso.lat,
                              coso.lon,
                              filename=cart_out + var + '_trendz.pdf',
                              fix_subplots_shape=(3, 3),
                              figsize=(16, 9),
                              cbar_range=(c5, c95),
                              color_norm=divnorm,
                              subtitles=t**s,
                              add_hatching=fighatch,
                              cmap=cmap,
                              n_color_levels=17,
                              hatch_styles=['////', '', ''])

    okfi = [fi for fi, tit in zip(figtrend, t**s) if '1st' in tit
            ] + [fi for fi, tit in zip(figtrend, t**s) if '5th' in tit]
    oktit = [tit for tit in t**s if '1st' in tit
             ] + [tit for tit in t**s if '5th' in tit]
    okha = [fi for fi, tit in zip(fighatch, t**s) if '1st' in tit
            ] + [fi for fi, tit in zip(fighatch, t**s) if '5th' in tit]

    ctl.plot_multimap_contour(okfi,
Ejemplo n.º 6
0
cmaps['pr'] = 'BrBG'
cbar_range = dict()
cbar_range['tas'] = (-5, 5)
cbar_range['pr'] = (-3, 3)
lat = results_ref['lat']
lon = results_ref['lon']
cblab = dict()
cblab['tas'] = 'Temperature (K)'
cblab['pr'] = 'Daily prec (mm)'

margs = [-30,70, 20,80]

for varnam in ['tas', 'pr']:
    fields = composites[('present', 'ref', varnam, 'mean')]
    filnam = cart_out + 'refcomp_{}.pdf'.format(varnam)
    ctl.plot_multimap_contour(fields, lat, lon, filnam, visualization = 'standard', central_lat_lon = (70, -20), plot_margins = margs, cmap = cmaps[varnam], title = '', subtitles = regnames, cb_label = cblab[varnam], bounding_lat = 0., draw_grid = True, n_color_levels = 10, draw_contour_lines = False, lw_contour = 0.7, cbar_range = cbar_range[varnam])#, plot_type = 'pcolormesh')

for cos in ['present', 'future']:
    for resol in ['LR', 'HR']:
        for varnam in ['tas', 'pr']:
            fields = compcomp[(cos, varnam, resol)]
            filnam = cart_out + 'modcomp_{}_{}_{}.pdf'.format(varnam, cos, resol)
            ctl.plot_multimap_contour(fields, lat, lon, filnam, visualization = 'standard', central_lat_lon = (70, -20), plot_margins = margs, cmap = cmaps[varnam], title = '', subtitles = regnames, cb_label = cblab[varnam], bounding_lat = 0., draw_grid = True, n_color_levels = 10, draw_contour_lines = False, lw_contour = 0.7, cbar_range = cbar_range[varnam])#, plot_type = 'pcolormesh')

for varnam in ['tas', 'pr']:
    fields = composites[('present', 'ref', varnam, 'mean')]
    filnam = cart_out + 'refcomp_{}.pdf'.format(varnam)
    ctl.plot_multimap_contour(fields, lat, lon, filnam, visualization = 'standard', central_lat_lon = (70, -20), plot_margins = margs, cmap = cmaps[varnam], title = '', subtitles = regnames, cb_label = cblab[varnam], bounding_lat = 0., draw_grid = True, n_color_levels = 10, draw_contour_lines = False, lw_contour = 0.7, cbar_range = cbar_range[varnam])#, plot_type = 'pcolormesh')

cbar_range['tas'] = (-2, 2)
cbar_range['pr'] = (-2, 2)
Ejemplo n.º 7
0
ax.plot(coso, lata, color=cols[2], linewidth=2, label='EAT')

ax.axvline(0., color='lightslategray', linewidth=0.2)
ax.set_xlabel('Zonal trend anomaly (m/yr)')
ax.set_ylabel('Latitude')
plt.legend()
fig.savefig(filename)

filename = cart_out_orig + 'trend_anom_ssp585.pdf'
ctl.plot_multimap_contour(trendsanom,
                          lat,
                          lon,
                          filename,
                          plot_anomalies=True,
                          plot_margins=(-180, 180, 20, 90),
                          cbar_range=(-2, 2),
                          add_hatching=hatchs,
                          fix_subplots_shape=(7, 2),
                          figsize=(15, 20),
                          subtitles=allmods_MM,
                          cb_label='m/year',
                          verbose=True,
                          draw_grid=True)

filename = cart_out_orig + 'trend_anom_ssp585_EAT.pdf'
ctl.plot_multimap_contour(trendsanom,
                          lat,
                          lon,
                          filename,
                          plot_anomalies=True,
                          visualization='nearside',
                          central_lat_lon=(65, -30),
Ejemplo n.º 8
0
        print(i, LA.norm(el), LA.norm(elpr))

    allclus_ml.append(cluster_ml)
    allclus_sk.append(cluster_sk)

allclus_ml = np.stack(allclus_ml)
allclus_sk = np.stack(allclus_sk)

mean_ml = np.mean(allclus_ml, axis=0)
mean_sk = np.mean(allclus_sk, axis=0)
std_ml = np.std(allclus_ml, axis=0)
std_sk = np.std(allclus_sk, axis=0)

print('Standard deviation of the different clusters:\n')
for i, (el, elpr) in enumerate(zip(std_ml, std_sk)):
    print(i, LA.norm(el), LA.norm(elpr))
print('Mean of the different clusters:\n')
for i, (el, elpr) in enumerate(zip(mean_ml, mean_sk)):
    print(i, LA.norm(el - elpr))

#plt.ion()
ctl.plot_multimap_contour(cluspatt_ml,
                          lat_area,
                          lon_area,
                          filename=cart + 'clusmap_ml.pdf')

ctl.plot_multimap_contour(cluspatt_sk,
                          lat_area,
                          lon_area,
                          filename=cart + 'clusmap_sk.pdf')
Ejemplo n.º 9
0
    ]

    nams += subtits
    patts += patt_ref

    filename = cart_out + 'Allclus_OBSERVED_{}.pdf'.format(area)
    figs = ctl.plot_multimap_contour(
        patt_ref,
        lat,
        lon,
        filename,
        visualization=proj,
        central_lat_lon=clatlo[area],
        cmap=cmappa,
        title='',
        subtitles=subtits,
        cb_label='Geopotential height anomaly (m)',
        color_percentiles=(0.5, 99.5),
        number_subplots=False,
        bounding_lat=blat,
        draw_grid=True,
        n_color_levels=10,
        n_lines=10,
        draw_contour_lines=True,
        clevels=clevels,
        lw_contour=0.7)

    filename = cart_out + 'Allclus_OBSERVED_{}_line.pdf'.format(area)
    figs = ctl.plot_multimap_contour(
        patt_ref,
        lat,
        lon,
Ejemplo n.º 10
0
cartmap = cart + 'Maps/'
area = 'EAT'
for num, nam in enumerate(patnames[area]):
    patts = [results_fullp[(ens, area, (1850,2100))]['cluspattern'][num] for ens in ensmem]
    #patts = [hist_runs[(ens,area)]['cluspattern'][num] for ens in ensmem]

    filename = cartmap + 'Clusfullp_{}{}_all_new.pdf'.format('EAT',num)
    print(filename)
    for pa in patts:
        print(ens, pa.min())
    if area == 'EAT':
        clatlo = (70.,0.)
    else:
        clatlo = (70.,-90.)
    ctl.plot_multimap_contour(patts, lat, lon, filename, visualization = 'polar', central_lat_lon = clatlo, cmap = 'RdBu_r', title = nam, subtitles = ensmem, cb_label = 'Geopotential height anomaly (m)', color_percentiles = (0.5,99.5), fix_subplots_shape = (2,3), number_subplots = False, figsize = (15,15), draw_contour_lines = False)

sys.exit()

cartfr = cart+'freq_histo/'

for area in ['EAT', 'PNA']:
    for ran in [histran, futran]:
        fig = plt.figure()
        lab1 = 'base'
        lab2 = 'stoc'
        wi = 0.3
        for clu, clunam in enumerate(patnames[area]):
            if clu > 0:
                lab1 = None
                lab2 = None
Ejemplo n.º 11
0
        subtitles.append(ru + ' - eq')

    cbr0 = ctl.get_cbar_range([ma.values for ma in mappe[:3]], True, (2, 98))
    cbr1 = ctl.get_cbar_range([ma.values for ma in mappe[3:]], True, (2, 98))
    cbar_range = 3 * [cbr0] + 3 * [cbr1]

    # subtitles = ['{} - {}'.format(ru, seasok) for seasok in ['DJF', 'MAM', 'JJA', 'SON'] for ru in allru]

    if var in var_map:
        fig = ctl.plot_multimap_contour(
            mappe,
            figsize=(16, 8),
            title=var,
            plot_anomalies=True,
            add_contour_field=6 * [pimean],
            add_contour_plot_anomalies=False,
            add_contour_same_levels=False,
            fix_subplots_shape=(2, 3),
            subtitles=subtitles,
            use_different_cbars=True,
            cbar_range=cbar_range
        )  #, cmap = cmaps, cbar_range = cbar_range, use_different_cbars = True, use_different_cmaps = True)
        figs_map.append(fig[0])
    else:
        # 3D vars
        fig, axs = plt.subplots(2, 3, figsize=(12, 8))
        for ma, ax, subt in zip(mappe, axs.flatten(), subtitles):
            if 'tr' in subt:
                vma = 10
            else:
                vma = 5
Ejemplo n.º 12
0
        cba = None
        cma = 'viridis'
        if var == 'siconc':
            cba = (0, 1)
            cma = 'Blues_r'
        #for pol in ['Npolar', 'Spolar']:
        for clat in [90, -90]:
            print(var, copl, clat)
            fig = ctl.plot_multimap_contour(mappeseas,
                                            figsize=(24, 12),
                                            plot_anomalies=False,
                                            subtitles=subtitles,
                                            title=var + ' - ' + copl,
                                            add_contour_field=mapcont,
                                            add_contour_plot_anomalies=False,
                                            visualization='nearside',
                                            cmap=cma,
                                            cbar_range=cba,
                                            central_lat_lon=(clat, 0),
                                            bounding_lat=40 * np.sign(clat),
                                            fix_subplots_shape=(2, 4))

            figs_map.append(fig)

figs_map = np.concatenate(figs_map)
fignames = [
    var + '_' + copl + '_' + pole for var in var_map_200 for copl in allcopls
    for pole in ['N', 'S']
]
ctl.plot_pdfpages(cart_out + 'bottino_seaicemap.pdf', figs_map, True, fignames)
Ejemplo n.º 13
0
 print('adesso {}\n'.format(tag))
 patt = results['cluspattern'][tag]
 if np.any(np.isnan(patt)):
     print('There are {} NaNs in this patt.. replacing with zeros\n'.format(
         np.sum(np.isnan(patt))))
     patt[np.isnan(patt)] = 0.0
 cartout = cart + 'Model_{}/'.format(tag)
 if not os.path.exists(cartout): os.mkdir(cartout)
 filename = cartout + 'Allclus_' + tag + '.pdf'
 ctl.plot_multimap_contour(
     patt,
     lat,
     lon,
     filename,
     visualization='polar',
     central_lat_lon=(50., 0.),
     cmap='RdBu_r',
     title='North-Atlantic weather regimes - {}'.format(tag),
     subtitles=patnames,
     cb_label='Geopotential height anomaly (m)',
     color_percentiles=(0.5, 99.5),
     fix_subplots_shape=(2, 2),
     number_subplots=False)
 for patuno, patuno_ref, pp, pps in zip(patt, patt_ref, patnames,
                                        patnames_short):
     nunam = cartout + 'clus_' + pps + '_' + tag + '.pdf'
     ctl.plot_double_sidebyside(patuno,
                                patuno_ref,
                                lat,
                                lon,
                                filename=nunam,
                                visualization='polar',
Ejemplo n.º 14
0
                                    'DJFM')] = ctl.seasonal_climatology(
                                        varok, dateok, 'DJFM')
        resdict[(ru, varnam, 'mean200',
                 'JJAS')], resdict[(ru, varnam, 'std200',
                                    'JJAS')] = ctl.seasonal_climatology(
                                        varok, dateok, 'JJAS')

pickle.dump(glomean, open(cart_out + 'mean_climate.p', 'wb'))

for varnam in ['tas', 'pr', 'uas']:
    fiout = cart_out + '{}_mean200.pdf'.format(varnam)
    varall = [resdict[(ru, varnam, 'mean200')] for ru in allru
              ] + [resdict[(ru, varnam, 'std200')] for ru in allru]
    ctl.plot_multimap_contour(varall,
                              lat,
                              lon,
                              fiout,
                              plot_anomalies=False,
                              fix_subplots_shape=(2, 3))

    fiout = cart_out + '{}_mean200_rsp025.pdf'.format(varnam)
    varall = [
        resdict[(ru, varnam, 'mean200')] - resdict[('b025', varnam, 'mean200')]
        for ru in allru[1:]
    ] + [resdict[(ru, varnam, 'std200')] for ru in allru[1:]]
    ctl.plot_multimap_contour(varall,
                              lat,
                              lon,
                              fiout,
                              plot_anomalies=False,
                              fix_subplots_shape=(2, 2))
Ejemplo n.º 15
0
all_figures = []
for ex in exps_all:
    patt = results[ex]['cluspattern_area']
    if ex != 'ERA': patt = patt / gg
    patt_ref = results_ref['cluspattern_area']
    lat_ref = results[ex]['lat_area']
    lon_ref = results[ex]['lon_area']
    figs = ctl.plot_multimap_contour(patt,
                                     lat_ref,
                                     lon_ref,
                                     None,
                                     visualization='nearside',
                                     central_lat_lon=(70, -20),
                                     cmap='RdBu_r',
                                     title=ex,
                                     subtitles=patnames,
                                     cb_label='Geop. height anomaly (m)',
                                     cbar_range=(-150, 150),
                                     number_subplots=False,
                                     bounding_lat=0,
                                     plot_margins=None,
                                     draw_grid=True,
                                     plot_type='pcolormesh')
    all_figures += figs

figs = ctl.plot_multimap_contour(patt_ref,
                                 lat_ref,
                                 lon_ref,
                                 None,
                                 visualization='nearside',
                                 central_lat_lon=(70, -20),
Ejemplo n.º 16
0
    gi11tos_dtr.append(ginko)

gi11tos = np.concatenate(gi11tos, axis = 0)
gi11tos_dtr = np.concatenate(gi11tos_dtr, axis = 0)

pickle.dump([pi11tos, pi11tos_dtr, gi11tos, gi11tos_dtr], open(cart_out + 'tos_data.p', 'wb'))
pickle.dump([obs_states, mod_states], open(cart_out + 'tos_data_xr.p', 'wb'))

pi11tos, pi11tos_dtr, gi11tos, gi11tos_dtr = pickle.load(open(cart_out + 'tos_data.nc', 'rb'))
obs_states, mod_states = pickle.load(open(cart_out + 'tos_data_xr.p', 'rb'))
############################################################

solver = ctl.eof_computation(pi11tos, latitude=pino.lat.values)

filout = cart_out + 'tos_eofs_obs_withtrend.pdf'
ctl.plot_multimap_contour(solver.eofs(eofscaling=2)[:n_ref], lat, lon, filout, plot_anomalies=True, cbar_range=(-0.6,0.6), subtitles= ['eof {}'.format(i) for i in range(n_ref)], cb_label='T (K)')

### detrended
solver_dtr = ctl.eof_computation(pi11tos_dtr, latitude=pino.lat.values)

filout2 = cart_out + 'tos_eofs_obs_detrended.pdf'
ctl.plot_multimap_contour(solver_dtr.eofs(eofscaling=2)[:n_ref], lat, lon, filout2, plot_anomalies=True, cbar_range=(-0.6,0.6), subtitles= ['eof {}'.format(i) for i in range(n_ref)], cb_label='T (K)')

# match
#eof2 = ctl.match_pc_sets(solver.eofs(eofscaling=2)[:n_ref], solver_dtr.eofs(eofscaling=2)[:n_ref], latitude = lat)
#filout3 = cart_out + 'tos_eofs_opa0_diff_dtr-wtr.pdf'
#ctl.plot_multimap_contour(eof2-solver.eofs(eofscaling=2)[:n_ref], pino.lat.values, pino.lon.values, filout3, plot_anomalies=True, cbar_range=(-0.2,0.2), subtitles= ['eof {}'.format(i) for i in range(n_ref)], cb_label='T (K)')

#######################################

obseofs = solver.eofs(eofscaling=2)[:n_ref]
Ejemplo n.º 17
0
        if varnam == 'pr_rel':
            transient[thres] = np.nan
            equi[thres] = np.nan
            mappe = [(transient - pimap) / pimap, (equi - transient) / pimap]
        elif varnam == 'tas':
            mappe = [transient - pimap, equi - transient]
            #mappe = [ma - ctl.global_mean(ma, coso.lat) for ma in mappe]
        else:
            mappe = [transient - pimap, equi - transient]

        ctl.plot_multimap_contour(mappe,
                                  coso.lat,
                                  coso.lon,
                                  filename=cart_out +
                                  'trans_vs_stab_{}_{}.pdf'.format(varnam, ru),
                                  subtitles=['transient', 'stabilization'],
                                  cmap=cmappa,
                                  plot_anomalies=True,
                                  cbar_range=ext,
                                  figsize=(16, 6),
                                  cb_label=cblab)

        fig_patt_trans.append(mappe[0])
        fig_patt_stab.append(mappe[1])

        mappe += [mappe[0] + mappe[1]]
        ctl.plot_multimap_contour(
            mappe,
            coso.lat,
            coso.lon,
            filename=cart_out +