Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/notebooks/CfRadial1_Model_Transformation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"source": [
"## Open CfRadial1 file using xr.open_dataset\n",
"\n",
"Making use of the xarray `netcdf4` backend. We get back all data and metadata in one single CfRadial1 Dataset. Since xarray 2025.04.0 we have to use `decode_timedalte=False` to prevent erroneous decoding of timedelta values for eg. pulse widths."
"Making use of the xarray `h5netcdf` backend. We get back all data and metadata in one single CfRadial1 Dataset. Since xarray 2025.04.0 we have to use `decode_timedalte=False` to prevent erroneous decoding of timedelta values for eg. pulse widths."
]
},
{
Expand All @@ -67,7 +67,7 @@
"metadata": {},
"outputs": [],
"source": [
"ds = xr.open_dataset(filename, engine=\"netcdf4\", decode_timedelta=False)\n",
"ds = xr.open_dataset(filename, engine=\"h5netcdf\", decode_timedelta=False)\n",
"with xr.set_options(\n",
" display_expand_data_vars=True, display_expand_attrs=True, display_max_rows=1000\n",
"):\n",
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ dask
h5netcdf >= 1.0.0
h5py >= 3.0.0
lat_lon_parser
netCDF4
numpy
pyproj
scipy
Expand Down
22 changes: 7 additions & 15 deletions xradar/io/backends/cfradial1.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@

import numpy as np
from xarray import Dataset, DataTree, merge, open_dataset
from xarray.backends import NetCDF4DataStore
from xarray.backends.common import BackendEntrypoint
from xarray.backends.store import StoreBackendEntrypoint

from ... import util
from ...model import (
Expand Down Expand Up @@ -328,7 +326,7 @@ def open_cfradial1_datatree(filename_or_obj, **kwargs):
site_coords : bool
Attach radar site-coordinates to Dataset, defaults to ``True``.
engine: str
Engine that will be passed to Xarray.open_dataset, defaults to "netcdf4"
Engine that will be passed to xarray.open_dataset, defaults to "h5netcdf"

Returns
-------
Expand All @@ -341,12 +339,12 @@ def open_cfradial1_datatree(filename_or_obj, **kwargs):
optional = kwargs.pop("optional", True)
site_coords = kwargs.pop("site_coords", True)
sweep = kwargs.pop("sweep", None)
engine = kwargs.pop("engine", "netcdf4")
engine = kwargs.pop("engine", "h5netcdf")
# needed for new xarray literal timedelta decoding
kwargs.update(decode_timedelta=kwargs.pop("decode_timedelta", False))

# open root group, cfradial1 only has one group
# open_cfradial1_datatree only opens the file once using netcdf4
# open_cfradial1_datatree only opens the file once using h5netcdf
# and retrieves the different groups from the loaded object
ds = open_dataset(filename_or_obj, engine=engine, **kwargs)

Expand Down Expand Up @@ -396,7 +394,7 @@ class CfRadial1BackendEntrypoint(BackendEntrypoint):
Additional kwargs are fed to :py:func:`xarray.open_dataset`.
"""

description = "Open CfRadial1 (.nc, .nc4) using netCDF4 in Xarray"
description = "Open CfRadial1 (.nc, .nc4) using h5netcdf in xarray"
url = "https://xradar.rtfd.io/en/latest/io.html#cfradial1"

def open_dataset(
Expand All @@ -418,16 +416,10 @@ def open_dataset(
site_coords=True,
optional=True,
):
store = NetCDF4DataStore.open(
# Open using h5netcdf engine and then construct the CfRadial1 view
ds0 = open_dataset(
filename_or_obj,
format=format,
group=None,
)

store_entrypoint = StoreBackendEntrypoint()

ds0 = store_entrypoint.open_dataset(
store,
engine="h5netcdf",
mask_and_scale=mask_and_scale,
decode_times=decode_times,
concat_characters=concat_characters,
Expand Down
3 changes: 2 additions & 1 deletion xradar/io/export/cfradial1.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,4 +328,5 @@ def to_cfradial1(dtree=None, filename=None, calibs=True):
time = str(dataset.time[0].dt.strftime("%Y%m%d_%H%M%S").values)
filename = f"cfrad1_{dataset.instrument_name}_{time}.nc"

dataset.to_netcdf(filename, format="netcdf4")
# Write using h5netcdf backend to avoid netCDF4 dependency
dataset.to_netcdf(filename, engine="h5netcdf")
Loading