ECMWF API plugin for EODAG#
This tutorial will show you how use eodag to download data from ECWMF using EcmwfApi eodag plugin. The API plugin and this tutorial have been developed in the context of DOMINO-X.
[1]:
from eodag import EODataAccessGateway, setup_logging
setup_logging(1) # 0: nothing, 1: only progress bars, 2: INFO, 3: DEBUG
dag = EODataAccessGateway()
dag.set_preferred_provider("ecmwf")
Search (build download request) from an existing collection:#
In this example, we will request data from TIGGE public dataset, using a collection already configured in eodag (TIGGE_CF_SFC) or using a custom request to access the same data.
Retrieval request can be customized from ecmwf web ui on https://apps.ecmwf.int/datasets/data/tigge.
For performance purpose, we request a single param (total cloud cover, tcc) to the request as TIGGE_CF_SFC is configured to ask for all available param values. See ecmwf availables parameters. You can add more MARS keywords, that will overwrite default values configured for TIGGE_CF_SFC collection.
[2]:
products_from_collection = dag.search(
geom=[-60, 30, -130, 70],
start="2021-11-01",
end="2021-11-02",
collection="TIGGE_CF_SFC",
**{
"ecmwf:class": "ti",
"ecmwf:dataset": "tigge",
"ecmwf:expver": "prod",
"ecmwf:type": "cf",
"ecmwf:levtype": "sfc",
"ecmwf:origin": "ecmwf",
"ecmwf:grid": "0.5/0.5",
"ecmwf:param": "tcc",
"ecmwf:step": "0",
"ecmwf:time": "00:00",
"ecmwf:target": "output"
}
)
products_from_collection
[2]:
| SearchResult (1) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
0 EOProduct(id=TIGGE_CF_SFC_ORDERABLE_2717adc865d5b21469be9c6f68dc528951d3877d, provider=ecmwf)
|
Note
You can also directly use MARS parameters as is through EODAG search API and replace collection with the desired dataset (tigge is this case)
Send product retrieval request and load it as an xarray.DataArray#
download performed using ECMWF credentials set in
~/.config/eodag/eodag.ymlas for other EO providers:
ecmwf:
priority:
api:
output_dir: /my/path/to/data/eodag_data
credentials:
username: john.doe@csgroup.eu
password: my-ecmwf-api-access-key
you can check your request status from https://apps.ecmwf.int/webmars/joblist/
See ECMWF guidelines if request is queued for a long time
[3]:
# Get XarrayDict
xd = products_from_collection[0].to_xarray()
xd
[3]:
| XarrayDict (1) |
'grib': xarray.Dataset (latitude: 81, longitude: 141) Size: 48kB<xarray.Dataset> Size: 48kB
Dimensions: (latitude: 81, longitude: 141)
Coordinates:
number int64 8B ...
time datetime64[ns] 8B ...
step timedelta64[ns] 8B ...
entireAtmosphere float64 8B ...
* latitude (latitude) float64 648B 70.0 69.5 69.0 ... 31.0 30.5 30.0
* longitude (longitude) float64 1kB 230.0 230.5 231.0 ... 299.5 300.0
valid_time datetime64[ns] 8B ...
Data variables:
tcc (latitude, longitude) float32 46kB ...
Attributes: (12/27)
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
... ...
ecmwf:target: output
ecmwf:time: 00:00
ecmwf:type: cf
eodag:default_geometry: POLYGON((180 -90, 180 90, -180 90, -180 -90, 180...
eodag:download_link: https://apps.ecmwf.int/datasets/data/tigge?{"are...
order:status: succeeded |
[4]:
# DataArray from XarrayDict first value
da = next(iter(xd.values())).tcc
da
[4]:
<xarray.DataArray 'tcc' (latitude: 81, longitude: 141)> Size: 46kB
[11421 values with dtype=float32]
Coordinates:
number int64 8B ...
time datetime64[ns] 8B ...
step timedelta64[ns] 8B ...
entireAtmosphere float64 8B ...
* latitude (latitude) float64 648B 70.0 69.5 69.0 ... 31.0 30.5 30.0
* longitude (longitude) float64 1kB 230.0 230.5 231.0 ... 299.5 300.0
valid_time datetime64[ns] 8B ...
Attributes: (12/31)
GRIB_paramId: 228164
GRIB_dataType: cf
GRIB_numberOfPoints: 11421
GRIB_typeOfLevel: entireAtmosphere
GRIB_stepUnits: 1
GRIB_stepType: instant
... ...
GRIB_shortName: tcc
GRIB_totalNumber: 51
GRIB_units: %
long_name: Total Cloud Cover
units: %
standard_name: unknownPlot using cartopy#
[5]:
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
ax = plt.axes(projection=ccrs.Orthographic(-80, 35))
ax.coastlines()
ax.gridlines(draw_labels=True)
da.plot.contourf(ax=ax, transform=ccrs.PlateCarree())
[5]:
<cartopy.mpl.contour.GeoContourSet at 0x7f8c3858d160>