{ "cells": [ { "cell_type": "markdown", "id": "c4d5ef32-f24e-4ce3-b4df-9edb52de1bfb", "metadata": {}, "source": [ "# ECMWF API plugin for EODAG\n", "\n", "This tutorial will show you how use eodag to download data from [ECWMF](https://www.ecmwf.int/) using [EcmwfApi](https://eodag.readthedocs.io/en/latest/plugins_reference/generated/eodag.plugins.apis.ecmwf.EcmwfApi.html) `eodag` plugin. The API plugin and this tutorial have been developed in the context of DOMINO-X." ] }, { "cell_type": "code", "execution_count": 1, "id": "1298613c-5383-48c4-bc0a-f4136130daaf", "metadata": {}, "outputs": [], "source": [ "from eodag import EODataAccessGateway, setup_logging\n", "\n", "setup_logging(1) # 0: nothing, 1: only progress bars, 2: INFO, 3: DEBUG\n", "dag = EODataAccessGateway()\n", "dag.set_preferred_provider(\"ecmwf\")" ] }, { "cell_type": "markdown", "id": "fd6acf76-19ac-4e27-be87-644d2d978ba0", "metadata": {}, "source": [ "### Search (build download request) from an existing product type:\n", "\n", "In this example, we will request data from [TIGGE public dataset](https://www.ecmwf.int/en/research/projects/tigge), using a product type already configured in eodag (`TIGGE_CF_SFC`) or using a custom request to access the same data.\n", "\n", "Retrieval request can be customized from ecmwf web ui on https://apps.ecmwf.int/datasets/data/tigge. \n", "\n", "For performance purpose, we add a `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](https://apps.ecmwf.int/codes/grib/param-db/). You can add more [MARS keywords](https://confluence.ecmwf.int/display/UDOC/Keywords+in+MARS+and+Dissemination+requests), that will overwrite default values configured for `TIGGE_CF_SFC` product type." ] }, { "cell_type": "code", "execution_count": 2, "id": "2181ef4d-cc88-458c-a633-f009cedc43ef", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "1 product built EOProduct(id=TIGGE_CF_SFC_20211101_31613e05afb70ccea479a4e2ce057227b15de05b, provider=ecmwf), \n", " having param=59/134/136/146/147/151/165/166/167/168/172/176/177/179/189/235/228001/228002/228039/228139/228141/228144/228164/228228\n", "\n", "1 product built EOProduct(id=TIGGE_CF_SFC_20211101_28b0b1a0da723aba1682661621bd7b21fe12f1ea, provider=ecmwf), \n", " having param=tcc\n" ] } ], "source": [ "# Request for all parameters\n", "products_from_product_type, total_count = dag.search(\n", " geom=[-60, 30, -130, 70],\n", " start=\"2021-11-01\",\n", " end=\"2021-11-02\",\n", " productType=\"TIGGE_CF_SFC\",\n", ")\n", "print(\n", " \"%s product built %s, \\n having param=%s\\n\"\n", " % (\n", " total_count,\n", " products_from_product_type[0],\n", " products_from_product_type[0].properties[\"param\"],\n", " )\n", ")\n", "# Request for total cloud cover\n", "products_from_product_type, total_count = dag.search(\n", " geom=[-60, 30, -130, 70],\n", " start=\"2021-11-01\",\n", " end=\"2021-11-02\",\n", " productType=\"TIGGE_CF_SFC\",\n", " param=\"tcc\",\n", ")\n", "print(\n", " \"%s product built %s, \\n having param=%s\"\n", " % (\n", " total_count,\n", " products_from_product_type[0],\n", " products_from_product_type[0].properties[\"param\"],\n", " )\n", ")" ] }, { "cell_type": "markdown", "id": "59577515-7446-4e1f-ba33-3ef87fb7c80d", "metadata": {}, "source": [ "### Send product retrieval request and download when available\n", "\n", "- download performed using [ECMWF credentials](https://github.com/ecmwf/ecmwf-api-client#registered-access-recommended) set in `~/.config/eodag/eodag.yml` as for other EO providers:\n", "```yaml\n", " ecmwf:\n", " priority:\n", " api:\n", " outputs_prefix: /data/eodag_data\n", " credentials:\n", " username: john.doe@csgroup.eu\n", " password: my-ecmwf-api-access-key\n", "```\n", "- you can check your request status from https://apps.ecmwf.int/webmars/joblist/\n", "- See [ECMWF guidelines](https://confluence.ecmwf.int/display/UDOC/My+request+is+queued+for+a+long+time+-+Web+API+FAQ) if request is queued for a long time" ] }, { "cell_type": "code", "execution_count": 4, "id": "c5844159-d67f-405b-aaf8-2017ff0010e7", "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "d19e81147f054136982b51ffd1e75d8a", "version_major": 2, "version_minor": 0 }, "text/plain": [ "0.00B [00:00, ?B/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "'/data/eodag_data/TIGGE_CF_SFC_20211101_28b0b1a0da723aba1682661621bd7b21fe12f1ea.grib'" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "product_path = dag.download(products_from_product_type[0])\n", "product_path" ] }, { "cell_type": "markdown", "id": "db727f7e-68b7-4570-a15b-28c7cd6d1c59", "metadata": {}, "source": [ "### Open dataset with xarray and [cfgrib](https://github.com/ecmwf/cfgrib), then plot using matplotlib" ] }, { "cell_type": "code", "execution_count": 5, "id": "a733a270-b984-45cb-80a4-a35a1b2112f4", "metadata": {}, "outputs": [], "source": [ "import xarray as xr\n", "import matplotlib.pyplot as plt" ] }, { "cell_type": "code", "execution_count": 6, "id": "1d1e5b4c-0919-493a-af0c-1b5604909978", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
<xarray.Dataset>\n", "Dimensions: (latitude: 81, longitude: 141)\n", "Coordinates:\n", " number int64 0\n", " time datetime64[ns] 2021-11-01\n", " step timedelta64[ns] 00:00:00\n", " entireAtmosphere float64 0.0\n", " * latitude (latitude) float64 70.0 69.5 69.0 68.5 ... 31.0 30.5 30.0\n", " * longitude (longitude) float64 230.0 230.5 231.0 ... 299.5 300.0\n", " valid_time datetime64[ns] 2021-11-01\n", "Data variables:\n", " tcc (latitude, longitude) float32 100.0 100.0 ... 8.406 10.62\n", "Attributes:\n", " GRIB_edition: 2\n", " GRIB_centre: ecmf\n", " GRIB_centreDescription: European Centre for Medium-Range Weather Forecasts\n", " GRIB_subCentre: 0\n", " Conventions: CF-1.7\n", " institution: European Centre for Medium-Range Weather Forecasts\n", " history: 2022-05-11T09:27 GRIB to CDM+CF via cfgrib-0.9.1...