{ "cells": [ { "cell_type": "markdown", "id": "e4a4f2e7-c9dc-44eb-90ba-ee22a07bf7cc", "metadata": {}, "source": [ "## Reading NetCDF data from OPEnDAP services" ] }, { "cell_type": "raw", "id": "15f9e9da-05df-4d06-8dbf-a77ea2bf46c4", "metadata": { "editable": true, "raw_mimetype": "text/restructuredtext", "slideshow": { "slide_type": "" }, "tags": [] }, "source": [ "In this example we read NetCDF data from an OPEnDAP service using the :ref:`data-sources-opendap` source." ] }, { "cell_type": "code", "execution_count": 1, "id": "b56c4de5-3737-4f71-8407-14685eaca2b7", "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [] }, "outputs": [], "source": [ "import earthkit.data as ekd\n", "\n", "url=\"https://psl.noaa.gov/thredds/dodsC/Datasets/noaa.oisst.v2/sst.mnmean.nc\"\n", "ds = ekd.from_source(\"opendap\", url)" ] }, { "cell_type": "markdown", "id": "2b87c915-b0e1-4e26-8158-b4a6205fb762", "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [] }, "source": [ "What we get is a NetCDF fieldlist." ] }, { "cell_type": "code", "execution_count": 2, "id": "e4ce374f-71f7-4a22-b3e5-2f8a2b38357c", "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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
variablelevelvalid_datetimeunits
0sstNone1981-12-01T00:00:00degC
1sstNone1982-01-01T00:00:00degC
2sstNone1982-02-01T00:00:00degC
3sstNone1982-03-01T00:00:00degC
4sstNone1982-04-01T00:00:00degC
...............
489sstNone2022-09-01T00:00:00degC
490sstNone2022-10-01T00:00:00degC
491sstNone2022-11-01T00:00:00degC
492sstNone2022-12-01T00:00:00degC
493sstNone2023-01-01T00:00:00degC
\n", "

494 rows × 4 columns

\n", "
" ], "text/plain": [ " variable level valid_datetime units\n", "0 sst None 1981-12-01T00:00:00 degC\n", "1 sst None 1982-01-01T00:00:00 degC\n", "2 sst None 1982-02-01T00:00:00 degC\n", "3 sst None 1982-03-01T00:00:00 degC\n", "4 sst None 1982-04-01T00:00:00 degC\n", ".. ... ... ... ...\n", "489 sst None 2022-09-01T00:00:00 degC\n", "490 sst None 2022-10-01T00:00:00 degC\n", "491 sst None 2022-11-01T00:00:00 degC\n", "492 sst None 2022-12-01T00:00:00 degC\n", "493 sst None 2023-01-01T00:00:00 degC\n", "\n", "[494 rows x 4 columns]" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ds.ls()" ] }, { "cell_type": "code", "execution_count": 3, "id": "c7fa8a57-7d75-4b1d-81ba-4ee6139161ab", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(180, 360)" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "v = ds[2].to_numpy()\n", "v.shape" ] }, { "cell_type": "code", "execution_count": 4, "id": "f244d7ec-65c9-42b6-8c96-5846e4decccd", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "
<xarray.Dataset> Size: 128MB\n",
       "Dimensions:    (lat: 180, lon: 360, time: 494, nbnds: 2)\n",
       "Coordinates:\n",
       "  * lat        (lat) float32 720B 89.5 88.5 87.5 86.5 ... -87.5 -88.5 -89.5\n",
       "  * lon        (lon) float32 1kB 0.5 1.5 2.5 3.5 4.5 ... 356.5 357.5 358.5 359.5\n",
       "  * time       (time) datetime64[ns] 4kB 1981-12-01 1982-01-01 ... 2023-01-01\n",
       "Dimensions without coordinates: nbnds\n",
       "Data variables:\n",
       "    time_bnds  (time, nbnds) datetime64[ns] 8kB dask.array<chunksize=(494, 2), meta=np.ndarray>\n",
       "    sst        (time, lat, lon) float32 128MB dask.array<chunksize=(494, 180, 360), meta=np.ndarray>\n",
       "Attributes:\n",
       "    title:                           NOAA Optimum Interpolation (OI) SST V2\n",
       "    Conventions:                     CF-1.0\n",
       "    history:                         Wed Apr  6 13:47:45 2005: ncks -d time,0...\n",
       "    comments:                        Data described in  Reynolds, R.W., N.A. ...\n",
       "    platform:                        Model\n",
       "    source:                          NCEP Climate Modeling Branch\n",
       "    institution:                     National Centers for Environmental Predi...\n",
       "    References:                      https://www.psl.noaa.gov/data/gridded/da...\n",
       "    dataset_title:                   NOAA Optimum Interpolation (OI) SST V2\n",
       "    source_url:                      http://www.emc.ncep.noaa.gov/research/cm...\n",
       "    DODS_EXTRA.Unlimited_Dimension:  time
" ], "text/plain": [ " Size: 128MB\n", "Dimensions: (lat: 180, lon: 360, time: 494, nbnds: 2)\n", "Coordinates:\n", " * lat (lat) float32 720B 89.5 88.5 87.5 86.5 ... -87.5 -88.5 -89.5\n", " * lon (lon) float32 1kB 0.5 1.5 2.5 3.5 4.5 ... 356.5 357.5 358.5 359.5\n", " * time (time) datetime64[ns] 4kB 1981-12-01 1982-01-01 ... 2023-01-01\n", "Dimensions without coordinates: nbnds\n", "Data variables:\n", " time_bnds (time, nbnds) datetime64[ns] 8kB dask.array\n", " sst (time, lat, lon) float32 128MB dask.array\n", "Attributes:\n", " title: NOAA Optimum Interpolation (OI) SST V2\n", " Conventions: CF-1.0\n", " history: Wed Apr 6 13:47:45 2005: ncks -d time,0...\n", " comments: Data described in Reynolds, R.W., N.A. ...\n", " platform: Model\n", " source: NCEP Climate Modeling Branch\n", " institution: National Centers for Environmental Predi...\n", " References: https://www.psl.noaa.gov/data/gridded/da...\n", " dataset_title: NOAA Optimum Interpolation (OI) SST V2\n", " source_url: http://www.emc.ncep.noaa.gov/research/cm...\n", " DODS_EXTRA.Unlimited_Dimension: time" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ds.to_xarray()" ] }, { "cell_type": "code", "execution_count": null, "id": "32b6e298-9c41-49d9-827f-fd2ccbe9935b", "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 }