{ "cells": [ { "cell_type": "markdown", "id": "9ea9a922-c03f-43c1-aa83-b4ce321b75f5", "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [] }, "source": [ "## Xarray engine: ensemble data" ] }, { "cell_type": "markdown", "id": "ef0e9584-da7b-4461-804e-5785e494485e", "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [] }, "source": [ "Get input GRIB ensemble forecast data." ] }, { "cell_type": "code", "execution_count": 1, "id": "ecc9eac2-21fa-47a1-b1a4-37a26c980800", "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [] }, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "fe83d176cacd410da62e44b2ac16e0b2", "version_major": 2, "version_minor": 0 }, "text/plain": [ "ens_cf_pf.grib: 0%| | 0.00/7.03k [00:00\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
centreshortNametypeOfLevelleveldataDatedataTimestepRangedataTypenumbergridType
0ecmftisobaricInhPa5002024060300cf0regular_ll
1ecmftisobaricInhPa5002024060306cf0regular_ll
2ecmftisobaricInhPa5002024060300pf1regular_ll
3ecmftisobaricInhPa5002024060300pf2regular_ll
4ecmftisobaricInhPa5002024060306pf1regular_ll
5ecmftisobaricInhPa5002024060306pf2regular_ll
\n", "" ], "text/plain": [ " centre shortName typeOfLevel level dataDate dataTime stepRange \\\n", "0 ecmf t isobaricInhPa 500 20240603 0 0 \n", "1 ecmf t isobaricInhPa 500 20240603 0 6 \n", "2 ecmf t isobaricInhPa 500 20240603 0 0 \n", "3 ecmf t isobaricInhPa 500 20240603 0 0 \n", "4 ecmf t isobaricInhPa 500 20240603 0 6 \n", "5 ecmf t isobaricInhPa 500 20240603 0 6 \n", "\n", " dataType number gridType \n", "0 cf 0 regular_ll \n", "1 cf 0 regular_ll \n", "2 pf 1 regular_ll \n", "3 pf 2 regular_ll \n", "4 pf 1 regular_ll \n", "5 pf 2 regular_ll " ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ds_fl.ls()" ] }, { "cell_type": "raw", "id": "48c853ab-abec-4475-818f-f64d8d3d01d8", "metadata": { "editable": true, "raw_mimetype": "text/restructuredtext", "slideshow": { "slide_type": "" }, "tags": [] }, "source": [ "When we convert GRIB data to Xarray with :py:meth:`~data.readers.grib.index.GribFieldList.to_xarray` the ensemble dimension is defined by the \"number\" :ref:`dimension role `. By default, this role is using the \"number\" metadata key." ] }, { "cell_type": "code", "execution_count": 3, "id": "7ae667a2-8e6b-4c6d-9cfe-b6bde40b2971", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "
<xarray.Dataset> Size: 33kB\n",
       "Dimensions:    (number: 3, step: 2, latitude: 19, longitude: 36)\n",
       "Coordinates:\n",
       "  * number     (number) int64 24B 0 1 2\n",
       "  * step       (step) timedelta64[ns] 16B 00:00:00 06:00:00\n",
       "  * latitude   (latitude) float64 152B 90.0 80.0 70.0 60.0 ... -70.0 -80.0 -90.0\n",
       "  * longitude  (longitude) float64 288B 0.0 10.0 20.0 30.0 ... 330.0 340.0 350.0\n",
       "Data variables:\n",
       "    t          (number, step, latitude, longitude) float64 33kB ...\n",
       "Attributes: (12/13)\n",
       "    param:        t\n",
       "    paramId:      130\n",
       "    class:        od\n",
       "    stream:       enfo\n",
       "    levtype:      pl\n",
       "    type:         cf\n",
       "    ...           ...\n",
       "    date:         20240603\n",
       "    time:         0\n",
       "    domain:       g\n",
       "    levelist:     500\n",
       "    Conventions:  CF-1.8\n",
       "    institution:  ECMWF
" ], "text/plain": [ " Size: 33kB\n", "Dimensions: (number: 3, step: 2, latitude: 19, longitude: 36)\n", "Coordinates:\n", " * number (number) int64 24B 0 1 2\n", " * step (step) timedelta64[ns] 16B 00:00:00 06:00:00\n", " * latitude (latitude) float64 152B 90.0 80.0 70.0 60.0 ... -70.0 -80.0 -90.0\n", " * longitude (longitude) float64 288B 0.0 10.0 20.0 30.0 ... 330.0 340.0 350.0\n", "Data variables:\n", " t (number, step, latitude, longitude) float64 33kB ...\n", "Attributes: (12/13)\n", " param: t\n", " paramId: 130\n", " class: od\n", " stream: enfo\n", " levtype: pl\n", " type: cf\n", " ... ...\n", " date: 20240603\n", " time: 0\n", " domain: g\n", " levelist: 500\n", " Conventions: CF-1.8\n", " institution: ECMWF" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ds_fl.to_xarray()" ] }, { "cell_type": "markdown", "id": "6f2a0d29-10bf-45ad-abf5-e457fd6f820d", "metadata": { "editable": true, "raw_mimetype": "text/restructuredtext", "slideshow": { "slide_type": "" }, "tags": [] }, "source": [ "This 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:" ] }, { "cell_type": "code", "execution_count": 4, "id": "ba4a3746-3549-494b-8272-df0b03d6936c", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "
<xarray.Dataset> Size: 33kB\n",
       "Dimensions:    (number: 3, step: 2, latitude: 19, longitude: 36)\n",
       "Coordinates:\n",
       "  * number     (number) int64 24B 0 1 2\n",
       "  * step       (step) timedelta64[ns] 16B 00:00:00 06:00:00\n",
       "  * latitude   (latitude) float64 152B 90.0 80.0 70.0 60.0 ... -70.0 -80.0 -90.0\n",
       "  * longitude  (longitude) float64 288B 0.0 10.0 20.0 30.0 ... 330.0 340.0 350.0\n",
       "Data variables:\n",
       "    t          (number, step, latitude, longitude) float64 33kB ...\n",
       "Attributes: (12/14)\n",
       "    param:        t\n",
       "    paramId:      130\n",
       "    class:        od\n",
       "    stream:       enfo\n",
       "    levtype:      pl\n",
       "    type:         cf\n",
       "    ...           ...\n",
       "    time:         0\n",
       "    domain:       g\n",
       "    number:       0\n",
       "    levelist:     500\n",
       "    Conventions:  CF-1.8\n",
       "    institution:  ECMWF
" ], "text/plain": [ " Size: 33kB\n", "Dimensions: (number: 3, step: 2, latitude: 19, longitude: 36)\n", "Coordinates:\n", " * number (number) int64 24B 0 1 2\n", " * step (step) timedelta64[ns] 16B 00:00:00 06:00:00\n", " * latitude (latitude) float64 152B 90.0 80.0 70.0 60.0 ... -70.0 -80.0 -90.0\n", " * longitude (longitude) float64 288B 0.0 10.0 20.0 30.0 ... 330.0 340.0 350.0\n", "Data variables:\n", " t (number, step, latitude, longitude) float64 33kB ...\n", "Attributes: (12/14)\n", " param: t\n", " paramId: 130\n", " class: od\n", " stream: enfo\n", " levtype: pl\n", " type: cf\n", " ... ...\n", " time: 0\n", " domain: g\n", " number: 0\n", " levelist: 500\n", " Conventions: CF-1.8\n", " institution: ECMWF" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ds_fl.to_xarray(dim_roles={\"number\": \"perturbationNumber\"})" ] }, { "cell_type": "code", "execution_count": null, "id": "596c4426-32d7-4766-a640-4436da604918", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "dev", "language": "python", "name": "dev" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.12" } }, "nbformat": 4, "nbformat_minor": 5 }