Computing cartesian and geographical coordinates for polar data#

import warnings

import wradlib as wrl
import wradlib_data
import xradar as xd
from IPython.display import display

warnings.filterwarnings("ignore")

Read the data#

Here, we use an OPERA hdf5 dataset.

filename = "hdf5/20130429043000.rad.bewid.pvol.dbzh.scan1.hdf"
filename = wradlib_data.DATASETS.fetch(filename)
pvol = xd.io.open_odim_datatree(filename)
display(pvol)
<xarray.DataTree>
Group: /
β”‚   Dimensions:              (sweep: 5)
β”‚   Coordinates:
β”‚       latitude             float64 8B ...
β”‚       longitude            float64 8B ...
β”‚       altitude             float64 8B ...
β”‚   Dimensions without coordinates: sweep
β”‚   Data variables:
β”‚       volume_number        int64 8B 0
β”‚       platform_type        <U5 20B 'fixed'
β”‚       instrument_type      <U5 20B 'radar'
β”‚       time_coverage_start  <U20 80B '2013-04-29T04:30:00Z'
β”‚       time_coverage_end    <U20 80B '2013-04-29T04:31:39Z'
β”‚       sweep_fixed_angle    (sweep) float64 40B 0.3 0.9 1.8 3.3 6.0
β”‚       sweep_group_name     (sweep) int64 40B 0 1 2 3 4
β”‚   Attributes:
β”‚       Conventions:      ODIM_H5/V2_2
β”‚       instrument_name:  None
β”‚       version:          None
β”‚       title:            None
β”‚       institution:      None
β”‚       references:       None
β”‚       source:           None
β”‚       history:          None
β”‚       comment:          im/exported using xradar
β”œβ”€β”€ Group: /sweep_0
β”‚       Dimensions:            (azimuth: 360, range: 960)
β”‚       Coordinates:
β”‚         * azimuth            (azimuth) float32 1kB 0.5 1.5 2.5 ... 357.5 358.5 359.5
β”‚           elevation          (azimuth) float64 3kB ...
β”‚           time               (azimuth) datetime64[ns] 3kB 2013-04-29T04:30:00.02777...
β”‚         * range              (range) float32 4kB 125.0 375.0 ... 2.396e+05 2.399e+05
β”‚       Data variables:
β”‚           DBZH               (azimuth, range) float64 3MB ...
β”‚           sweep_mode         <U20 80B ...
β”‚           sweep_number       int64 8B ...
β”‚           prt_mode           <U7 28B ...
β”‚           follow_mode        <U7 28B ...
β”‚           sweep_fixed_angle  float64 8B ...
β”‚           nyquist_velocity   float64 8B ...
β”œβ”€β”€ Group: /sweep_1
β”‚       Dimensions:            (azimuth: 360, range: 960)
β”‚       Coordinates:
β”‚         * azimuth            (azimuth) float32 1kB 0.5 1.5 2.5 ... 357.5 358.5 359.5
β”‚           elevation          (azimuth) float64 3kB ...
β”‚           time               (azimuth) datetime64[ns] 3kB 2013-04-29T04:30:20.02777...
β”‚         * range              (range) float32 4kB 125.0 375.0 ... 2.396e+05 2.399e+05
β”‚       Data variables:
β”‚           DBZH               (azimuth, range) float64 3MB ...
β”‚           sweep_mode         <U20 80B ...
β”‚           sweep_number       int64 8B ...
β”‚           prt_mode           <U7 28B ...
β”‚           follow_mode        <U7 28B ...
β”‚           sweep_fixed_angle  float64 8B ...
β”‚           nyquist_velocity   float64 8B ...
β”œβ”€β”€ Group: /sweep_2
β”‚       Dimensions:            (azimuth: 360, range: 960)
β”‚       Coordinates:
β”‚         * azimuth            (azimuth) float32 1kB 0.5 1.5 2.5 ... 357.5 358.5 359.5
β”‚           elevation          (azimuth) float64 3kB ...
β”‚           time               (azimuth) datetime64[ns] 3kB 2013-04-29T04:30:40.02777...
β”‚         * range              (range) float32 4kB 125.0 375.0 ... 2.396e+05 2.399e+05
β”‚       Data variables:
β”‚           DBZH               (azimuth, range) float64 3MB ...
β”‚           sweep_mode         <U20 80B ...
β”‚           sweep_number       int64 8B ...
β”‚           prt_mode           <U7 28B ...
β”‚           follow_mode        <U7 28B ...
β”‚           sweep_fixed_angle  float64 8B ...
β”‚           nyquist_velocity   float64 8B ...
β”œβ”€β”€ Group: /sweep_3
β”‚       Dimensions:            (azimuth: 360, range: 960)
β”‚       Coordinates:
β”‚         * azimuth            (azimuth) float32 1kB 0.5 1.5 2.5 ... 357.5 358.5 359.5
β”‚           elevation          (azimuth) float64 3kB ...
β”‚           time               (azimuth) datetime64[ns] 3kB 2013-04-29T04:31:00.02777...
β”‚         * range              (range) float32 4kB 125.0 375.0 ... 2.396e+05 2.399e+05
β”‚       Data variables:
β”‚           DBZH               (azimuth, range) float64 3MB ...
β”‚           sweep_mode         <U20 80B ...
β”‚           sweep_number       int64 8B ...
β”‚           prt_mode           <U7 28B ...
β”‚           follow_mode        <U7 28B ...
β”‚           sweep_fixed_angle  float64 8B ...
β”‚           nyquist_velocity   float64 8B ...
└── Group: /sweep_4
        Dimensions:            (azimuth: 360, range: 960)
        Coordinates:
          * azimuth            (azimuth) float32 1kB 0.5 1.5 2.5 ... 357.5 358.5 359.5
            elevation          (azimuth) float64 3kB ...
            time               (azimuth) datetime64[ns] 3kB 2013-04-29T04:31:20.02777...
          * range              (range) float32 4kB 125.0 375.0 ... 2.396e+05 2.399e+05
        Data variables:
            DBZH               (azimuth, range) float64 3MB ...
            sweep_mode         <U20 80B ...
            sweep_number       int64 8B ...
            prt_mode           <U7 28B ...
            follow_mode        <U7 28B ...
            sweep_fixed_angle  float64 8B ...
            nyquist_velocity   float64 8B ...

Retrieve azimuthal equidistant coordinates and projection#

for key in list(pvol.children):
    if "sweep" in key:
        pvol[key].ds = pvol[key].to_dataset(inherit="all_coords").wrl.georef.georeference()
pvol["sweep_0"].ds.DBZH.plot(x="x", y="y")
<matplotlib.collections.QuadMesh at 0x7f977b0edd30>
../../_images/c3e056ee879d72cdc613226042a29007bd46190e7a6d25cf34a96ccbc18dc9b3.png

Retrieve geographic coordinates (longitude and latitude)#

Using crs-keyword argument.#

for key in list(pvol.children):
    if "sweep" in key:
        pvol[key].ds = pvol[key].ds.wrl.georef.georeference(
            crs=wrl.georef.get_default_projection()
        )
ds1 = pvol["sweep_0"].ds.wrl.georef.georeference(
    crs=wrl.georef.get_default_projection()
)
ds1.DBZH.plot(x="x", y="y")
<matplotlib.collections.QuadMesh at 0x7f9772fa02d0>
../../_images/1d78cdfcf255ee8d0d49e14bbe1a416c0c7fc05cfe3c104e3c362242b8101ef6.png

Using reproject#

ds2 = pvol["sweep_0"].ds.wrl.georef.reproject(
    trg_crs=wrl.georef.epsg_to_osr(32632),
)
ds2.DBZH.plot(x="x", y="y")
<matplotlib.collections.QuadMesh at 0x7f97797f7390>
../../_images/473321af6fd7faafbed20826c05223753daaaf61b59ec7373bf594a935775bd4.png