...
Code Block |
---|
language | py |
---|
title | Open a GRIB file |
---|
collapse | true |
---|
|
# assumed you have download from the Climate Data Store a GloFAS GRIB file named 'download.grib'
In [1]: import xarray as xr
# reading GloFAS GRIB file
In [2]: ds = xr.open_dataset('download.grib',engine='cfgrib')
In [3]: ds
Out[4]:
<xarray.Dataset>
Dimensions: (latitude: 1500, longitude: 3600, step: 3, time: 3)
Coordinates:
number int64 ...
* time (time) datetime64[ns] 2019-12-01 2019-12-02 2019-12-03
* step (step) timedelta64[ns] 1 days 2 days 3 days
surface int64 ...
* latitude (latitude) float64 89.95 89.85 89.75 ... -59.75 -59.85 -59.95
* longitude (longitude) float64 -179.9 -179.8 -179.8 ... 179.7 179.8 179.9
valid_time (time, step) datetime64[ns] ...
Data variables:
dis24 (time, step, latitude, longitude) float32 ...
Attributes:
GRIB_edition: 2
GRIB_centre: ecmf
GRIB_centreDescription: European Centre for Medium-Range Weather Forecasts
GRIB_subCentre: 0
Conventions: CF-1.7
institution: European Centre for Medium-Range Weather Forecasts
history: 2021-02-11T11:00:21 GRIB to CDM+CF via cfgrib-0.... |
Info |
---|
title | How to correctly read historical datasets
The different GRIB data structure of the EFAS and GloFAS datasets may require some additional configuration.
-Read historical datasets
Code Block |
---|
|
import xarray as xr
ds = xr.open_dataset("glofas_historical_201901.grib",engine="cfgrib",backend_kwargs={'time_dims':['time']})
|
Info |
---|
title | How to correctly read GRIB with heterogeneous types |
---|
|
If you download both 'control reforecast' and ‘ensemble perturbed reforecasts' products in a single GRIB file, in order to read it in Python you will need to pass a backward_kwargs dictionary in the open_dataset function, as in the examples below: Code Block |
---|
| import xarray as xr
# Filtering and saving the Control reforecast (cf) data
glofas_cf = xr.open_dataset("Glofas_forecast.grib", engine='cfgrib', backend_kwargs={'filter_by_keys': {'dataType': 'cf'}, 'indexpath':''})
glofas_cf.to_netcdf("Glofas_forecast_cf.nc")
# Filtering and saving the Ensemble perturbed reforecasts (pf) data
glofas_pf = xr.open_dataset("Glofas_forecast.grib ", engine='cfgrib', backend_kwargs={'filter_by_keys': {'dataType': 'pf'}, 'indexpath':''})
glofas_pf.to_netcdf("Glofas_forecast_pf.nc")
|
|
...