{ "cells": [ { "cell_type": "markdown", "id": "4cf9f31e-4b58-43bd-842e-142f0affb4a8", "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [] }, "source": [ "## Using ODB data" ] }, { "cell_type": "code", "execution_count": 1, "id": "03108956-3f8e-4132-88e4-7455a4cc78dc", "metadata": {}, "outputs": [], "source": [ "import earthkit.data as ekd\n", "ekd.download_example_file(\"test.odb\")" ] }, { "cell_type": "raw", "id": "a9e6621e-5c32-4a0d-a992-209660f58f68", "metadata": { "editable": true, "raw_mimetype": "text/restructuredtext", "slideshow": { "slide_type": "" }, "tags": [] }, "source": [ "`ODB `_ is a bespoke format developed at ECMWF to store observations. The following code reads some ODB data with :ref:`from_source() ` from a file containing forecast and analysis departures:" ] }, { "cell_type": "code", "execution_count": 2, "id": "d2f705e7-8336-4355-9b60-1fe05d8e23b3", "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [] }, "outputs": [], "source": [ "ds = ekd.from_source(\"file\", \"test.odb\")" ] }, { "cell_type": "markdown", "id": "6a0702a9-0b1a-46e6-bac3-71c78050f2e4", "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [] }, "source": [ "*to_pandas()* converts data into a Pandas dataframe (uses [pyodc](https://github.com/ecmwf/pyodc) under the hood):" ] }, { "cell_type": "code", "execution_count": 3, "id": "2f252c91-3cc9-46ec-b262-3b2f399ce05d", "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", "
latlonfg_depan_dep
038.8089984.2926000.5145430.513129
173.693100-3.416700-0.098977-0.123831
231.168501-29.8654990.4201310.389983
349.040798-19.877501-0.182703-0.124131
473.35109740.1761020.0876870.149949
...............
71245.798801-0.5271000.1038590.132765
71373.788597-8.806200-0.069707-0.080577
71460.162998-14.5729000.1388160.011107
71553.455299-29.6416000.0825820.184872
71640.66920129.702101-0.023861-0.032721
\n", "

717 rows × 4 columns

\n", "
" ], "text/plain": [ " lat lon fg_dep an_dep\n", "0 38.808998 4.292600 0.514543 0.513129\n", "1 73.693100 -3.416700 -0.098977 -0.123831\n", "2 31.168501 -29.865499 0.420131 0.389983\n", "3 49.040798 -19.877501 -0.182703 -0.124131\n", "4 73.351097 40.176102 0.087687 0.149949\n", ".. ... ... ... ...\n", "712 45.798801 -0.527100 0.103859 0.132765\n", "713 73.788597 -8.806200 -0.069707 -0.080577\n", "714 60.162998 -14.572900 0.138816 0.011107\n", "715 53.455299 -29.641600 0.082582 0.184872\n", "716 40.669201 29.702101 -0.023861 -0.032721\n", "\n", "[717 rows x 4 columns]" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = ds.to_pandas()\n", "df" ] }, { "cell_type": "markdown", "id": "83537ee3-30c8-4797-a550-7387a0e72672", "metadata": {}, "source": [ "We can directly pass arguments to pyodc. E.g. **columns** specify a subset of the ODB columns we want to extract:" ] }, { "cell_type": "code", "execution_count": 4, "id": "fa1f0e84-a66e-426d-9a23-fc4329afd34e", "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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
latlonan_dep
038.8089984.2926000.513129
173.693100-3.416700-0.123831
231.168501-29.8654990.389983
349.040798-19.877501-0.124131
473.35109740.1761020.149949
............
71245.798801-0.5271000.132765
71373.788597-8.806200-0.080577
71460.162998-14.5729000.011107
71553.455299-29.6416000.184872
71640.66920129.702101-0.032721
\n", "

717 rows × 3 columns

\n", "
" ], "text/plain": [ " lat lon an_dep\n", "0 38.808998 4.292600 0.513129\n", "1 73.693100 -3.416700 -0.123831\n", "2 31.168501 -29.865499 0.389983\n", "3 49.040798 -19.877501 -0.124131\n", "4 73.351097 40.176102 0.149949\n", ".. ... ... ...\n", "712 45.798801 -0.527100 0.132765\n", "713 73.788597 -8.806200 -0.080577\n", "714 60.162998 -14.572900 0.011107\n", "715 53.455299 -29.641600 0.184872\n", "716 40.669201 29.702101 -0.032721\n", "\n", "[717 rows x 3 columns]" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df1 = ds.to_pandas(odc_read_odb_kwargs={\"columns\": (\"lat\", \"lon\", \"an_dep\")})\n", "df1" ] }, { "cell_type": "code", "execution_count": null, "id": "62568d51-78d6-46f0-852e-3ed1ccef5da5", "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 }