{ "cells": [ { "cell_type": "markdown", "id": "27b6be13-d0a5-41e1-9479-f1028b01610f", "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [] }, "source": [ "## MIR: regridding octahedral GRIB fieldlist" ] }, { "cell_type": "raw", "id": "1f8af122-f127-437b-bf14-e867acdce44d", "metadata": { "editable": true, "raw_mimetype": "text/restructuredtext", "slideshow": { "slide_type": "" }, "tags": [] }, "source": [ "This example shows how to interpolate GRIB data defined on an octahedral reduced Gaussian grid using the :ref:`mir ` backend. We will also see how to inspect and plot the resulting data and how to convert it to xarray.\n", "\n", "To make this notebook work :xref:`earthkit-data` and :xref:`earthkit-plots` have to be installed. The data will be represented as an `earthkit-data GRIB FieldList `_." ] }, { "cell_type": "markdown", "id": "630902ad-c821-47b4-9140-f04cc9a53976", "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [] }, "source": [ "#### Regridding" ] }, { "cell_type": "raw", "id": "b2d1244c-70da-4300-94be-19621099cd2a", "metadata": { "editable": true, "raw_mimetype": "text/restructuredtext", "slideshow": { "slide_type": "" }, "tags": [] }, "source": [ "We perform the regridding with the :ref:`regrid() ` method." ] }, { "cell_type": "code", "execution_count": 1, "id": "8c1cff92-971e-4494-b847-b2df7e7ee53c", "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "9b766e6d44694688977a5aed562f77cd", "version_major": 2, "version_minor": 0 }, "text/plain": [ "O32_t2.grib2: 0%| | 0.00/31.4k [00:00" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import earthkit.plots as ekp\n", "\n", "ekp.quickplot(r).show()" ] }, { "cell_type": "markdown", "id": "2d465f73-7848-49b5-adc3-697a68760520", "metadata": {}, "source": [ "#### Converting the results to xarray" ] }, { "cell_type": "code", "execution_count": 3, "id": "44543f10-44df-4e35-b5a3-33a7a4240b13", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "
<xarray.Dataset> Size: 44kB\n",
       "Dimensions:    (step: 2, latitude: 37, longitude: 72)\n",
       "Coordinates:\n",
       "  * step       (step) timedelta64[ns] 16B 00:00:00 12:00:00\n",
       "  * latitude   (latitude) float64 296B 90.0 85.0 80.0 75.0 ... -80.0 -85.0 -90.0\n",
       "  * longitude  (longitude) float64 576B 0.0 5.0 10.0 15.0 ... 345.0 350.0 355.0\n",
       "Data variables:\n",
       "    2t         (step, latitude, longitude) float64 43kB ...\n",
       "Attributes:\n",
       "    param:        2t\n",
       "    paramId:      167\n",
       "    class:        od\n",
       "    stream:       oper\n",
       "    levtype:      sfc\n",
       "    type:         fc\n",
       "    expver:       0001\n",
       "    date:         20240323\n",
       "    time:         1200\n",
       "    domain:       g\n",
       "    Conventions:  CF-1.8\n",
       "    institution:  ECMWF
" ], "text/plain": [ " Size: 44kB\n", "Dimensions: (step: 2, latitude: 37, longitude: 72)\n", "Coordinates:\n", " * step (step) timedelta64[ns] 16B 00:00:00 12:00:00\n", " * latitude (latitude) float64 296B 90.0 85.0 80.0 75.0 ... -80.0 -85.0 -90.0\n", " * longitude (longitude) float64 576B 0.0 5.0 10.0 15.0 ... 345.0 350.0 355.0\n", "Data variables:\n", " 2t (step, latitude, longitude) float64 43kB ...\n", "Attributes:\n", " param: 2t\n", " paramId: 167\n", " class: od\n", " stream: oper\n", " levtype: sfc\n", " type: fc\n", " expver: 0001\n", " date: 20240323\n", " time: 1200\n", " domain: g\n", " Conventions: CF-1.8\n", " institution: ECMWF" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "r.to_xarray()" ] }, { "cell_type": "markdown", "id": "97c2e3e3-6deb-4df0-a498-168643b1e70e", "metadata": {}, "source": [ "#### Writing the results to disk" ] }, { "cell_type": "markdown", "id": "ed089b30-03f7-430a-9f41-17520d5206cd", "metadata": {}, "source": [ "Write the resulting fieldlist to disk:" ] }, { "cell_type": "code", "execution_count": 4, "id": "ad36951e-9118-46f2-933c-ce5b852341f0", "metadata": {}, "outputs": [], "source": [ "out_file = \"_res_O32_to_5x5.grib\"\n", "r.to_target(\"file\", out_file)" ] }, { "cell_type": "code", "execution_count": null, "id": "28e76042-a0f0-4794-8a4b-d6594556b15f", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "mir", "language": "python", "name": "mir" }, "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.13.1" } }, "nbformat": 4, "nbformat_minor": 5 }