ecmwf / cfgrib

A Python interface to map GRIB files to the NetCDF Common Data Model following the CF Convention using ecCodes
Apache License 2.0
409 stars 77 forks source link

variable encoding for to_netcdf #334

Closed EddyCMWF closed 1 year ago

EddyCMWF commented 1 year ago

This is required because netCDF encoding options (e.g. compression options) need to be added per variable and it is not always possible/simple/sensible to know what variables are in the grib file before converting to netCDF.

This change allows users to provide a common set of compression options which are applied to each data variable in the xr.dataset. Any encoding provided in the netcdf_kwargs_json overrides what is set via the global var_encoding_json.

The variable encoding is parsed using the -v or --var-encoding-json options, e.g.: cfgrib to_netcdf -v '{"dtype": "float", "scale_factor": 0.1}' -o $OUTFILE $INFILE

codecov-commenter commented 1 year ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 95.44%. Comparing base (134df11) to head (cfa24b8). Report is 130 commits behind head on master.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #334 +/- ## ========================================== + Coverage 95.40% 95.44% +0.04% ========================================== Files 26 26 Lines 2022 2040 +18 Branches 234 236 +2 ========================================== + Hits 1929 1947 +18 Misses 62 62 Partials 31 31 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

iainrussell commented 1 year ago

Thanks Eddy! I'm not sure that "-v" is quite the best argument, since it's usually used to denote 'verbose', but it seems like the best option at the moment. I'll merge the pull request, and if you think of another option abbreviation you prefer, we can always change it!