{ "cells": [ { "cell_type": "markdown", "id": "27b6be13-d0a5-41e1-9479-f1028b01610f", "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [] }, "source": [ "## Interpolating octahedral GRIB data" ] }, { "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. 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` (version >= 0.6.0) 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": [ "#### Interpolation" ] }, { "cell_type": "code", "execution_count": 1, "id": "8c1cff92-971e-4494-b847-b2df7e7ee53c", "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "01b671ce37874b1a98c964e354f787fe", "version_major": 2, "version_minor": 0 }, "text/plain": [ "O32_multi.grib2: 0%| | 0.00/31.4k [00:00" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import earthkit.plots\n", "\n", "figure = earthkit.plots.Figure(size=(9, 6), rows=1, columns=2)\n", "figure.add_map().plot(r[0])\n", "figure.add_map().plot(r[1])\n", "figure.coastlines()\n", "figure.subplot_titles()\n", "figure.legend()\n", "figure.gridlines(sharey=True)\n", "figure.show()" ] }, { "cell_type": "markdown", "id": "2d465f73-7848-49b5-adc3-697a68760520", "metadata": {}, "source": [ "#### Converting the results to xarray" ] }, { "cell_type": "code", "execution_count": 4, "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": 4, "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": 5, "id": "ad36951e-9118-46f2-933c-ce5b852341f0", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/var/folders/93/w0p869rx17q98wxk83gn9ys40000gn/T/ipykernel_42716/1305914581.py:2: DeprecatedWarning: save is deprecated as of 0.13.0. Use to_target() instead\n", " r.save(out_file)\n" ] } ], "source": [ "out_file = \"_res_O32_to_5x5.grib\"\n", "r.save(out_file)" ] } ], "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 }