Guys ,iam struggling to plot CFAD OF REFLECTIVITY for stratiform and convective for a specific extent region FROM GPM DPR 2A, can any one help me ?
Maybe @ghiggi can assist you, and in the meantime, you can familiarize yourself with the GPM API documentation.
Hi @ankithva.
If you follow the GPM-API tutorials you will understand how to open the DPR dataset and subset over geographic regions or area of interest (see also this tutorial)
Then you can use the following code to identify stratiform and convective DPR footprints and compute CFAD diagrams:
from matplotlib.colors import LogNorm , Normalize
from xhistogram.xarray import histogram
# Retrieve precipitation type
ds["flagPrecipitationType"] = ds.gpm.retrieve(
"flagPrecipitationType", method="major_rain_type"
).compute()
ds["flagPrecipitationType"].gpm.plot_map()
# Select stratiform or convective footprints
ds_footprints = ds.stack(dim={"footprints": ['cross_track', 'along_track']})
ds_footprints_convective = ds_footprints.isel({"footprints": ds_footprints["flagPrecipitationType"] == 1})
ds_footprints_stratiform = ds_footprints.isel({"footprints": ds_footprints["flagPrecipitationType"].isin([2,3])})
# Define reflectivity bins
reflectivity_bins = np.arange(10, 60, step=0.5)
height_bins = np.arange(0, 15_000, step=250)
for ds_dpr in [ds_footprints_convective, ds_footprints_stratiform]:
# Retrieve Ku reflectivity
da_ku = ds_dpr["zFactorFinal"].sel(radar_frequency="Ku").compute()
# CFAD with range on y axis
da_dens = histogram(da_ku, bins=reflectivity_bins, dim=["footprints"], density=False)
da_dens = da_dens.where(da_dens > 0)
norm = Normalize(vmin=10, vmax=None)
# norm = LogNorm(vmin=10, vmax=None)
da_dens.plot.imshow(x="zFactorFinal_bin", y="range", origin="upper", cmap="Spectral_r", norm=norm, extend="both")
plt.show()
# CFAD with height on y axis
da_ku_gates = da_ku.reset_index("footprints").stack(dim={"gates": ['footprints', 'range']})
da_dens = histogram(da_ku_gates, da_ku_gates["height"],
bins=[reflectivity_bins, height_bins]
)
da_dens = da_dens.where(da_dens > 0)
da_dens.plot.imshow(x="zFactorFinal_bin", y="height_bin", origin="lower", cmap="Spectral_r", extend="both")
plt.show()
facing some issue when installing gpm-api and importing gpm
ImportError Traceback (most recent call last)
Cell In[10], line 2
1 import datetime
----> 2 import gpm
3 import fsspec
4 import numpy as np
File ~/miniconda3/envs/gpmapi/lib/python3.11/site-packages/gpm/init.py:44
39 from gpm.configs import ( # noqa
40 define_configs,
41 read_configs,
42 )
43 from gpm.dataset.dataset import open_dataset # noqa
—> 44 from gpm.dataset.datatree import open_datatree # noqa
45 from gpm.dataset.granule import open_granule # noqa
46 from gpm.io.download import download_archive as download # noqa
File ~/miniconda3/envs/gpmapi/lib/python3.11/site-packages/gpm/dataset/datatree.py:30
27 “”“This module contains functions to read a GPM granule into a DataTree object.”“”
28 import os
—> 30 import datatree
31 import xarray as xr
33 import gpm
File ~/miniconda3/envs/gpmapi/lib/python3.11/site-packages/datatree/init.py:2
1 # import public API
----> 2 from .datatree import DataTree
3 from .extensions import register_datatree_accessor
4 from .io import open_datatree
File ~/miniconda3/envs/gpmapi/lib/python3.11/site-packages/datatree/datatree.py:33
31 from xarray.core.merge import dataset_update_method
32 from xarray.core.options import OPTIONS as XR_OPTS
—> 33 from xarray.core.utils import (
34 Default,
35 Frozen,
36 HybridMappingProxy,
37 _default,
38 either_dict_or_kwargs,
39 maybe_wrap_array,
40 )
41 from xarray.core.variable import Variable
43 from . import formatting, formatting_html
ImportError: cannot import name ‘HybridMappingProxy’ from ‘xarray.core.utils’ (/home/ankith/miniconda3/envs/gpmapi/lib/python3.11/site-packages/xarray/core/utils.py)
The new GPM-API release coming out on Monday will resolve the problem.
It’s caused by deprecations occured in xarray 2024.11.
Meanwhile, you can install an old version of xarray, or you wait on monday for the new GPM-API release.
Cheers
Gio
@ankithva I released a new gpm-api version. Ensure to update also xarray and pycolorbar to the latest version