Xarray engine: ensemble data
Get input GRIB ensemble forecast data.
[1]:
import earthkit.data as ekd
ds_fl = ekd.from_source("sample", "ens_cf_pf.grib")
The data contains 3 ensemble members: 1 control and 2 perturbed members.
[2]:
ds_fl.ls()
[2]:
| centre | shortName | typeOfLevel | level | dataDate | dataTime | stepRange | dataType | number | gridType | |
|---|---|---|---|---|---|---|---|---|---|---|
| 0 | ecmf | t | isobaricInhPa | 500 | 20240603 | 0 | 0 | cf | 0 | regular_ll |
| 1 | ecmf | t | isobaricInhPa | 500 | 20240603 | 0 | 6 | cf | 0 | regular_ll |
| 2 | ecmf | t | isobaricInhPa | 500 | 20240603 | 0 | 0 | pf | 1 | regular_ll |
| 3 | ecmf | t | isobaricInhPa | 500 | 20240603 | 0 | 0 | pf | 2 | regular_ll |
| 4 | ecmf | t | isobaricInhPa | 500 | 20240603 | 0 | 6 | pf | 1 | regular_ll |
| 5 | ecmf | t | isobaricInhPa | 500 | 20240603 | 0 | 6 | pf | 2 | regular_ll |
When we convert GRIB data to Xarray with to_xarray() the ensemble dimension is defined by the “number” dimension role. By default, this role is using the “number” metadata key.
[3]:
ds_fl.to_xarray()
[3]:
<xarray.Dataset> Size: 33kB
Dimensions: (number: 3, step: 2, latitude: 19, longitude: 36)
Coordinates:
* number (number) int64 24B 0 1 2
* step (step) timedelta64[ns] 16B 00:00:00 06:00:00
* latitude (latitude) float64 152B 90.0 80.0 70.0 60.0 ... -70.0 -80.0 -90.0
* longitude (longitude) float64 288B 0.0 10.0 20.0 30.0 ... 330.0 340.0 350.0
Data variables:
t (number, step, latitude, longitude) float64 33kB ...
Attributes: (12/13)
param: t
paramId: 130
class: od
stream: enfo
levtype: pl
type: cf
... ...
date: 20240603
time: 0
domain: g
levelist: 500
Conventions: CF-1.8
institution: ECMWFThis default behaviour can be overridden by specifying custom dim_roles. E.g. to get the ensemble member number from the “perturbatioNumber” key we can use:
[4]:
ds_fl.to_xarray(dim_roles={"number": "perturbationNumber"})
[4]:
<xarray.Dataset> Size: 33kB
Dimensions: (number: 3, step: 2, latitude: 19, longitude: 36)
Coordinates:
* number (number) int64 24B 0 1 2
* step (step) timedelta64[ns] 16B 00:00:00 06:00:00
* latitude (latitude) float64 152B 90.0 80.0 70.0 60.0 ... -70.0 -80.0 -90.0
* longitude (longitude) float64 288B 0.0 10.0 20.0 30.0 ... 330.0 340.0 350.0
Data variables:
t (number, step, latitude, longitude) float64 33kB ...
Attributes: (12/14)
param: t
paramId: 130
class: od
stream: enfo
levtype: pl
type: cf
... ...
time: 0
domain: g
number: 0
levelist: 500
Conventions: CF-1.8
institution: ECMWF[ ]: