-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New library for handling complex numbers in netCDF #8288
Comments
Hi @ZedThree this looks like a great improvement. We've built out infrastructure that would allow you to pass Can you give that a try and let us know how it goes? |
Thanks @dcherian, I've had a look and implemented my own backend. It does work fine, but unfortunately it takes about 170 lines as I need to duplicate a lot of the existing netcdf4 backend in order to change two lines. I'm worried I'd need to keep this up-to-date with xarray. I think the only thing from class NetCDF4DataStore(WritableCFDataStore):
...
@property
def DatasetClass(self) -> type:
import netCDF4
return netCDF4.Dataset
class NcComplexDataStore(NetCDF4DataStore):
@property
def DatasetClass(self) -> type:
from ._wrapper import Dataset
return Dataset |
@ZedThree First of all I want to thank you for your perseverance going through the instances. These issues
and the CF hackaton meeting notes availabe from cf-convention/discuss#243 are interesting reads. It seems that finally complex data is about to be standardized within cf-conventions. From my perspective and from all what I've read so far in the above discussions and documents handling complex numbers should be a first class citizen upstream and seems to be best placed directly into netcdf4-python instead trying to retrofit that into xarray via backends. I do not advocate against any backend usage until this is sorted out. A package which provides a backend to be used as suggested by @dcherian above and which would be available via PyPI (and conda-forge) would be really helpful in that sense. |
@ZedThree that seems OK to me. However, this is a bit risky since we will not commit to not breaking your downstream code :) In practice, I suspect that will rarely happen. Can you send in a PR and lets see what everyone else thinks? Since class NetCDF4DataStore(WritableCFDataStore):
def __init__(self, ...):
# do this to allow subclassing by external backend engines.
DatasetClass = netCDF4.Dataset |
@kmuehlbauer I think it would be great if complex numbers were handled natively by netCDF, but as you've seen, it keeps tumbling upstream :) Even if we do get HDF5-native complex numbers, we will still be left with codes that can't/won't use them, which is why I would like to also solve this issue downstream too. netcdf4-python might be best middle ground though, so we'll see how the maintainers feel about it. More pressure from more communities is always welcome of course :) @dcherian Sorry, I think the indentation in your snippet is messed up a little. Did you mean to just make I'll try to whip up a PR so we can discuss details there |
@ZedThree Yes, sometimes it takes a lot of effort, I'm totally with you ;-) Looking forward to your PR. |
This was implemented in netcdf4-python: Unidata/netcdf4-python#1295 |
Is your feature request related to a problem?
Complex numbers are not natively handled by netCDF, and currently only the
h5netcdf
engine in xarray can handle them. However, it produces files unreadable by current versions of netCDF. There are also many different conventions, andh5netcdf
can only read a few of them.Describe the solution you'd like
I've written a drop-in extension to netCDF that seamlessly handles complex numbers, and can read many different conventions.
The Python API is built on top of netCDF4-python, so only a very simple change to xarray is needed to use it:
and then it works out of the box:
If the library is built against the latest
main
of netCDF-C, then it also supports files written byh5netcdf
. And while the package isn't on PyPI yet, built wheels with this feature are available from CI jobs.nc_complex
is not quite ready yet, but I wanted to gauge interest for adding it as an optional replacement fornetCDF4
in xarray.Describe alternatives you've considered
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: