Skip to content
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

Fix 139 #140

Merged
merged 8 commits into from
Oct 6, 2022
Merged

Fix 139 #140

merged 8 commits into from
Oct 6, 2022

Conversation

observingClouds
Copy link
Owner

fixes #139

@observingClouds
Copy link
Owner Author

A simple combination of the original encoding and output encoding does not work: https://github.com/observingClouds/xbitinfo/actions/runs/3170048268/jobs/5162370558#step:8:790
The issue is that not all encodings from the original dataset are valid encodings for the output engine (e.g. netcdf4 or zarr). By default each encoding is checked if it is valid for the specific engine and otherwise raises an error.

@observingClouds
Copy link
Owner Author

The easiest fix for now would be to copy all valid_encodings from the input encoding to the output encoding.

@observingClouds
Copy link
Owner Author

@aaronspring what do you think of this fix? I'm basically calling some xarray backend function for netCDF4 and zarr that ensure that unsupported encodings are dropped before calling the respective library. As a consequence we can just merge the original encoding with xbitinfos additional compression encoding.

enc_checker = xr.backends.netCDF4_._extract_nc4_variable_encoding

It's not nice to call a backend function, however this is meant to be only a temporary solution until pydata/xarray#7129 and pydata/xarray#7127 are fixed.

@observingClouds observingClouds marked this pull request as ready for review October 5, 2022 05:51
@aaronspring
Copy link
Collaborator

I like it. Does this mean that to_compressed_netcdf only works for netcdf4? Should we make it work also for other engines or would we need to rework xr.to_netcdf?

@observingClouds
Copy link
Owner Author

Good point @aaronspring . I think it should also work with other engines, but might drop a few extra encodings that are not allowed for the netCDF4 library. The easiest would be to be able to set raise_on_invalid to False, but I don't see a possibility to do so in xr.Dataset.to_netcdf. raise_on_invalid seems to be available in all inherited engine functions, like e.g. in netCDF4: https://github.com/pydata/xarray/blob/13c52b27b777709fc3316cf4334157f50904c02b/xarray/backends/netCDF4_.py#L224

@observingClouds
Copy link
Owner Author

observingClouds commented Oct 5, 2022

I decided to make netCDF4 the only allowed engine for now. This is the safest route. Depending on the engine and additional options there are just too many cases to test for ourselves. We can remove this restriction whenever there is a solution upstream, otherwise we would need to write a lot of functionality and tests that xarray already provides.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

eraint_uvz test_full fails
2 participants