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
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)