{ "cells": [ { "cell_type": "markdown", "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [] }, "source": [ "## GRIB: missing values" ] }, { "attachments": {}, "cell_type": "raw", "metadata": { "editable": true, "raw_mimetype": "text/restructuredtext", "slideshow": { "slide_type": "" }, "tags": [] }, "source": [ "We :ref:`read ` a GRIB file containing 2 messages with missing values. First we ensure the example file is available." ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [] }, "outputs": [], "source": [ "import numpy as np\n", "import earthkit.data as ekd\n", "ekd.download_example_file(\"missing.grib\")" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "fs = ekd.from_source(\"file\", \"missing.grib\")" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "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", " \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": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fs.ls()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "When can see how many missing values we have by inspecting the metadata:" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[1, 1]" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fs.metadata(\"bitmapPresent\")" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[142, 13]" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fs.metadata(\"numberOfMissingValues\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "When data values are extracted as numpy arrays missing values are automatically replaced by np.nan:" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Number of nans=142\n", "Number of nans=13\n" ] } ], "source": [ "for f in fs:\n", " v = f.values\n", " print(f\"Number of nans={np.count_nonzero(np.isnan(v))}\")" ] } ], "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": 4 }