Example #1
0
    def plot_cluster_map(
        self,
        i,
        log_plot_dic=None,
        map_dic=None,
        par_to_plot=co.COL,
    ):
        if map_dic is None:
            map_dic = {}
        if log_plot_dic is None:
            log_plot_dic = {}
        clus = self.cluster_flags[i]
        boo = self.merged_ds[co.ClusFlag] == clus

        ax = fa.get_ax_bolivia(**map_dic)
        #     fig,ax = plt.subplots()
        warnings.simplefilter('ignore')

        ar = self.merged_ds.where(boo)[par_to_plot]
        com = fa.get_dims_complement(ar, [co.R_CENTER, co.TH_CENTER])
        ar = ar.sum(dim=com)
        if par_to_plot is co.CPer:
            ar = ar / self.merged_ds[par_to_plot].sum() * 100
        cmap = fa.get_custom_cmap(self.colors[i])
        def_dic = dict(ax=ax,
                       name=par_to_plot,
                       perM=.95,
                       quantile=True,
                       colorbar=False,
                       patch_args={'cmap': cmap})

        com_dic = {**def_dic, **log_plot_dic}
        fa.logpolar_plot(ar, **com_dic)
Example #2
0
def plot_general_lapaz(ds1):
    cl = co.CPer
    c1 = ds1[cl].sum([co.RL, co.ZM])
    c2 = ds1[cl].sum([co.ZM, co.RL, co.TH_CENTER])
    ar = c1 / c2
    # ar = c1
    ar = ar.isel(**{co.R_CENTER: slice(0, -3)})
    ax = fa.get_ax_lapaz(fig_args={'figsize': (5, 5)})
    fa.logpolar_plot(ar, name=co.CPer, ax=ax, perM=.95, perm=.01)
    # ax.set_xlim(-75, -60)
    # ax.set_ylim(-25, -7)
    return ax
Example #3
0
def plot_log_custom(d_sum,
                    v_max,
                    v_min,
                    map_fun=fa.get_ax_bolivia):
    ax = map_fun(fig_args={'figsize': (10, 8)})
    p_args_ = {
        'norm': mpl_colors.LogNorm(vmin=v_min, vmax=v_max)
    }
    fa.logpolar_plot(d_sum, ax=ax, perM=v_max, perm=v_min,
                     quantile=False,
                     patch_args=p_args_,
                     drop_zeros=False,
                     )
Example #4
0
def plot_clust_in_bolivia(_n, dscc):
    ax = fa.get_ax_bolivia()
    _f = 2
    for _f in range(_n):
        _ds = dscc.loc[{co.CLUS_LENGTH_DIM: _n}]
        _ds = _ds.drop(co.KMEAN_OBJ)
        _ds = _ds.where(_ds[co.FLAG] == _f)
        _ds = _ds.sum([co.RL, co.ZM])

        _ds = _ds[[co.CONC]]

        _cm = fa.get_custom_cmap(ucp.cc[_f][:3])

        fa.logpolar_plot(_ds, ax=ax, patch_args={'cmap': _cm}, colorbar=False)
Example #5
0
def plot_clust_bolivia_individual(_n, dscc):
    for _f in range(_n):
        ax = fa.get_ax_bolivia()
        ax.set_title(str(_f))
        _ds = dscc.loc[{co.CLUS_LENGTH_DIM: _n}]
        _ds = _ds.drop(co.KMEAN_OBJ)
        _ds = _ds.where(_ds[co.FLAG] == _f)
        _ds = _ds.sum([co.RL, co.ZM])

        _ds = _ds[[co.CONC]]

        _cm = fa.get_custom_cmap([*ucp.cc, *ucp.cc, *ucp.cc][_f][:3])

        fa.logpolar_plot(_ds, ax=ax, patch_args={'cmap': _cm}, colorbar=False)
Example #6
0
def plot_clust_in_lapaz(_n, dscc):
    for _f in range(_n):
        ax = fa.get_ax_lapaz()
        ax.set_title(str(_f))
        _ds = dscc.loc[{co.CLUS_LENGTH_DIM: _n}][
            {co.R_CENTER: slice(1, 23)}]
        _ds = _ds.drop(co.KMEAN_OBJ)
        _ds = _ds.where(_ds[co.FLAG] == _f)
        _ds = _ds.sum([co.RL, co.ZM])

        _ds = _ds[[co.CONC]]

        _cm = fa.get_custom_cmap([*ucp.cc, *ucp.cc, *ucp.cc][_f][:3])

        if _ds[co.CONC].max().item() != 0:
            fa.logpolar_plot(_ds, ax=ax, patch_args={'cmap': _cm},
                             colorbar=False)
        fa.add_chc_lpb(ax)
Example #7
0
def plot_bolivia(ax, da_srl, name, r, t0, t1, tlen):
    da_th_r = da_srl.sum([co.ZM, co.RL])
    ax: plt.Axes = fa.get_ax_bolivia(ax=ax)
    patch = fa.logpolar_plot(da_th_r.to_dataset(),
                             ax=ax,
                             name=co.CONC,
                             return_patch=True,
                             colorbar=False)
    ax.set_title(
        f'{name}:{r[name]}  |  {r[t0]}  -  {r[t1]}  |  {tlen}:{int(r[tlen])}')
    return patch
# %%

# %%
i = 0
ax = fa.get_ax_bolivia()
for i in range(len_clus):
    clus = self.cluster_flags[i]
    boo = self.merged_ds[co.ClusFlag] == clus
    #     fig,ax = plt.subplots()
    import warnings
    warnings.simplefilter('ignore')
    ar = self.merged_ds.where(boo)[co.CPer].mean(dim=[co.RL])
    fa.logpolar_plot(ar,
                     ax,
                     name=co.CPer,
                     perM=.15,
                     quantile=False,
                     colorbar=False,
                     patch_args={'cmap': fa.get_custom_cmap(FLP.COLORS[i])})

# %%
i = 0
ax = fa.get_ax_lapaz()
for i in range(len_clus):
    clus = self.cluster_flags[i]
    boo = self.merged_ds[co.ClusFlag] == clus
    #     fig,ax = plt.subplots()
    import warnings
    warnings.simplefilter('ignore')
    ar = self.merged_ds.where(boo)[co.CCPer].mean(dim=[co.RL])
    fa.logpolar_plot(ar,
# %%
from matplotlib.patches import Circle, Wedge, Polygon
from matplotlib.collections import PatchCollection

# %%
conc = nds/nds[fa.GA]
conc.name = 'conc'

# %%

# %%
ax = fa.get_ax_bolivia()
# fig, ax = plt.subplots()
ax = fa.logpolar_plot(conc.where(conc>0),ax,name='conc',perM=.8,perm=.1,
                 colorbar=True,
                 patch_args={'norm':matplotlib.colors.LogNorm(),'cmap':'viridis'}
                )

# %%
ax = fa.get_ax_bolivia()
# fig, ax = plt.subplots()
ax = fa.logpolar_plot(conc.where(conc>0),ax,name='conc',perM=.8,perm=.1,
                 colorbar=True,
#                  patch_args={'norm':matplotlib.colors.LogNorm()}
                )

# %%
ax = fa.get_ax_bolivia()
# fig, ax = plt.subplots()
ax = fa.logpolar_plot(nds,ax,perM=.99,perm=.1,
                 colorbar=True
# self = FLP.FlexLogPol(path,concat=False)
self = FLP.FlexLogPol(
    path,
    #     concat=True,
    concat=False,
    get_clusters=False,
    open_merged=True,
    clusters_avail=False)

# %%

# %%
com = fa.get_dims_complement(self.merged_ds, [co.R_CENTER, co.TH_CENTER])
sds = self.merged_ds.sum(com)
ax = fa.get_ax_bolivia()
fa.logpolar_plot(sds[co.CONC], name=co.CONC, ax=ax, drop_zeros=False)

# %%
ax = fa.get_ax_bolivia()
fa.logpolar_plot(self.merged_ds[co.TOPO],
                 name=co.TOPO,
                 ax=ax,
                 drop_zeros=False)

# %%
self.reset_z_levels()

# %%
com = fa.get_dims_complement(self.merged_ds, [co.R_CENTER, co.TH_CENTER])
sds = self.merged_ds.sum(com)
ax = fa.get_ax_bolivia()

# %%
dsSM = ds1 = FLP.smooth_merged_ds(
    dsF
    )

# %%
cl = co.CPer
c1 =ds1[cl].sum([co.RL,co.ZM])
c2 = ds1[cl].sum([co.ZM,co.RL,co.TH_CENTER])
ar = c1/c2
# ar = c1
ar = ar.isel(**{co.R_CENTER:slice(0,-3)})
ax = fa.get_ax_bolivia(fig_args={'figsize':(5,5)})
fa.logpolar_plot(ar,name=co.CPer,ax=ax,perM=.95,perm=.01)
ax.set_xlim(-75,-60)
ax.set_ylim(-25,-7)
# ax = fa.get_ax_lapaz()
# fa.logpolar_plot(ar,name=co.CPer,ax=ax,perM=.95)


# %%
ax.figure.savefig('/tmp/map.pdf')

# %%

# %%
ds1.sum([co.ZM,co.RL,co.TH_CENTER])[co.CPer].plot(marker='.',xscale='log')

# %%
Example #12
0
# %%
dsF = self.filter_hours_with_few_mea()

# %%
dsSM = ds1 = FLP.smooth_merged_ds(dsF)

# %%
cl = co.CPer
c1 = ds1[cl].sum([co.RL, co.ZM])
c2 = ds1[cl].sum([co.ZM, co.RL, co.TH_CENTER])
ar = c1 / c2
# ar = c1
ar = ar.isel(**{co.R_CENTER: slice(0, -3)})
ax = fa.get_ax_bolivia(fig_args={'figsize': (5, 5)})
fa.logpolar_plot(ar, name=co.CPer, ax=ax, perM=.95, perm=.01)
ax.set_xlim(-75, -60)
ax.set_ylim(-25, -7)
# ax = fa.get_ax_lapaz()
# fa.logpolar_plot(ar,name=co.CPer,ax=ax,perM=.95)

# %%
ax.figure.savefig('/tmp/map.pdf')

# %% [markdown]
# # new part

# %%
dsZ = dsSM

# %%
# %%
ds = xr.open_dataset(pat)

# %%
ds

# %%
ds['CONC'][{co.RL: 10}].sum(co.ZM).plot(y=co.R_CENTER, x=co.TH_CENTER)

# %%
da = ds.loc[{co.RL: '2018-01-10 15'}]

# %%
ax = fa.get_ax_bolivia()
fa.logpolar_plot(da.sum(co.ZM), ax=ax)

# %%
da

# %%
da

# %%
da = ds.loc[{co.RL: slice('2018-01-10 21', '2018-01-11 06')}]
da['dis'] = da[co.R_CENTER] * 100
da = da.assign_coords(dis=da['dis'])
da['CONC'].sum(co.TH_CENTER).\
plot(
    x='dis',figsize=(20,5),
    #     norm = mpl.colors.SymLogNorm(linthresh=10),
Example #14
0
def clus_plot(
        i_lab, ds: xr.Dataset,
        conc_lab=None,
        ds_lab=None,
        figure_size=15,
        dpi=400,
        fig_title: str = None,
        conc_lab_ts=None,
        df_prop=None
):
    if conc_lab is None:
        conc_lab = ds.attrs['chosen_smooth']
    if conc_lab_ts is None:
        conc_lab_ts = conc_lab

    r_dis_km: xr.DataArray = ds[co.R_CENTER] * 100
    r_dis_km = r_dis_km.assign_attrs({
        'units': 'km',
        'long_name': 'radial distance from CHC'
    })
    # return r_dis_km
    ds = ds.assign_coords(**{R_DIS_KM: r_dis_km})

    if ds_lab is None:
        ds_lab = ds[[conc_lab_ts, conc_lab]].where(ds['lab'] == i_lab)
    ds_lab = ds_lab.assign_coords(**{R_DIS_KM: r_dis_km})
    # print(ds_lab.attrs)
    cols = 10
    rows = 10
    f_len = figure_size
    f: plt.Figure = plt.figure(
        figsize=(f_len, cols / rows * f_len),
        dpi=dpi
    )
    xn = 2
    yn = 4
    xp = .07
    yp = .05
    ww = (1 - xp * 3) / xn
    hh = (1 - yp * 5) / yn
    # yy = .29
    # xx = .4
    # xxL = .55
    # ypos = .35
    l_lpb = ((2 * xp) + ww, (2 * yp) + hh, .8 * ww, hh)
    l_bol = ((2 * xp) + ww, yp, .8 * ww, hh)
    l_ts = (xp, 1 - yp - hh, 1 - 2 * xp, hh)
    l_per_inf = (xp, (3 * yp) + (2 * hh), ww, hh)
    l_far = (xp, yp, 1.2 * ww, hh)
    l_zoom = (xp, 2 * yp + hh, 1.2 * ww, hh)

    ax_vertical_far_: plt.Axes = f.add_axes(l_far)
    da_lab = ds_lab[conc_lab]
    da_lab.load()
    plot_vertical_ax(ax_vertical_far_, conc_lab, ds, da_lab)
    ax_vertical_far_.scatter(0, 5240, c='blue', label='CHC')
    ax_vertical_far_.legend()
    ax_vertical_far_.grid(True)
    ax_vertical_far_.set_axisbelow(False)

    ax_vertical_zoom = f.add_axes(l_zoom)
    plot_vertical_ax(ax_vertical_zoom, conc_lab, ds, da_lab,
                     xlim=(0, 200))
    ax_vertical_zoom.scatter(0, 5240, c='blue', label='CHC')
    ax_vertical_zoom.legend()
    ax_vertical_zoom.grid(True)
    ax_vertical_zoom.set_axisbelow(False)

    carree = crt.crs.PlateCarree()

    ax_lpb: cartopy.mpl.geoaxes.GeoAxesSubplot = \
        f.add_axes(l_lpb, projection=carree)

    cc_ = da_lab.sum([co.RL, co.ZM], keep_attrs=True)
    ax_lpb = fa.get_ax_lapaz(ax=ax_lpb)
    print(cc_.attrs)
    fa.logpolar_plot(cc_, name=conc_lab, ax=ax_lpb)

    ax_bol = f.add_axes(l_bol, projection=carree)
    lo_la_bol_range = 15
    lo_la_limits = [
        co.CHC_LON - lo_la_bol_range,
        co.CHC_LON + lo_la_bol_range,
        co.CHC_LAT - lo_la_bol_range,
        co.CHC_LAT + lo_la_bol_range,
    ]
    ax_bol = fa.get_ax_bolivia(ax=ax_bol, lola_extent=lo_la_limits)

    fa.logpolar_plot(cc_, name=conc_lab, ax=ax_bol)

    # noinspection PyUnusedLocal
    ax_ts = f.add_axes(l_ts)

    plot_lab_time_series(da_lab=ds_lab[conc_lab_ts], ax_ts=ax_ts)

    ax_per_inf = f.add_axes(l_per_inf)
    if df_prop is not None:
        plot_cluster_summary_figure(
            df_prop,
            'SRR [%]',
            'distance from CHC [km]',
            # save_fig=True,
            fig_save_name='dis_vs_srr_influence.pdf',
            xy_locs=([-30, 5], [0, 9], [500, 11], [950, 9]),
            y_range=(0, 13),
            add_vertical_lines=True,
            add_cluster_group_label=False,
            ax=ax_per_inf
        )
        y = df_prop.set_index('cluster_i')['SRR [%]'][i_lab]
        x = df_prop.set_index('cluster_i')['distance from CHC [km]'][i_lab]
        # ax_per_inf.scatter(x,y,c='k',s=10,marker='o')
        ax_per_inf.scatter(x, y, s=200, marker='o', facecolors='none',
                           edgecolors='k')

    # todo fix this
    else:
        plot_concentration_influence_div_by_cluster(
            ds=ds, conc_lab=conc_lab, i_lab=i_lab,
            ax=ax_per_inf
        )

    plt.show()
    if fig_title is None:
        f.suptitle(f'cluster: {i_lab}', y=.95)
    else:
        f.suptitle(fig_title, y=1)
    f.tight_layout()
    log.ger.debug('show plot')
    f.show()
    return f