xeofs icon indicating copy to clipboard operation
xeofs copied to clipboard

Cannot save complex/Hilbert models with `engine=netcdf4`

Open nicrie opened this issue 1 year ago • 2 comments

Describe the bug Trying to save a complex/Hilbert model with engine=netcdf4 results in the following error:

TypeError: illegal primitive data type, must be one of dict_keys(['S1', 'i1', 'u1', 'i2', 'u2', 'i4', 'u4', 'i8', 'u8', 'f4', 'f8']), got complex128

Reproducible Minimal Working Example Provide a concise Python code snippet that demonstrates the issue. To display the code clearly, use GitHub Flavored Markdown for formatting:

import xarray as xr
import xeofs as xe

t2m = xr.tutorial.open_dataset("air_temperature").air
heof = xe.models.HilbertEOF()
heof.fit(t2m, "time")
heof.save("test.nc", engine="netcdf4")

Expected behavior A clear and concise description of what you expected to happen.

Desktop (please complete the following information):

  • OS: Ubuntu 22
  • xeofs version 2.4.1

Additional context None

nicrie avatar Sep 03 '24 17:09 nicrie

Complex support has only very recently been added upstream to netcdf4, and I don't think it's quite available from xarray yet.

engine='h5netcdf', invalid_netcdf=True should work so long as we are properly passing through extra kwargs. engine='zarr' should also work.

slevang avatar Sep 03 '24 17:09 slevang

nice, good to know! I think a clearer error message could be really helpful for the user, maybe just mentioning that the other formats are supported.

nicrie avatar Sep 03 '24 21:09 nicrie