How to add date and step info when writing grib file with `to_grib`
See original GitHub issueI followed the example in the README for writing a GRIB file from a simple Dataset
import xarray as xr
import cfgrib
ds2 = xr.Dataset({'skin_temperature': (('latitude', 'longitude'), np.zeros((5, 6)) + 300.)})
ds2.coords['latitude'] = np.linspace(90., -90., 5)
ds2.coords['longitude'] = np.linspace(0., 360., 6, endpoint=False)
ds2.skin_temperature.attrs['GRIB_shortName'] = 'skt'
cfgrib.to_grib(ds2, 'out.grib2', grib_keys={'edition': 2})
That was successful.
Now, I would like to specify the datetime to the grib2 file, but when I add the coordinate time
, valid_time
, or step
I get an error.
import xarray as xr
import cfgrib
import pandas as pd
ds2 = xr.Dataset({'skin_temperature': (('latitude', 'longitude'), np.zeros((5, 6)) + 300.)})
ds2.coords['latitude'] = np.linspace(90., -90., 5)
ds2.coords['longitude'] = np.linspace(0., 360., 6, endpoint=False)
ds2.coords['time'] = pd.to_datetime('2017-10-01') ### <----- Added this line
ds2.skin_temperature.attrs['GRIB_shortName'] = 'skt'
cfgrib.to_grib(ds2, 'out.grib2', grib_keys={'edition': 2})
KeyError: 1506816000000000000
I realize this is an Alpha capability, but can you please provide any additional information on passing time data when creating a simple grib file. Thanks!
Note: I have
cfgrib 0.9.8.3
Issue Analytics
- State:
- Created 3 years ago
- Comments:10 (1 by maintainers)
Top Results From Across the Web
Tricks for wgrib2
3) Use the import_text option to read in new data values and use the -grib_out to write the values to a grib file....
Read more >GRIB Files in the CDM | netCDF-Java Developer Guide
For simple cases, you can create the ncx4 file based on a collection spec using ToolsUI: IOSP/GRIB1(2)/GribCollection . Enter the collection ...
Read more >Handling GRIB in GrADS - COLA/GMU
The next step is to create a descriptor file which describes the complete grid and the list of variables. The final step is...
Read more >GRIB decoding - ECMWF Confluence Wiki
Staged migration of remaining GRIB 1 fields to GRIB 2 will follow ... Identify the parameter, date, time, forecast step and the grid...
Read more >Coding or converting grib files - GIS Stack Exchange
There is so much library out there, that it is really a matter of preferences. The most complete, documented and up to date...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Here is my test case:
Works like a charm with
pandas=1.0.5
. Withpandas>=1.1.0
, I get:This issue should be fixed by #272.