Skip to content

Commit

Permalink
Try to remove invalid netcdf feature
Browse files Browse the repository at this point in the history
This should no longer be required with latest xarray/h5netcdf
  • Loading branch information
jenshnielsen committed Oct 25, 2024
1 parent 725ec6a commit 54ef65a
Showing 1 changed file with 16 additions and 33 deletions.
49 changes: 16 additions & 33 deletions src/qcodes/dataset/exporters/export_to_xarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,37 +256,20 @@ def xarray_to_h5netcdf_with_complex_numbers(
else:
internal_ds = xarray_dataset

data_var_kinds = [
internal_ds.data_vars[data_var].dtype.kind for data_var in internal_ds.data_vars
]
coord_kinds = [internal_ds.coords[coord].dtype.kind for coord in internal_ds.coords]
allow_invalid_netcdf = "c" in data_var_kinds or "c" in coord_kinds

with warnings.catch_warnings():
# see http://xarray.pydata.org/en/stable/howdoi.html
# for how to export complex numbers
if allow_invalid_netcdf:
warnings.filterwarnings(
"ignore",
module="h5netcdf",
message="You are writing invalid netcdf features",
category=UserWarning,
maybe_write_job = internal_ds.to_netcdf(
path=file_path,
engine="h5netcdf",
compute=compute,
)
if not compute and maybe_write_job is not None:
# Dask and therefor tqdm.dask is slow to
# import and only used here so defer the import
# to when required.
from tqdm.dask import TqdmCallback

with TqdmCallback(desc="Combining files"):
_LOG.info(
"Writing netcdf file using Dask delayed writer.",
extra={"file_name": file_path},
)
maybe_write_job = internal_ds.to_netcdf(
path=file_path,
engine="h5netcdf",
invalid_netcdf=allow_invalid_netcdf,
compute=compute,
)
if not compute and maybe_write_job is not None:
# Dask and therefor tqdm.dask is slow to
# import and only used here so defer the import
# to when required.
from tqdm.dask import TqdmCallback

with TqdmCallback(desc="Combining files"):
_LOG.info(
"Writing netcdf file using Dask delayed writer.",
extra={"file_name": file_path},
)
maybe_write_job.compute()
maybe_write_job.compute()

0 comments on commit 54ef65a

Please sign in to comment.