Code Monkey home page Code Monkey logo

Comments (7)

agstephens avatar agstephens commented on August 25, 2024 1

@cehbrecht: It looks like using the example code above (from PR #204) is the best place to clean up the dataset. Hopefully, it will only involve adding a few extra lines of code.

from clisops.

cehbrecht avatar cehbrecht commented on August 25, 2024

This issue is also related to #198. The FixValue issue was (partially) fixed already in our 0.9.0 release by PR #204

from clisops.

cehbrecht avatar cehbrecht commented on August 25, 2024

The unnecessary coordinate at the bounds variables, like:

double lat_bnds(lat, bnds) ;
    lat_bnds:coordinates = "height" ;

... was already reported to xarray by @ellesmith88 :
pydata/xarray#5510

A workaround to get rid off these coordinates is provided in xarray:
pydata/xarray#5514

For example like this:

ds.lat_bnds.encoding["coordinates"] = None

from clisops.

cehbrecht avatar cehbrecht commented on August 25, 2024

Workaround?

In the test notebook above I'm applying all mentioned workarounds on the xarray dataset:

ds.time.encoding["_FillValue"] = None
ds.lon.encoding["_FillValue"] = None
ds.lat.encoding["_FillValue"] = None
ds.height.encoding["_FillValue"] = None

ds.lat_bnds.encoding["_FillValue"] = None
ds.lat_bnds.encoding["coordinates"] = None

ds.lon_bnds.encoding["_FillValue"] = None
ds.lon_bnds.encoding["coordinates"] = None

ds.time_bnds.encoding["_FillValue"] = None
ds.time_bnds.encoding["coordinates"] = None

Then I write the dataset as netcdf file:

ds.to_netcdf("/tmp/out.nc")

Both cdo sinfo and ncdump -h seem to be happy with the new netcdf file.

from clisops.

cehbrecht avatar cehbrecht commented on August 25, 2024

@Zeitsperre @sol1105 @agstephens thoughts?

from clisops.

cehbrecht avatar cehbrecht commented on August 25, 2024

workaround can be added like this (from PR #204):

def _remove_redundant_fill_values(self, ds):
"""
Get coordinate variables and remove fill values added by xarray (CF conventions say that coordinate variables cannot have missing values).
Get bounds variables and remove fill values added by xarray.
"""
if isinstance(ds, xr.Dataset):
main_var = get_main_variable(ds)
for coord_id in ds[main_var].coords:
# remove fill value from coordinate variables
if ds.coords[coord_id].dims == (coord_id,):
ds[coord_id].encoding["_FillValue"] = None
# remove fill value from bounds variables if they exist
try:
bnd = ds.cf.get_bounds(coord_id).name
ds[bnd].encoding["_FillValue"] = None
except KeyError:
continue
return ds

from clisops.

cehbrecht avatar cehbrecht commented on August 25, 2024

Fixed in clisops by #225. Works also now in daops and rook.

from clisops.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.