{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "ee62959d-4b21-462c-881d-2931047531ec", "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [] }, "outputs": [], "source": [ "!test -f temp_small.bufr || wget https://get.ecmwf.int/repository/test-data/pdbufr/test-data/temp_small.bufr" ] }, { "cell_type": "markdown", "id": "a1867cba-dbbb-4856-96e4-6c3d2c113ef9", "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [] }, "source": [ "## Temp: overview" ] }, { "cell_type": "code", "execution_count": 2, "id": "a209a358-fa42-462f-ad76-c7cc801737fd", "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [] }, "outputs": [], "source": [ "import pdbufr" ] }, { "cell_type": "raw", "id": "cde468ee-da73-49d5-a7e6-a8c6dadbf7a6", "metadata": { "editable": true, "raw_mimetype": "text/restructuredtext", "slideshow": { "slide_type": "" }, "tags": [] }, "source": [ "The input BUFR data contains Temp (radiosonde) observations. In this notebook we will read this file with the :ref:`temp reader `, which uses :ref:`pre-defined parameters ` instead of the ecCodes BUFR keys. Parameter is a high-level concept in ``pdbufr`` enabling data extraction without knowing the actual BUFR encoding and allowing more tailor-made access to specific data types." ] }, { "cell_type": "markdown", "id": "b7788371-ce79-4eb4-8ab6-e5b7ecf9664a", "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [] }, "source": [ "#### The default settings" ] }, { "cell_type": "raw", "id": "e04427eb-fbdd-4992-8d8c-d7ebb651e961", "metadata": { "editable": true, "raw_mimetype": "text/restructuredtext", "slideshow": { "slide_type": "" }, "tags": [] }, "source": [ "By default the \"stnid\", \"lat\", \"lon\", \"elevation\", \"time\" (see :ref:`station parameters ` for details) and the :ref:`upper level parameters ` are extracted. We only extract the first station from the BUFR file by specifying a ``filter``. The resulting dataframe contains one row per pressure level." ] }, { "cell_type": "code", "execution_count": 3, "id": "442ec325-ac17-4c94-a1aa-e7a49fbf59ed", "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", " \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", " \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", "
stnidlatlonelevationtimepressurezttdwind_speedwind_dir
07190758.47-78.08262008-12-08 12:00:00100300.0250.0258.3255.7NaNNaN
17190758.47-78.08262008-12-08 12:00:00100000.0430.0259.7258.30.00.0
27190758.47-78.08262008-12-08 12:00:0099800.0630.0261.1259.6NaNNaN
37190758.47-78.08262008-12-08 12:00:0099100.01160.0261.7258.3NaNNaN
47190758.47-78.08262008-12-08 12:00:0092500.06240.0258.1256.25.0275.0
57190758.47-78.08262008-12-08 12:00:0085000.012470.0253.1251.09.0250.0
67190758.47-78.08262008-12-08 12:00:0075100.021340.0245.3244.2NaNNaN
77190758.47-78.08262008-12-08 12:00:0072400.023900.0242.9239.7NaNNaN
87190758.47-78.08262008-12-08 12:00:0071700.024580.0242.3239.3NaNNaN
97190758.47-78.08262008-12-08 12:00:0070000.026240.0241.7238.312.0235.0
\n", "
" ], "text/plain": [ " stnid lat lon elevation time pressure z \\\n", "0 71907 58.47 -78.08 26 2008-12-08 12:00:00 100300.0 250.0 \n", "1 71907 58.47 -78.08 26 2008-12-08 12:00:00 100000.0 430.0 \n", "2 71907 58.47 -78.08 26 2008-12-08 12:00:00 99800.0 630.0 \n", "3 71907 58.47 -78.08 26 2008-12-08 12:00:00 99100.0 1160.0 \n", "4 71907 58.47 -78.08 26 2008-12-08 12:00:00 92500.0 6240.0 \n", "5 71907 58.47 -78.08 26 2008-12-08 12:00:00 85000.0 12470.0 \n", "6 71907 58.47 -78.08 26 2008-12-08 12:00:00 75100.0 21340.0 \n", "7 71907 58.47 -78.08 26 2008-12-08 12:00:00 72400.0 23900.0 \n", "8 71907 58.47 -78.08 26 2008-12-08 12:00:00 71700.0 24580.0 \n", "9 71907 58.47 -78.08 26 2008-12-08 12:00:00 70000.0 26240.0 \n", "\n", " t td wind_speed wind_dir \n", "0 258.3 255.7 NaN NaN \n", "1 259.7 258.3 0.0 0.0 \n", "2 261.1 259.6 NaN NaN \n", "3 261.7 258.3 NaN NaN \n", "4 258.1 256.2 5.0 275.0 \n", "5 253.1 251.0 9.0 250.0 \n", "6 245.3 244.2 NaN NaN \n", "7 242.9 239.7 NaN NaN \n", "8 242.3 239.3 NaN NaN \n", "9 241.7 238.3 12.0 235.0 " ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = pdbufr.read_bufr(\"temp_small.bufr\", reader=\"temp\", filters={\"count\": 1})\n", "df[:10]" ] }, { "cell_type": "markdown", "id": "b04b469a-2e8d-4607-a08d-9e394ce61c9c", "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [] }, "source": [ "#### Using parameter groups" ] }, { "cell_type": "raw", "id": "5c8c77d1-fa9f-422f-bb0d-01c66adb63f7", "metadata": { "editable": true, "raw_mimetype": "text/restructuredtext", "slideshow": { "slide_type": "" }, "tags": [] }, "source": [ "By using the ``columns`` option we can control the parameters to extract. Using the pre-defined values of \"station\", \"location\" or \"geometry\" we will only read station related information yielding one row per station. See details :ref:`here `." ] }, { "cell_type": "code", "execution_count": 4, "id": "5374286e-2fe4-436f-b258-b718ab8efbd7", "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", " \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", "
stnidlatlonelevationtime
07190758.47-78.08262008-12-08 12:00:00
17182353.75-73.673022008-12-08 12:00:00
289009-90.000.0028352008-12-08 12:00:00
3913486.97158.22382008-12-08 12:00:00
4914087.33134.48302008-12-08 12:00:00
57183651.27-80.65112008-12-08 12:00:00
683612-20.47-54.675672008-12-08 12:00:00
\n", "
" ], "text/plain": [ " stnid lat lon elevation time\n", "0 71907 58.47 -78.08 26 2008-12-08 12:00:00\n", "1 71823 53.75 -73.67 302 2008-12-08 12:00:00\n", "2 89009 -90.00 0.00 2835 2008-12-08 12:00:00\n", "3 91348 6.97 158.22 38 2008-12-08 12:00:00\n", "4 91408 7.33 134.48 30 2008-12-08 12:00:00\n", "5 71836 51.27 -80.65 11 2008-12-08 12:00:00\n", "6 83612 -20.47 -54.67 567 2008-12-08 12:00:00" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pdbufr.read_bufr(\"temp_small.bufr\", reader=\"temp\", columns=\"station\")" ] }, { "cell_type": "code", "execution_count": 5, "id": "023b37ee-486f-41c0-82c2-94fdcf921396", "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", " \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", "
latlon
058.47-78.08
153.75-73.67
2-90.000.00
36.97158.22
47.33134.48
551.27-80.65
6-20.47-54.67
\n", "
" ], "text/plain": [ " lat lon\n", "0 58.47 -78.08\n", "1 53.75 -73.67\n", "2 -90.00 0.00\n", "3 6.97 158.22\n", "4 7.33 134.48\n", "5 51.27 -80.65\n", "6 -20.47 -54.67" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pdbufr.read_bufr(\"temp_small.bufr\", reader=\"temp\", columns=\"location\")" ] }, { "cell_type": "code", "execution_count": 6, "id": "5b8c044f-2f0a-40f4-93fd-1aa605ce7658", "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", " \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", "
latlonelevation
058.47-78.0826
153.75-73.67302
2-90.000.002835
36.97158.2238
47.33134.4830
551.27-80.6511
6-20.47-54.67567
\n", "
" ], "text/plain": [ " lat lon elevation\n", "0 58.47 -78.08 26\n", "1 53.75 -73.67 302\n", "2 -90.00 0.00 2835\n", "3 6.97 158.22 38\n", "4 7.33 134.48 30\n", "5 51.27 -80.65 11\n", "6 -20.47 -54.67 567" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pdbufr.read_bufr(\"temp_small.bufr\", reader=\"temp\", columns=\"geometry\")" ] }, { "cell_type": "markdown", "id": "b47b8da8-6f35-4121-bcc6-840ada133bde", "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [] }, "source": [ "We can can combine these groups with \"upper\", which represents the pressure level parameters. Please note thath at the moment it is not possible to use individual parameters in ``columns``." ] }, { "cell_type": "code", "execution_count": 7, "id": "9ff9d4c1-b458-4dda-985e-00ba615e4ae5", "metadata": { "editable": true, "raw_mimetype": "", "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", " \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", "
latlonpressurezttdwind_speedwind_dir
058.47-78.08100300.0250.0258.3255.7NaNNaN
158.47-78.08100000.0430.0259.7258.30.00.0
258.47-78.0899800.0630.0261.1259.6NaNNaN
358.47-78.0899100.01160.0261.7258.3NaNNaN
458.47-78.0892500.06240.0258.1256.25.0275.0
\n", "
" ], "text/plain": [ " lat lon pressure z t td wind_speed wind_dir\n", "0 58.47 -78.08 100300.0 250.0 258.3 255.7 NaN NaN\n", "1 58.47 -78.08 100000.0 430.0 259.7 258.3 0.0 0.0\n", "2 58.47 -78.08 99800.0 630.0 261.1 259.6 NaN NaN\n", "3 58.47 -78.08 99100.0 1160.0 261.7 258.3 NaN NaN\n", "4 58.47 -78.08 92500.0 6240.0 258.1 256.2 5.0 275.0" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = pdbufr.read_bufr(\"temp_small.bufr\", reader=\"temp\", columns=[\"location\",\"upper\"], filters={\"count\": 1})\n", "df[:5]" ] }, { "cell_type": "markdown", "id": "333adc31-69ba-4635-9464-ef1cc3a03fa3", "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [] }, "source": [ "#### Adding units columns" ] }, { "cell_type": "markdown", "id": "b71f9d2c-0ec0-4625-ab31-299d5a725a15", "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [] }, "source": [ "With ``units_columns=True`` we can add units to the resulting DataFrame." ] }, { "cell_type": "code", "execution_count": 8, "id": "2a591c40-2254-426d-9b95-0f068bd612ce", "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", " \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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
stnidlatlonelevationtimepressurepressure_unitszz_unitstt_unitstdtd_unitswind_speedwind_speed_unitswind_dirwind_dir_units
07190758.47-78.08262008-12-08 12:00:00100300.0Pa250.0m2 s-2258.3K255.7KNaNm/sNaNdeg
17190758.47-78.08262008-12-08 12:00:00100000.0Pa430.0m2 s-2259.7K258.3K0.0m/s0.0deg
27190758.47-78.08262008-12-08 12:00:0099800.0Pa630.0m2 s-2261.1K259.6KNaNm/sNaNdeg
37190758.47-78.08262008-12-08 12:00:0099100.0Pa1160.0m2 s-2261.7K258.3KNaNm/sNaNdeg
47190758.47-78.08262008-12-08 12:00:0092500.0Pa6240.0m2 s-2258.1K256.2K5.0m/s275.0deg
\n", "
" ], "text/plain": [ " stnid lat lon elevation time pressure \\\n", "0 71907 58.47 -78.08 26 2008-12-08 12:00:00 100300.0 \n", "1 71907 58.47 -78.08 26 2008-12-08 12:00:00 100000.0 \n", "2 71907 58.47 -78.08 26 2008-12-08 12:00:00 99800.0 \n", "3 71907 58.47 -78.08 26 2008-12-08 12:00:00 99100.0 \n", "4 71907 58.47 -78.08 26 2008-12-08 12:00:00 92500.0 \n", "\n", " pressure_units z z_units t t_units td td_units wind_speed \\\n", "0 Pa 250.0 m2 s-2 258.3 K 255.7 K NaN \n", "1 Pa 430.0 m2 s-2 259.7 K 258.3 K 0.0 \n", "2 Pa 630.0 m2 s-2 261.1 K 259.6 K NaN \n", "3 Pa 1160.0 m2 s-2 261.7 K 258.3 K NaN \n", "4 Pa 6240.0 m2 s-2 258.1 K 256.2 K 5.0 \n", "\n", " wind_speed_units wind_dir wind_dir_units \n", "0 m/s NaN deg \n", "1 m/s 0.0 deg \n", "2 m/s NaN deg \n", "3 m/s NaN deg \n", "4 m/s 275.0 deg " ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = pdbufr.read_bufr(\"temp_small.bufr\", reader=\"temp\", filters={\"count\": 1}, units_columns=True)\n", "df[:5]" ] }, { "cell_type": "code", "execution_count": null, "id": "5fb3c901-904b-4a79-918f-7ac11407feb6", "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [] }, "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 }