Production of a maximum reflectivity composite from 3 neighboring radars#

import tempfile

import xarray
import xradar
import matplotlib.pyplot

import wradlib
import wradlib_data

Get measurements from three belgian radars#

filenames = ["bejab.pvol.hdf", "bewid.pvol.hdf", "behel.pvol.hdf"]
paths = [wradlib_data.DATASETS.fetch(f"hdf5/{f}") for f in filenames]
volumes = [xradar.io.backends.odim.open_odim_datatree(p) for p in paths]
Downloading file 'hdf5/bejab.pvol.hdf' from 'https://github.com/wradlib/wradlib-data/raw/main/data/hdf5/bejab.pvol.hdf' to '/home/docs/.cache/wradlib-data'.
Downloading file 'hdf5/bewid.pvol.hdf' from 'https://github.com/wradlib/wradlib-data/raw/main/data/hdf5/bewid.pvol.hdf' to '/home/docs/.cache/wradlib-data'.
Downloading file 'hdf5/behel.pvol.hdf' from 'https://github.com/wradlib/wradlib-data/raw/main/data/hdf5/behel.pvol.hdf' to '/home/docs/.cache/wradlib-data'.
/home/docs/checkouts/readthedocs.org/user_builds/wradlib/conda/2.6.0/lib/python3.13/site-packages/xradar/io/backends/common.py:286: FutureWarning: In a future version of xarray the default value for compat will change from compat='no_conflicts' to compat='override'. This is likely to lead to different results when combining overlapping variables with the same name. To opt in to new defaults and get rid of these warnings now use `set_options(use_new_combine_kwarg_defaults=True) or set compat explicitly.
  subgroup = xr.merge([ds[extract_vars] for ds in ls_ds])
/home/docs/checkouts/readthedocs.org/user_builds/wradlib/conda/2.6.0/lib/python3.13/site-packages/xradar/io/backends/common.py:286: FutureWarning: In a future version of xarray the default value for compat will change from compat='no_conflicts' to compat='override'. This is likely to lead to different results when combining overlapping variables with the same name. To opt in to new defaults and get rid of these warnings now use `set_options(use_new_combine_kwarg_defaults=True) or set compat explicitly.
  subgroup = xr.merge([ds[extract_vars] for ds in ls_ds])
/home/docs/checkouts/readthedocs.org/user_builds/wradlib/conda/2.6.0/lib/python3.13/site-packages/xradar/io/backends/common.py:286: FutureWarning: In a future version of xarray the default value for compat will change from compat='no_conflicts' to compat='override'. This is likely to lead to different results when combining overlapping variables with the same name. To opt in to new defaults and get rid of these warnings now use `set_options(use_new_combine_kwarg_defaults=True) or set compat explicitly.
  subgroup = xr.merge([ds[extract_vars] for ds in ls_ds])
/home/docs/checkouts/readthedocs.org/user_builds/wradlib/conda/2.6.0/lib/python3.13/site-packages/xradar/io/backends/common.py:286: FutureWarning: In a future version of xarray the default value for compat will change from compat='no_conflicts' to compat='override'. This is likely to lead to different results when combining overlapping variables with the same name. To opt in to new defaults and get rid of these warnings now use `set_options(use_new_combine_kwarg_defaults=True) or set compat explicitly.
  subgroup = xr.merge([ds[extract_vars] for ds in ls_ds])
/home/docs/checkouts/readthedocs.org/user_builds/wradlib/conda/2.6.0/lib/python3.13/site-packages/xradar/io/backends/common.py:286: FutureWarning: In a future version of xarray the default value for compat will change from compat='no_conflicts' to compat='override'. This is likely to lead to different results when combining overlapping variables with the same name. To opt in to new defaults and get rid of these warnings now use `set_options(use_new_combine_kwarg_defaults=True) or set compat explicitly.
  subgroup = xr.merge([ds[extract_vars] for ds in ls_ds])
/home/docs/checkouts/readthedocs.org/user_builds/wradlib/conda/2.6.0/lib/python3.13/site-packages/xradar/io/backends/common.py:286: FutureWarning: In a future version of xarray the default value for compat will change from compat='no_conflicts' to compat='override'. This is likely to lead to different results when combining overlapping variables with the same name. To opt in to new defaults and get rid of these warnings now use `set_options(use_new_combine_kwarg_defaults=True) or set compat explicitly.
  subgroup = xr.merge([ds[extract_vars] for ds in ls_ds])
/home/docs/checkouts/readthedocs.org/user_builds/wradlib/conda/2.6.0/lib/python3.13/site-packages/xradar/io/backends/common.py:286: FutureWarning: In a future version of xarray the default value for compat will change from compat='no_conflicts' to compat='override'. This is likely to lead to different results when combining overlapping variables with the same name. To opt in to new defaults and get rid of these warnings now use `set_options(use_new_combine_kwarg_defaults=True) or set compat explicitly.
  subgroup = xr.merge([ds[extract_vars] for ds in ls_ds])
/home/docs/checkouts/readthedocs.org/user_builds/wradlib/conda/2.6.0/lib/python3.13/site-packages/xradar/io/backends/common.py:286: FutureWarning: In a future version of xarray the default value for compat will change from compat='no_conflicts' to compat='override'. This is likely to lead to different results when combining overlapping variables with the same name. To opt in to new defaults and get rid of these warnings now use `set_options(use_new_combine_kwarg_defaults=True) or set compat explicitly.
  subgroup = xr.merge([ds[extract_vars] for ds in ls_ds])
/home/docs/checkouts/readthedocs.org/user_builds/wradlib/conda/2.6.0/lib/python3.13/site-packages/xradar/io/backends/common.py:286: FutureWarning: In a future version of xarray the default value for compat will change from compat='no_conflicts' to compat='override'. This is likely to lead to different results when combining overlapping variables with the same name. To opt in to new defaults and get rid of these warnings now use `set_options(use_new_combine_kwarg_defaults=True) or set compat explicitly.
  subgroup = xr.merge([ds[extract_vars] for ds in ls_ds])
/home/docs/checkouts/readthedocs.org/user_builds/wradlib/conda/2.6.0/lib/python3.13/site-packages/xradar/io/backends/common.py:286: FutureWarning: In a future version of xarray the default value for compat will change from compat='no_conflicts' to compat='override'. This is likely to lead to different results when combining overlapping variables with the same name. To opt in to new defaults and get rid of these warnings now use `set_options(use_new_combine_kwarg_defaults=True) or set compat explicitly.
  subgroup = xr.merge([ds[extract_vars] for ds in ls_ds])
/home/docs/checkouts/readthedocs.org/user_builds/wradlib/conda/2.6.0/lib/python3.13/site-packages/xradar/io/backends/common.py:286: FutureWarning: In a future version of xarray the default value for compat will change from compat='no_conflicts' to compat='override'. This is likely to lead to different results when combining overlapping variables with the same name. To opt in to new defaults and get rid of these warnings now use `set_options(use_new_combine_kwarg_defaults=True) or set compat explicitly.
  subgroup = xr.merge([ds[extract_vars] for ds in ls_ds])
/home/docs/checkouts/readthedocs.org/user_builds/wradlib/conda/2.6.0/lib/python3.13/site-packages/xradar/io/backends/common.py:286: FutureWarning: In a future version of xarray the default value for compat will change from compat='no_conflicts' to compat='override'. This is likely to lead to different results when combining overlapping variables with the same name. To opt in to new defaults and get rid of these warnings now use `set_options(use_new_combine_kwarg_defaults=True) or set compat explicitly.
  subgroup = xr.merge([ds[extract_vars] for ds in ls_ds])
/home/docs/checkouts/readthedocs.org/user_builds/wradlib/conda/2.6.0/lib/python3.13/site-packages/xradar/io/backends/common.py:286: FutureWarning: In a future version of xarray the default value for compat will change from compat='no_conflicts' to compat='override'. This is likely to lead to different results when combining overlapping variables with the same name. To opt in to new defaults and get rid of these warnings now use `set_options(use_new_combine_kwarg_defaults=True) or set compat explicitly.
  subgroup = xr.merge([ds[extract_vars] for ds in ls_ds])
/home/docs/checkouts/readthedocs.org/user_builds/wradlib/conda/2.6.0/lib/python3.13/site-packages/xradar/io/backends/common.py:286: FutureWarning: In a future version of xarray the default value for compat will change from compat='no_conflicts' to compat='override'. This is likely to lead to different results when combining overlapping variables with the same name. To opt in to new defaults and get rid of these warnings now use `set_options(use_new_combine_kwarg_defaults=True) or set compat explicitly.
  subgroup = xr.merge([ds[extract_vars] for ds in ls_ds])
/home/docs/checkouts/readthedocs.org/user_builds/wradlib/conda/2.6.0/lib/python3.13/site-packages/xradar/io/backends/common.py:286: FutureWarning: In a future version of xarray the default value for compat will change from compat='no_conflicts' to compat='override'. This is likely to lead to different results when combining overlapping variables with the same name. To opt in to new defaults and get rid of these warnings now use `set_options(use_new_combine_kwarg_defaults=True) or set compat explicitly.
  subgroup = xr.merge([ds[extract_vars] for ds in ls_ds])
/home/docs/checkouts/readthedocs.org/user_builds/wradlib/conda/2.6.0/lib/python3.13/site-packages/xradar/io/backends/common.py:286: FutureWarning: In a future version of xarray the default value for compat will change from compat='no_conflicts' to compat='override'. This is likely to lead to different results when combining overlapping variables with the same name. To opt in to new defaults and get rid of these warnings now use `set_options(use_new_combine_kwarg_defaults=True) or set compat explicitly.
  subgroup = xr.merge([ds[extract_vars] for ds in ls_ds])
/home/docs/checkouts/readthedocs.org/user_builds/wradlib/conda/2.6.0/lib/python3.13/site-packages/xradar/io/backends/common.py:286: FutureWarning: In a future version of xarray the default value for compat will change from compat='no_conflicts' to compat='override'. This is likely to lead to different results when combining overlapping variables with the same name. To opt in to new defaults and get rid of these warnings now use `set_options(use_new_combine_kwarg_defaults=True) or set compat explicitly.
  subgroup = xr.merge([ds[extract_vars] for ds in ls_ds])
/home/docs/checkouts/readthedocs.org/user_builds/wradlib/conda/2.6.0/lib/python3.13/site-packages/xradar/io/backends/common.py:286: FutureWarning: In a future version of xarray the default value for compat will change from compat='no_conflicts' to compat='override'. This is likely to lead to different results when combining overlapping variables with the same name. To opt in to new defaults and get rid of these warnings now use `set_options(use_new_combine_kwarg_defaults=True) or set compat explicitly.
  subgroup = xr.merge([ds[extract_vars] for ds in ls_ds])

Define a raster dataset with projected coordinates#

europe_crs = 3035
bounds = [3614000, 2783000, 4200000, 3338000]
resolution = 1000
raster_projected = wradlib.georef.create_raster_xarray(
    crs=europe_crs,
    bounds=bounds,
    resolution=resolution,
)

Define a raster dataset with geographic coordinates#

bounds = [0, 48, 9, 53]
resolution = 1000
raster_geographic = wradlib.georef.create_raster_geographic(
    bounds=bounds, resolution=resolution, resolution_in_meters=True
)

Transform lowest sweep into a raster for each radar#

raster = {}
raster["projected"] = raster_projected
raster["geographic"] = raster_geographic
rasters = {}
for key in ["projected", "geographic"]:
    metadata = xradar.model.required_sweep_metadata_vars
    rasters_radar = []
    for volume in volumes:
        sweep = volume["sweep_0"].to_dataset()
        sweep = sweep[["DBZH"] + list(metadata)]
        sweep = sweep.sel(range=slice(0, 200e3))
        sweep = xradar.georeference.get_x_y_z(sweep)
        raster_radar = wradlib.comp.sweep_to_raster(
            sweep=sweep,
            raster=raster[key],
        )
        rasters_radar.append(raster_radar)

    for raster_radar in rasters_radar:
        raster_radar["DBZH"].plot(vmin=0, vmax=50)
        matplotlib.pyplot.axis("equal")
        matplotlib.pyplot.show()
    rasters[key] = rasters_radar
../../_images/50b3eeb26f26f503b45bd7f5d967e2de358aeaece58a20411a52c5ec5de51c82.png ../../_images/cefa849abfc867009309bc80525c6d2ac461dd837fe75c3003ab1c3647f35685.png ../../_images/2d363b08b299fd54339bab05d8ed415080f0d9f4787318f0a948c1750a903df9.png ../../_images/fbbc2abe99a7881dfc8bfce284fcecb2f6fcc0b309defd5e194f3c5105bf2043.png ../../_images/28620f12c6276a51c01d691c4ddf800e0de9cfd030a4da1a84706818747baec2.png ../../_images/80e37424ed4969e462f1e06c0548f6c2d95a6529f7f5be7c6b87e57f57884411.png

Take the maximum reflectivity value from the 3 rasters#

for key in ["projected", "geographic"]:
    rasters_concat = xarray.concat(rasters[key], dim="sweep")
    comp = rasters_concat.max(dim="sweep", keep_attrs=True)
    with tempfile.NamedTemporaryFile(suffix=".nc", delete=False) as tmp:
        comp.to_netcdf(tmp.name)
    comp = comp.drop_vars("spatial_ref")
    fig, ax = matplotlib.pyplot.subplots()
    comp["DBZH"].plot(ax=ax, vmin=0, vmax=50)
    ax.set_title(key)
../../_images/4da2346c5c63f54beba7b09ab835bbcb9f416ca5ee523f5f02bd75adfa793098.png ../../_images/ecc9f4597e6e7674d3bcff82b330c177b4212587fe9604dcc10260e4e7de423e.png