0

Problem statement:

I need to implement an easy-to-share script compatible with Windows environment that allows me to open a NetCDF, manipulate it, and save it in Grib2 format.

Attempt 1: iris / iris-grib

I initially implemented my code with success using iris and iris-grib in a Linux environment. However, iris-grib depends on cf-units/udunits2/grib_api packages, which have serious compatibility issues with Windows (e.g. [1]), so it would be hard to make the code easy-to-share.

Attempt 2: xarray + cfgrib

Later, I tried to perform something like:

import xarray as xr
import cfgrib

my_ds = xr.open_dataset(INPUT_FILE_PATH)

[...some manipulation on my_ds...]

cfgrib.to_grib(my_ds, OUTPUT_FILE_PATH, grib_keys={'edition': 2})

Which worked great until the cfgrib.to_grib(...) line. There I got the error:

ValueError: required grib_key 'gridType' not passed nor auto-detected.

As my input NetCDF file is in EPSG:4326 projection (WGS-84), I tried to set the grib_keys arguments as grib_keys={'edition': 2, 'gridType': 'regular_ll'}.

ValueError: sample not found: 'regular_ll_sfc_grib2'

Which seems to be an issue with the cfgrib installation (done using conda) not being able to find its own ancillary internal files.

Attempt 3: cdo

Ok, so I saw that there is a Python package that wrappers cdo. Great! So with some file writings/readings, I can do what I want. Right?

Not really.

The cdo package installed with conda install cdo is indeed just a wrapper, so that the system is expected to have the own cdo command available and ready to run. As running cdo on Windows requires a cygwin set up, making the code easy-to-share would be somewhat really messy.

So...

What is a good and easy-to-share way to save a grib2 file on Windows 10 out of a NetCDF file?

[1] https://stackoverflow.com/questions/38979819/iris-for-anaconda-fails-to-read-grib

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.