...
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
# create a local virtual environment, you can call it as you wish, here 'myenv' is used. conda create -n myenv python=3.8 # add repository channel conda config --add channels conda-forge # activate the local environment. conda activate myenv # install the required packages conda install -c conda-forge/label/main xarray cfgrib eccodes # make sure you have installed eccodes version >= 2.23.0 python -c "import eccodes; print(eccodes.__version__)" |
Start Provided that you have downloaded an EFAS or GloFAS GRIB file from CDS, start a python console (it is important that you have activated the local environment) and type:
...
The different GRIB data structures of the EFAS and GloFAS datasets may require some additional configuration configurations to be set in the backend_kwargs argument of the xarray.open_dataset function.
Read GRIB historical datasets:
...
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
import xarray as xr # GloFAS historical ds = xr.open_dataset("glofas_historical_201901.grib",engine="cfgrib",backend_kwargs={'time_dims':['time']}) |
Read GRIB GloFAS historical datasets with multiple product types:
GloFAS historical has two product types, consolidated and intermediate, that you can download together in a GRIB file.
In order to open the file you need to specify the experimentVersionNumber in the backend_kwargs:
consolidated: '0001'
intermediate: '0005'
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
import xarray as xr
ds = xr.open_dataset('glofas.grib', engine='cfgrib',
... backend_kwargs={'read_keys': {'experimentVersionNumber':'0001'}})
|
Read GRIB file that has multiple product types:
There are 4 5 datasets that may can have more that one product type in a GRIB file, depending whether you decide to request more than one product type in a single request. These datasets and corresponding product types are:
- EFAS forecast: "control reforecast", "ensemble perturbed
...
- forecasts", "high resolution forecast"
- EFAS reforecast: "control reforecast", "ensemble perturbed
...
- reforecasts"
- GloFAS historical: "consolidated", "intermediate"
- GloFAS forecast: "control reforecast", "ensemble perturbed
...
- forecasts"
- GloFAS reforecast:
...
- "control reforecast", "ensemble perturbed
...
- reforecasts"
In order to read them you need to specify which product type you are reading using the backend_kwargs:
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
import xarray as xr # Reading the Control reforecast (cf) data glofas_cf cf = xr xr.open_dataset("Glofas_forecast.grib", engine='cfgrib', backend backend_kwargs={'filter_by_keys': {'dataType': 'cf'}, 'indexpath':''}) # Reading the Ensemble perturbed reforecasts (pf) data glofas_pf pf = xr xr.open_dataset("Glofas_forecast.grib ", engine='cfgrib', backend backend_kwargs={'filter_by_keys': {'dataType': 'pf'}, 'indexpath':''}) # Reading the Historical Consolidated (0001) data consololidated = xr.open_dataset('glofas.grib', engine='cfgrib', backend_kwargs={'read_keys': {'experimentVersionNumber':'0001'}}) # Reading the Historical Intermediate (0005) data intermediate = xr.open_dataset('glofas.grib', engine='cfgrib', backend_kwargs={'read_keys': {'experimentVersionNumber':'0005'}}) |