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

Error cfgrib.to_grib convert netcdf to grib #91

Closed
taoansf opened this issue Jun 19, 2019 · 5 comments
Closed

Error cfgrib.to_grib convert netcdf to grib #91

taoansf opened this issue Jun 19, 2019 · 5 comments
Assignees
Labels
bug Something isn't working

Comments

@taoansf
Copy link

taoansf commented Jun 19, 2019

Hello,

I'm looking for a solution to write a grib file from a netcdf data using this code

#! /usr/bin/env python
import xarray as xa
import cfgrib
ds = xa.open_dataset('2015-01-15.nc')
cfgrib.to_grib(ds,'2015-01-15.grb', grib_keys={'gridType':'regular_ll'})

However python give me this error mensage

File "C:\Users\Usuario\Miniconda3\lib\site-packages\cfgrib\bindings.py", line 442, in portable_handle_new_from_samples
sample_path = os.path.join(samples_folder, samplename + b'.tmpl')
TypeError: must be str, not bytes

This is my input file, from SST-MUR data

2015-01-15.zip

I will appreciate any help with this problem.

With best regards,

Taoan

@alexamici alexamici added the bug Something isn't working label Jun 19, 2019
@alexamici alexamici self-assigned this Jun 19, 2019
@alexamici
Copy link
Contributor

alexamici commented Jun 19, 2019

@taoansf ouch! This is a typical brown-paper-bag bug. It appears only on Windows. Sorry!

I fixed it in the stable/0.9,7.x branch, I'll try to push a release ASAP. Thanks!

@taoansf
Copy link
Author

taoansf commented Jun 26, 2019

Thank you @alexamici you are right, that error does not occur on my linux environment.

However, when I try to load the grib output with this code it does not work
#! /usr/bin/env python
import xarray as xa
import cfgrib
ds1 = xa.open_dataset('2015-01-15.nc')
cfgrib.to_grib(ds1,'2015-01-15.grb', grib_keys={'gridType':'regular_ll'})
ds2=xa.open_dataset('2015-01-15.grb', engine='cfgrib')

Do you have some idea how to solve this?

With best regards,

Taoan

@taoansf
Copy link
Author

taoansf commented Jun 26, 2019

This is the error message
image

My grib output
2015-01-15-grib.zip

@alexamici
Copy link
Contributor

The problem it that in order to save arbitrary netCDF files to GRIB with cfgrib you must specify all the grib_keys that are not automatically computed. At the moment very few keys are computed and you need to set almost all the values as you would do with ecCodes.

Saving a to grib a GRIB file opened with cfgrib works more often because the dataset keeps the GRIB keys of the original file, but if you start from a netCDF you need to do the work manually and you need to know the GRIB data format.

@taoansf
Copy link
Author

taoansf commented Jun 27, 2019

Thank you @alexamici, your explanation was very precise.
I will check eccodes documentation about the grib_keys to format my netcdf input.

With best regards,

Taoan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants