diff --git a/docs/_static/style.css b/docs/_static/style.css index c79f2338e..99aefc834 100644 --- a/docs/_static/style.css +++ b/docs/_static/style.css @@ -152,6 +152,62 @@ body[data-theme="dark"] table.dataframe tbody tr:hover td { } + +@media (prefers-color-scheme: dark) { + body:not([data-theme="light"]) table.eh-table { + color: rgba(255, 255, 255, 0.87); + border-color: #555; + } + + body:not([data-theme="light"]) table.eh-table th { + background-color: var(--color-background-secondary, #1a1c1e); + color: rgba(255, 255, 255, 0.87); + border-color: #555; + } + + body:not([data-theme="light"]) table.eh-table td { + background-color: var(--color-background-primary, #131416); + color: rgba(255, 255, 255, 0.87); + border-color: #555; + } + + body:not([data-theme="light"]) table.eh-table tbody tr:nth-child(odd) td { + background-color: var(--color-background-hover, #1e2124); + } + + body:not([data-theme="light"]) table.eh-table tbody tr:hover td { + background-color: #2a2d31; + } +} + +body[data-theme="dark"] table.eh-table { + color: rgba(255, 255, 255, 0.87); + border-color: #555; +} + +body[data-theme="dark"] table.eh-table th { + background-color: var(--color-background-secondary, #1a1c1e); + color: rgba(255, 255, 255, 0.87); + border-color: #555; +} + +body[data-theme="dark"] table.eh-table td { + background-color: var(--color-background-primary, #131416); + color: rgba(255, 255, 255, 0.87); + border-color: #555; +} + +body[data-theme="dark"] table.eh-table tbody tr:nth-child(odd) td { + background-color: var(--color-background-hover, #1e2124); +} + +body[data-theme="dark"] table.eh-table tbody tr:hover td { + background-color: #2a2d31; +} + + + + .nboutput .stderr { display: none; } diff --git a/docs/examples/field/field_overview.ipynb b/docs/examples/field/field_overview.ipynb new file mode 100644 index 000000000..cb1c11ed1 --- /dev/null +++ b/docs/examples/field/field_overview.ipynb @@ -0,0 +1,398 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "fffb922f-f8d2-45a5-b1ff-4ca9daeb63b6", + "metadata": {}, + "source": [ + "## Field overview" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "c7f4e186-4f1e-437e-a27b-ef8f53cbd659", + "metadata": {}, + "outputs": [], + "source": [ + "import earthkit.data as ekd" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "7926fb1b-d9d1-4f7e-8807-5c0420da25d8", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
GRIB file

\n", + "\n", + "\n", + "
path../test.grib
size1 KiB
typesfieldlist, pandas, xarray, numpy, array
" + ], + "text/plain": [ + "GribData(path={self._reader.path})" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "d = ekd.from_source(\"file\", \"../test.grib\")\n", + "d" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "b6c10045-d894-4ebd-9e8d-82f99af3ae19", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
Field
\n", + "
\n", + "
\n", + "
\n", + "
\n", + "
\n", + "\n", + "\n", + "\n", + "
\n", + "\n", + "\n", + "\n", + "
number_of_values209
array_typendarray
array_dtypefloat64
\n", + "
\n", + " \n", + "\n", + "\n", + "
\n", + "\n", + "\n", + "\n", + "
variable2t
unitskelvin
\n", + "
\n", + " \n", + "\n", + "\n", + "
\n", + "\n", + "\n", + "\n", + "
valid_datetime2020-05-13 12:00:00
base_datetime2020-05-13 12:00:00
step0:00:00
\n", + "
\n", + " \n", + "\n", + "\n", + "
\n", + "\n", + "\n", + "\n", + "
level0
layerNone
level_typesurface
\n", + "
\n", + " \n", + "\n", + "\n", + "
\n", + "\n", + "\n", + "\n", + "
member0
\n", + "
\n", + " \n", + "\n", + "\n", + "
\n", + "\n", + "\n", + "\n", + "
grid_spec{'grid': [4.0, 4.0], 'area': [73.0, -27.0, 33.0, 45.0]}
grid_typeregular_ll
shape(11, 19)
area[73.0, -27.0, 33.0, 45.0]
\n", + "
\n", + " \n", + "
\n", + "
\n", + "
\n", + "
\n", + "
\n", + " " + ], + "text/plain": [ + "Field(2t, 2020-05-13 12:00:00, 2020-05-13 12:00:00, 0:00:00, 0, surface, 0, regular_ll)" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "f =d.to_fieldlist()[0]\n", + "f" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "fbd72d33-9b21-467d-a36c-93e6255ff665", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "f.time" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "74a157d8-c38b-4149-94d7-d56d77509a7d", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7bae9ccc-9b74-470b-8cd4-1d8b104a1b2e", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8172a231-8ee3-4d38-94dc-4148e526cf1e", + "metadata": {}, + "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.13.1" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/docs/examples/field/index.rst b/docs/examples/field/index.rst new file mode 100644 index 000000000..ea931b3d7 --- /dev/null +++ b/docs/examples/field/index.rst @@ -0,0 +1,9 @@ +.. _field_examples: + +Fields +++++++++++++++ + +.. toctree:: + :maxdepth: 1 + + field_overview.ipynb diff --git a/docs/examples/source/data.ipynb b/docs/examples/source/data.ipynb new file mode 100644 index 000000000..ce359110c --- /dev/null +++ b/docs/examples/source/data.ipynb @@ -0,0 +1,785 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "4fd4382b-a433-49c1-a0f1-d59df9732a9f", + "metadata": {}, + "source": [ + "## The object returned by from_source" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "3ea031c4-361f-4713-ba00-4ca1fb6cb62c", + "metadata": {}, + "outputs": [], + "source": [ + "import earthkit.data as ekd" + ] + }, + { + "cell_type": "raw", + "id": "585ef6df-2c34-4dd9-8707-bce7660772c8", + "metadata": { + "editable": true, + "raw_mimetype": "text/x-rst", + "slideshow": { + "slide_type": "" + }, + "tags": [] + }, + "source": [ + ":ref:`from_source ` always returns a Data object, which provides some extra information about the the data but its primary goal is to convert the data into the required representation for further work. The actual data loading is deferred, as much as possible, until the data is converted into a given type." + ] + }, + { + "cell_type": "markdown", + "id": "c6fcc1ca-fcb3-4fb1-a72a-be540d0e2a92", + "metadata": {}, + "source": [ + "### File sources" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "28d4f543-ec08-4008-9d2c-87409cef21cc", + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [] + }, + "outputs": [ + { + "data": { + "text/html": [ + "
GRIB file

\n", + "\n", + "\n", + "
pathtest.grib
size1 KiB
typesfieldlist, pandas, xarray, numpy, array
" + ], + "text/plain": [ + "GribData(path={self._reader.path})" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "d = ekd.from_source(\"file\", \"test.grib\")\n", + "d" + ] + }, + { + "cell_type": "markdown", + "id": "9a03c697-3f20-46f4-8865-d58b868a107a", + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [] + }, + "source": [ + "The \"available types\" tells us the types we can comvert the data into. This list is also available as a property on the data object. " + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "244ef063-6b98-4e22-b516-f68c56bf6091", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['fieldlist', 'pandas', 'xarray', 'numpy', 'array']" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "d.available_types" + ] + }, + { + "cell_type": "markdown", + "id": "d3d8cace-d21a-40c9-92d0-ae339b7db49b", + "metadata": {}, + "source": [ + "To convert the data we need to call one of the \"to_\" methods. E.g we can convert our data into a fieldlist." + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "4517f46b-f1a0-4736-b198-1eaf0a2a4620", + "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", + "
parameter.variabletime.valid_datetimetime.base_datetimetime.stepvertical.levelvertical.level_typeensemble.membergeography.grid_type
02t2020-05-13 12:00:002020-05-13 12:00:000 days0surface0regular_ll
1msl2020-05-13 12:00:002020-05-13 12:00:000 days0surface0regular_ll
\n", + "
" + ], + "text/plain": [ + " parameter.variable time.valid_datetime time.base_datetime time.step \\\n", + "0 2t 2020-05-13 12:00:00 2020-05-13 12:00:00 0 days \n", + "1 msl 2020-05-13 12:00:00 2020-05-13 12:00:00 0 days \n", + "\n", + " vertical.level vertical.level_type ensemble.member geography.grid_type \n", + "0 0 surface 0 regular_ll \n", + "1 0 surface 0 regular_ll " + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "fl = d.to_fieldlist()\n", + "fl.ls()" + ] + }, + { + "cell_type": "markdown", + "id": "bcdb099c-5cf7-4636-8222-77762eb50711", + "metadata": {}, + "source": [ + "Some conversions may involve other conversions under the hood. For example, when GRIB is converted to Xarray, first it is always loaded into a fieldlist then converted to Xarray." + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "a41f4849-0ebb-4b97-9a4c-5890705d6791", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "
<xarray.Dataset> Size: 4kB\n",
+       "Dimensions:    (latitude: 11, longitude: 19)\n",
+       "Coordinates:\n",
+       "  * latitude   (latitude) float64 88B 73.0 69.0 65.0 61.0 ... 41.0 37.0 33.0\n",
+       "  * longitude  (longitude) float64 152B -27.0 -23.0 -19.0 ... 37.0 41.0 45.0\n",
+       "Data variables:\n",
+       "    2t         (latitude, longitude) float64 2kB ...\n",
+       "    msl        (latitude, longitude) float64 2kB ...\n",
+       "Attributes:\n",
+       "    Conventions:  CF-1.8\n",
+       "    institution:  ECMWF
" + ], + "text/plain": [ + " Size: 4kB\n", + "Dimensions: (latitude: 11, longitude: 19)\n", + "Coordinates:\n", + " * latitude (latitude) float64 88B 73.0 69.0 65.0 61.0 ... 41.0 37.0 33.0\n", + " * longitude (longitude) float64 152B -27.0 -23.0 -19.0 ... 37.0 41.0 45.0\n", + "Data variables:\n", + " 2t (latitude, longitude) float64 2kB ...\n", + " msl (latitude, longitude) float64 2kB ...\n", + "Attributes:\n", + " Conventions: CF-1.8\n", + " institution: ECMWF" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# this first loads the GRIB data into a fieldlist and converts that into Xarray\n", + "ds = d.to_xarray()\n", + "ds" + ] + }, + { + "cell_type": "markdown", + "id": "2bb18634-b699-40e1-9c14-bd587c314983", + "metadata": {}, + "source": [ + "### Streams" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b2602d40-7ee1-4473-95d2-a51a7b28c822", + "metadata": {}, + "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.13.1" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/docs/examples/source/files.ipynb b/docs/examples/source/files.ipynb index f55fb4945..a22ed1ff3 100644 --- a/docs/examples/source/files.ipynb +++ b/docs/examples/source/files.ipynb @@ -73,7 +73,7 @@ "tags": [] }, "source": [ - "Files can be read by :ref:`from_source ` as a \"file\" source. The resulting object depends privides some deatils about the data and to types it can converted to for further work." + "Files can be read by :ref:`from_source ` as a \"file\" source. The resulting object provides some details about the data and the types it can be converted to for further work. " ] }, { @@ -91,7 +91,19 @@ { "data": { "text/html": [ - "

GRIB file
Path: test.grib size: 1 KiB
Available types: fieldlist, pandas, xarray, numpy, array

" + "
GRIB file

\n", + "\n", + "\n", + "
pathtest.grib
size1 KiB
typesfieldlist, pandas, xarray, numpy, array
" ], "text/plain": [ "GribData(path={self._reader.path})" @@ -133,10 +145,22 @@ { "data": { "text/html": [ - "

NetCDF file
Path: test.nc size: 6.4 KiB
Available types: xarray, pandas, fieldlist, numpy, array

" + "
NetCDF file

\n", + "\n", + "\n", + "
pathtest.nc
size6.4 KiB
typesxarray, pandas, fieldlist, numpy, array
" ], "text/plain": [ - "" + "" ] }, "execution_count": 5, @@ -667,8 +691,8 @@ " GRIB_subCentre: 0\n", " Conventions: CF-1.7\n", " institution: European Centre for Medium-Range Weather Forecasts\n", - " history: GRIB to CDM+CF via cfgrib-0.9.5/ecCodes-2.17.0 w...