can xradar read Cfradial2 netcdf files?
Hi all. I just got a file in "cfradial2" format. It contains groups instead a single netcdf. Do we need to create a new backend for this kind of files or we can addapt cfradial1 backend. Attached, you will find a copy of the file
import xradar as xd
path = "radar-cfradial2.nc"
radar = xd.io.open_cfradial1_datatree(path)
returns this error
Traceback (most recent call last):
File "/media/alfonso/drive/Alfonso/python/demos/era5-ingestion/truweather.py", line 23, in <module>
radar = xd.io.open_cfradial1_datatree(path)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/alfonso/mambaforge/envs/raw2zarr-dev/lib/python3.12/site-packages/xradar/io/backends/cfradial1.py", line 355, in open_cfradial1_datatree
"/": _get_required_root_dataset(ds, optional=optional),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/alfonso/mambaforge/envs/raw2zarr-dev/lib/python3.12/site-packages/xradar/io/backends/cfradial1.py", line 82, in _get_required_root_dataset
root = root.rename_vars(
^^^^^^^^^^^^^^^^^
File "/home/alfonso/mambaforge/envs/raw2zarr-dev/lib/python3.12/site-packages/xarray/core/dataset.py", line 4234, in rename_vars
raise ValueError(
ValueError: cannot rename 'sweep_number' because it is not a variable or coordinate in this dataset
this is because is a Netcdf file with nested groups. we can check it out using xarray.open_groups or xarray.open_datatree
groups = xr.open_groups(path)
print(groups)
{'/': <xarray.Dataset> Size: 40B
Dimensions: (nsweep: 1)
Dimensions without coordinates: nsweep
Data variables:
sweep_group_name (nsweep) <U10 40B ...
Attributes:
Conventions: CF-1.7, Cf/Radial
version: 2.0
title: Radar CfRadial2 Dataset
history: Updated CfRadial2 on 2025-05-01T00:46:09.040110Z
RadarName: denton.tx
Latitude: 33.25355
Longitude: -97.15204
Height: 224.0,
'/sweep_0000': <xarray.Dataset> Size: 27MB
Dimensions: (ntime: 723, nrange: 1003)
Dimensions without coordinates: ntime, nrange
Data variables: (12/19)
time_us (ntime) datetime64[ns] 6kB ...
range_m (nrange) float64 8kB ...
azimuth_deg (ntime) float64 6kB ...
elevation_deg (ntime) float64 6kB ...
range_gate_width_mm (ntime) float64 6kB ...
start_range_mm (ntime) float64 6kB ...
... ...
specific_differential_phase (ntime, nrange) float32 3MB ...
radial_velocity_mps (ntime, nrange) float32 3MB ...
signal_to_noise_ratio_db (ntime, nrange) float32 3MB ...
spectral_width_mps (ntime, nrange) float32 3MB ...
filtering (ntime, nrange) int8 725kB ...
rain_rate_mmhr (ntime, nrange) float32 3MB ...
Attributes:
NumGates: 1003
ScanType: 2
AntennaGain: 33.0
AntennaBeamwidth: 2.7
PosVelocity: 15.0}
Let me know your thoughts.
File can be found in this link
In general, cfradial2 should be read by xarray.open_datatree. No additional backend needed, IMHO.
I would be in favor of having a
open_cfradial2_datatree(path)
function under the io module, which calls xarray.open_datatree for consistency?
I agree with @mgrover1, I can quickly create one, since it is pretty straight forward.
https://github.com/openradar/xradar/issues/93
Seems like still a good idea to do it anyway. At least as compatibility layer and for consistency as @mgrover1 suggested.
@syedhamidali please go ahead, if you have the bandwidth. :+1:
I will paste here my comments under #288.
Hi everyone,
Thanks for putting all of this together. I was looking at the cfradial2 data, and I can see it has a hierarchical structure with a root dataset as well as the sweep nodes. However, is this file fully FM301 compliant? I notice something like the root contains some attributes, but does it contain all the required attributes under the FM301 data model?
print(dtree['/'].ds)
<xarray.Dataset> Size: 40B
Dimensions: (nsweep: 1)
Dimensions without coordinates: nsweep
Data variables:
sweep_group_name (nsweep) <U10 40B ...
Attributes:
Conventions: CF-1.7, Cf/Radial
version: 2.0
title: Radar CfRadial2 Dataset
history: Updated CfRadial2 on 2025-05-01T00:46:09.040110Z
RadarName: denton.tx
Latitude: 33.25355
Longitude: -97.15204
Height: 224.0
On the other hand, I realized the dataset contains sweeps numbered as sweep_xxxx, is this the "correct" way to number the sweep under the WMO data model? Finally, I also realized this dataset contains coordinates and dimensions that I am not sure are cfradrial-FM301 compliant.
print(dtree['/sweep_0000']. ds
<xarray.Dataset> Size: 27MB
Dimensions: (ntime: 723, nrange: 1003)
Dimensions without coordinates: ntime, nrange
Data variables: (12/19)
time_us (ntime) datetime64[ns] 6kB ...
range_m (nrange) float64 8kB ...
azimuth_deg (ntime) float64 6kB ...
elevation_deg (ntime) float64 6kB ...
range_gate_width_mm (ntime) float64 6kB ...
start_range_mm (ntime) float64 6kB ...
... ...
specific_differential_phase (ntime, nrange) float32 3MB ...
radial_velocity_mps (ntime, nrange) float32 3MB ...
signal_to_noise_ratio_db (ntime, nrange) float32 3MB ...
spectral_width_mps (ntime, nrange) float32 3MB ...
filtering (ntime, nrange) int8 725kB ...
rain_rate_mmhr (ntime, nrange) float32 3MB ...
Attributes:
NumGates: 1003
ScanType: 2
AntennaGain: 33.0
AntennaBeamwidth: 2.7
PosVelocity: 15.0
Please let me know your thoughts