Ejemplo n.º 1
0
def plot_distance_height_chc(_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.TH_CENTER])

        _ds = _ds[[co.CONC]]

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

        _km = _ds[co.R_CENTER] * 100

        DIS = 'Distance [km]'
        _km.name = DIS

        _ds = _ds.assign_coords(**{DIS: _km})
        _, ax = plt.subplots()
        _ds[co.CONC].plot(x=DIS, cmap=_cm, ax=ax)
        ax.set_xscale('log')
        ax.set_yscale('log')
        ax.set_xlim(10, 2e3)
        ax.set_ylim(25e1, 2e4)
        ax.set_title(str(_f))
Ejemplo n.º 2
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)
Ejemplo n.º 3
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)
Ejemplo n.º 4
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)
Ejemplo n.º 5
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)
Ejemplo n.º 6
0
 def plot_clust_height(self,
                       ax: plt.Axes,
                       i,
                       perM,
                       drop_zero=True,
                       par_to_plot=co.COL):
     clus = self.cluster_flags[i]
     boo = self.merged_ds[co.ClusFlag] == clus
     ar = self.merged_ds[par_to_plot].where(boo)
     com = fa.get_dims_complement(ar, [co.R_CENTER, co.ZM])
     ar = ar.sum(dim=com)
     if par_to_plot is co.CPer:
         ar = ar / self.merged_ds[par_to_plot].sum() * 100
     if drop_zero:
         ar = ar.where(ar > 0)
     q = ar.quantile(perM)
     lab = "km from CHC"
     ar[lab] = ar[co.R_CENTER] * 100
     ar = ar.swap_dims({co.R_CENTER: lab})
     try:
         ar.name = co.PLOT_LABS[par_to_plot]
     except AssertionError as error:
         log.ger.error(error)
         pass
     ar.plot(
         cmap=fa.get_custom_cmap(self.colors[i]),
         vmin=0,
         vmax=q,
         ax=ax,
         x=lab,
     )
     ax.set_yscale('log')
     ax.set_ylim(100, 20000)
     ax.set_xscale('log')
     ax.set_xlim(.05 * 100, 30 * 100)
     ax.grid(True, 'major', axis='y')
     ax.grid(True, 'both', axis='x')
     ax.set_ylabel(co.PLOT_LABS[co.ZM])
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,
                     ax,
                     name=co.CCPer,
                     perM=.05,
#                 patch_args={'cmap':cmap}
#             )
#     ax.set_xlim(-75,-60)
#     ax.set_title(ii)
#     yl=ax.set_ylim(-25,-7)

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

# %%
ii=5
ds_fl = dsZ[co.CPer].where(dsZ[co.ClusFlag]==ii)

# %%
ax = fa.get_ax_bolivia()
cmap = fa.get_custom_cmap(self.colors[ii])
fa.logpolar_plot(ds_fl.sum([co.RL,co.ZM]),
                 name=co.CPer,ax=ax,
                 patch_args={'cmap':cmap}
                )
ax.set_xlim(-75,-60)
yl=ax.set_ylim(-25,-7)

# %%
import simplekml

# %%
import simplekml
kml = simplekml.Kml()

# %%
Ejemplo n.º 9
0
    def plot_absolute_height(self,
                             i,
                             ax=None,
                             perM=.95,
                             drop_zero=True,
                             par_to_plit=co.COL):
        mer = self.merged_ds.copy()
        # i = 6
        clus = self.cluster_flags[i]

        H = co.H
        fla = co.FLAGS
        HC = 'H*CONC'

        ver_area = 'VER_AREA'
        log_center = np.log(mer[co.R_CENTER])
        dis = log_center - \
              log_center.shift({co.R_CENTER: 1})
        dis = dis.median()
        l1 = log_center - dis / 2
        l2 = log_center + dis / 2
        l1 = np.e**l1
        l2 = np.e**l2
        r_dis = (l2 - l1) * 100000
        zlen = 500
        ar = np.arange(zlen / 2, 20000, zlen)

        mer = mer[[co.CONC, fla, co.TOPO]]

        # return merged_ds

        mer = mer.where(mer[fla] == clus, 0)

        mer['c/v'] = mer[co.CONC] / mer[co.VOL]

        mer = mer.interp(**{co.ZM: ar})

        mer[co.VOL] = mer[co.GA] * zlen
        mer[co.CONC] = mer['c/v'] * mer[co.VOL]

        mer[H] = mer[co.TOPO] + mer[co.ZM]

        mer[HC] = mer[H] * mer[co.CONC]

        var = [co.CONC, HC]
        com = fa.get_dims_complement(mer, [co.R_CENTER, co.ZM])
        ms = mer[var].sum(com)

        ms[ver_area] = ms[co.ZLM] * r_dis

        # ms:xr.DataArray = ms/ms[ver_area]

        ms[co.CONC] = ms[co.CONC].where(ms[co.CONC] > 0, 0)

        # ms = ms*zlen*r_dis

        ms[H] = ms[HC] / ms[co.CONC]

        def find_nearest(value):
            #     ar = self.get_z_lin()
            array = np.asarray(ar)
            idx = (np.abs(array - value)).argmin()
            return array[idx]

        ms[H] = xr.apply_ufunc(find_nearest, ms[H], vectorize=True)

        hs = ms.to_dataframe().groupby([H, co.R_CENTER
                                        ]).sum()[co.CONC].to_xarray()

        lab = "km from CHC"
        hs[lab] = hs[co.R_CENTER] * 100
        hs = hs.swap_dims({co.R_CENTER: lab})

        hs1 = hs.interp(**{H: ar})
        hs1 = hs1.combine_first(hs)

        if drop_zero:
            hs1 = hs1.where(hs1 > 0)

        if ax is None:
            fig, ax = plt.subplots(figsize=(10, 5))

        hs1 = hs1 / self.merged_ds[co.CONC].sum() * 100
        hs1.name = co.CPer
        q = hs1.quantile(perM)

        hs1.name = co.PLOT_LABS[co.CPer]

        hs1.plot(
            cmap=fa.get_custom_cmap(self.colors[i]),
            vmin=0,
            vmax=q,
            ax=ax,
            x=lab,
        )
        ax.set_ylim(100, 20000)
        ax.set_xscale('log')
        ax.set_xlim(.05 * 100, 30 * 100)
        ax.grid(True, 'major', axis='y')
        ax.grid(True, 'both', axis='x')
        ax.set_ylabel(co.PLOT_LABS[co.H])
Ejemplo n.º 10
0
def plot_dis_height_quantiles_chc_single(_f, _n, dsF, dscc, axs=None):
    if axs is None:
        _, ax = plt.subplots()
    else:
        if type(axs) == np.ndarray:
            ax = axs[_f]
        else:
            ax = axs

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

    _ds = dscc.loc[{co.CLUS_LENGTH_DIM: _n}]

    _ds = _ds.drop(co.KMEAN_OBJ)

    _ds = _ds.sum([co.RL])

    _ds1 = xr.merge([_ds, dsF[[co.TOPO]]]).where(
        _ds[co.FLAG] == _f)
    _ds1 = _ds1.swap_dims({co.R_CENTER: co.DIS})

    _ds2 = _ds1 / dsF[co.ZLM]

    _ds3 = _ds2[co.CONC]
    zmin, zmax = _ds2[co.ZM].quantile([0, 1])
    zz = np.arange(zmin, zmax, zmin)

    zl = zz[1] - zz[0]

    _ds4 = _ds3.interp(**{co.ZM: zz}) * zl

    ZREAL = 'ZREAL'
    _ds4[ZREAL] = _ds4 * 0 + _ds4[co.ZM] + (
            (_ds4[co.TOPO] / zl).round() * zl)

    _dims = set(_ds4.dims)

    _keep = _dims.union({ZREAL})

    # noinspection SpellCheckingInspection
    _coor = set(_ds4.coords)

    _drop = list(_coor - _keep)

    _ds5 = _ds4.drop(_drop).to_dataframe()

    _ds6 = \
        _ds5.reset_index().groupby([ZREAL, co.DIS, co.TH_CENTER]).sum()[
            [co.CONC]].to_xarray()

    _ds6.sum(co.TH_CENTER)[co.CONC].plot(xscale='log', vmin=0, ax=ax,
                                         cmap=_cm)

    HEIGHT = 'HEIGHT'
    _ds1[HEIGHT] = (_ds1[co.TOPO] + _ds1[co.ZM])

    _dg = _ds1[[HEIGHT, co.CONC]].to_dataframe()[[HEIGHT, co.CONC]]
    _dg = _dg.groupby(co.DIS)

    _dh = (_ds1[co.CONC] * (_ds1[co.TOPO] + _ds1[co.ZM])).mean(
        [co.TH_CENTER, co.ZM])
    _dh = _dh / (_ds1[co.CONC].mean([co.TH_CENTER, co.ZM]))

    ax.set_xlim(10, 2e3)

    _dh = (_ds1[co.CONC] * (_ds1[co.TOPO])).mean([co.TH_CENTER, co.ZM])
    _dh = _dh / (_ds1[co.CONC].mean([co.TH_CENTER, co.ZM]))

    _dh.plot(x=co.DIS, color='k', ax=ax)
    ax.set_xscale('log')

    ax.set_xlim(5, 2e3)
    ax.set_ylim(0, 1.5e4)
    ax.set_title(str(_f))
    ax.set_xlabel('Radial distance from CHC [km]')
    ax.set_ylabel('Height [masl]')
    ax.grid(color='k', alpha=.3, linestyle='--')
    ax.set_axisbelow(False)
    ax.set_facecolor('white')
    ax: plt.Axes = ax
    ax.scatter(5.2, 5200, color='red')
    ax.text(6, 5200, 'CHC')