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

Add 'unstructured_grid' support to write function #39

Closed
guidocioni opened this Issue Dec 14, 2018 · 6 comments

Comments

Projects
None yet
2 participants
@guidocioni
Copy link

guidocioni commented Dec 14, 2018

Currently cfgrib can handle the gridType unstructured_grid when reading files (see #28). However, when writing a GRIB file using this data an error is raised NotImplementedError: Unsupported 'gridType': u'unstructured_grid'. Is it to difficult to implement this feature?

alexamici added a commit that referenced this issue Dec 14, 2018

@alexamici

This comment has been minimized.

Copy link
Collaborator

alexamici commented Dec 14, 2018

@guidocioni can you please check out branch https://github.com/ecmwf/cfgrib/tree/write-unstructured_grid and test if it writes a GRIB file of you liking.

The change is trivial, if it works for you it'll go in the next release.

@alexamici alexamici self-assigned this Dec 14, 2018

@guidocioni

This comment has been minimized.

Copy link
Author

guidocioni commented Dec 19, 2018

ValueErrorTraceback (most recent call last)
<ipython-input-8-d316a23fef91> in <module>()
      1 import cfgrib
----> 2 cfgrib.to_grib(ds_subset, 'out1.grib')

/work/mh0731/m300382/conda_envs/my_base/lib/python2.7/site-packages/cfgrib/xarray_to_grib.py in to_grib(*args, **kwargs)
    261 
    262 def to_grib(*args, **kwargs):
--> 263     return canonical_dataset_to_grib(*args, **kwargs)

/work/mh0731/m300382/conda_envs/my_base/lib/python2.7/site-packages/cfgrib/xarray_to_grib.py in canonical_dataset_to_grib(dataset, path, mode, no_warn, grib_keys, **kwargs)
    257     with open(path, mode=mode) as file:
    258         for data_var in dataset.data_vars.values():
--> 259             canonical_dataarray_to_grib(data_var, file, grib_keys=real_grib_keys, **kwargs)
    260 
    261 

/work/mh0731/m300382/conda_envs/my_base/lib/python2.7/site-packages/cfgrib/xarray_to_grib.py in canonical_dataarray_to_grib(data_var, file, grib_keys, default_grib_keys, **kwargs)
    209         raise ValueError("required grib_key 'gridType' not passed nor auto-detected")
    210 
--> 211     template_message = make_template_message(merged_grib_keys, **kwargs)
    212 
    213     coords_names, data_var = expand_dims(data_var)

/work/mh0731/m300382/conda_envs/my_base/lib/python2.7/site-packages/cfgrib/xarray_to_grib.py in make_template_message(merged_grib_keys, template_path, sample_name)
    179         if sample_name is None:
    180             sample_name = detect_sample_name(merged_grib_keys)
--> 181         template_message = cfgrib.CfMessage.from_sample_name(sample_name)
    182 
    183     for key in MESSAGE_DEFINITION_KEYS:

/work/mh0731/m300382/conda_envs/my_base/lib/python2.7/site-packages/cfgrib/messages.pyc in from_sample_name(cls, sample_name, **kwargs)
     62     @classmethod
     63     def from_sample_name(cls, sample_name, **kwargs):
---> 64         codes_id = eccodes.codes_new_from_samples(sample_name.encode('ASCII'))
     65         return cls(codes_id=codes_id, **kwargs)
     66 

/work/mh0731/m300382/conda_envs/my_base/lib/python2.7/site-packages/cfgrib/eccodes.pyc in codes_new_from_samples(samplename, product_kind)
    590     handle = lib.codes_grib_handle_new_from_samples(ffi.NULL, samplename)
    591     if handle == ffi.NULL:
--> 592         raise ValueError("sample not found: %r" % samplename)
    593     return handle
    594 

ValueError: sample not found: 'unstructured_grid_sfc_grib2'
@alexamici

This comment has been minimized.

Copy link
Collaborator

alexamici commented Dec 19, 2018

Ok, it was not so trivial after all.

Can I download a file with unstructured_grid grid anywhere? So I can test locally.

@guidocioni

This comment has been minimized.

Copy link
Author

guidocioni commented Dec 19, 2018

Sure, I'd choose something easy from the opendata of DWD, like a file here https://opendata.dwd.de/weather/nwp/icon/grib/00/qv_s/

@alexamici alexamici closed this in 90c8106 Jan 1, 2019

@alexamici

This comment has been minimized.

Copy link
Collaborator

alexamici commented Jan 1, 2019

@guidocioni cfgrib now falls back to use a basic template when it can't detect a better one. The downside is that you need to specify all necessary GRIB keys. This should be enough to save to_grib a dataset opened with cfgrib.

Please report back if current master fixes the issue for you.

@guidocioni

This comment has been minimized.

Copy link
Author

guidocioni commented Jan 23, 2019

Sorry for the delay... I will try to test the behaviour in the following days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.