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

Updated fix: remove_fill_values() #88

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

agstephens
Copy link
Collaborator

Added import of cf_xarray and detection of bounds for each
coordinate. And then sets _FillValue to None to avoid writing
bounds with _FillValue to netcdf.

Pull Request Checklist:

  • This PR addresses an already opened issue (for bug fixes / features)
    • This PR fixes issue #xyz
  • Tests for the changes have been added (for bug fixes / features)
  • Documentation has been added / updated (for bug fixes / features)
  • HISTORY.rst has been updated (with summary of main changes)
  • I have added my relevant user information to AUTHORS.md
  • What kind of change does this PR introduce?:

  • Does this PR introduce a breaking change?:

  • Other information:

Added import of `cf_xarray` and detection of bounds for each
coordinate. And then sets _FillValue to None to avoid writing
bounds with _FillValue to netcdf.
@agstephens
Copy link
Collaborator Author

Hi @ellesmith88, please check this PR that hopefully makes sure the coordinate bounds variables do not have _FillValue = NaN in output files (once fixed). Thanks

@ellesmith88
Copy link
Collaborator

@agstephens I recently added this fix into clisops https://github.com/roocs/clisops/pull/204/files which fixes the fill values for the coordinate variables bounds in the output files. I think we could probably remove the fill value fix in daops completely, apart from the fact that it is currently used in the decadal fixes, as I implemented it as a fix before we decided to put it all in clisops.

If you want to add the bounds fix here as well then I think it needs to be something like:

try:
     bounds = ds.cf.get_bounds(coord_id)
     bounds.encoding["_FillValue"] = None
except KeyError:
     continue

as a KeyError is raised, rather than returning None, if the coordinate doesn't have any bounds. I tested with the file /badc/cmip6/data/CMIP6/CMIP/IPSL/IPSL-CM6A-LR/historical/r1i1p1f1/Amon/rlds/gr/v20180803/rlds_Amon_IPSL-CM6A-LR_historical_r1i1p1f1_gr_185001-201412.nc

Also, cf-xarray would need to be added to the requirements.

I can make these changes if you want to keep this in daops.

@agstephens
Copy link
Collaborator Author

@agstephens I recently added this fix into clisops https://github.com/roocs/clisops/pull/204/files which fixes the fill values for the coordinate variables bounds in the output files. I think we could probably remove the fill value fix in daops completely, apart from the fact that it is currently used in the decadal fixes, as I implemented it as a fix before we decided to put it all in clisops.

If you want to add the bounds fix here as well then I think it needs to be something like:

try:
     bounds = ds.cf.get_bounds(coord_id)
     bounds.encoding["_FillValue"] = None
except KeyError:
     continue

as a KeyError is raised, rather than returning None, if the coordinate doesn't have any bounds. I tested with the file /badc/cmip6/data/CMIP6/CMIP/IPSL/IPSL-CM6A-LR/historical/r1i1p1f1/Amon/rlds/gr/v20180803/rlds_Amon_IPSL-CM6A-LR_historical_r1i1p1f1_gr_185001-201412.nc

Also, cf-xarray would need to be added to the requirements.

I can make these changes if you want to keep this in daops.

@ellesmith88 Your proposal sounds most sensible - that we just remove this as a dachar/daops fix because it is applied at the clisops level. Let's just fix it at source (in clisops) and keep everything else simpler.

@cehbrecht cehbrecht marked this pull request as draft November 14, 2023 15:36
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.

2 participants