{ "cells": [ { "cell_type": "markdown", "id": "bf7d8446-8a4a-4cef-b286-19ade2f966cd", "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [] }, "source": [ "## Converting GRIB to GeoTIFF" ] }, { "cell_type": "code", "execution_count": 1, "id": "b22378eb-dde1-41fc-ace3-89c2fa729fcb", "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [] }, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "", "version_major": 2, "version_minor": 0 }, "text/plain": [ "test.grib: 0%| | 0.00/1.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", "
centreshortNametypeOfLevelleveldataDatedataTimestepRangedataTypenumbergridType
0ecmf2tsurface02020051312000an0regular_ll
1ecmfmslsurface02020051312000an0regular_ll
\n", "" ], "text/plain": [ " centre shortName typeOfLevel level dataDate dataTime stepRange dataType \\\n", "0 ecmf 2t surface 0 20200513 1200 0 an \n", "1 ecmf msl surface 0 20200513 1200 0 an \n", "\n", " number gridType \n", "0 0 regular_ll \n", "1 0 regular_ll " ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import earthkit.data as ekd\n", "ds = ekd.from_source(\"sample\", \"test.grib\")\n", "ds.ls()" ] }, { "cell_type": "raw", "id": "13ebbd7c-9a81-47eb-917c-97b498bd0c71", "metadata": { "editable": true, "raw_mimetype": "text/restructuredtext", "slideshow": { "slide_type": "" }, "tags": [] }, "source": [ "We use :func:`to_target` to write the GRIB fieldlist/field into a file. The encoder is automatically guessed from the target file suffix." ] }, { "cell_type": "code", "execution_count": 2, "id": "4631e8fd-f957-4825-ab5b-6da5724cbfcf", "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [] }, "outputs": [], "source": [ "ds.to_target(\"file\", \"_test.tiff\")" ] }, { "cell_type": "markdown", "id": "b1aa1482-d994-486c-8c68-be58256a24ff", "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [] }, "source": [ "Check the resulting GeoTIFF file." ] }, { "cell_type": "code", "execution_count": 3, "id": "c8248004-84d8-491e-b1c1-24f14d2006b6", "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [] }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
variableband
02 metre temperature1
1Mean sea level pressure2
\n", "
" ], "text/plain": [ " variable band\n", "0 2 metre temperature 1\n", "1 Mean sea level pressure 2" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ds1 = ekd.from_source(\"file\", \"_test.tiff\")\n", "ds1.ls()" ] }, { "cell_type": "markdown", "id": "e64156b5-2df7-4db6-8bfd-31a2382077bc", "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [] }, "source": [ "Please note that to generate GeoTIFF the GRIB data is converted into Xarray internally. Right now the GeoTIFF output can only be generated if all the DataArrays in the Xarray are 2D." ] }, { "cell_type": "code", "execution_count": null, "id": "24ae9be7-8222-4d8d-91c8-657d1b003b5d", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "dev_ecc", "language": "python", "name": "dev_ecc" }, "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.10.13" } }, "nbformat": 4, "nbformat_minor": 5 }