{ "cells": [ { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "# Daily statistics from hourly ERA5 data" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "# If first time running, uncomment the line below to install any additional dependencies\n", "# !bash requirements-for-notebooks.sh" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "from earthkit.transforms import aggregate as ek_aggregate\n", "from earthkit import data as ek_data\n", "\n", "from earthkit.data.testing import earthkit_remote_test_data_file\n", "ek_data.settings.set(\"cache-policy\", \"user\")\n", "\n", "import matplotlib.pyplot as plt" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Load some test data\n", "\n", "All `earthkit-transforms` methods can be called with `earthkit-data` objects (Readers and Wrappers) or with the \n", "pre-loaded `xarray`.\n", "\n", "In this example we will use hourly ERA5 2m temperature data on a 0.5x0.5 spatial grid for the year 2015 as\n", "our physical data.\n", "\n", "First we download (if not already cached) lazily load the ERA5 data (please see tutorials in `earthkit-data` for more details in cache management).\n", "\n", "We inspect the data using the describe method and see we have some 2m air temperature data. For a more detailed representation of the data you can use the to_xarray method." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
| \n", " | \n", " | level | \n", "date | \n", "time | \n", "step | \n", "paramId | \n", "class | \n", "stream | \n", "type | \n", "experimentVersionNumber | \n", "
|---|---|---|---|---|---|---|---|---|---|---|
| shortName | \n", "typeOfLevel | \n", "\n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " |
| 2t | \n", "surface | \n", "0 | \n", "20150301,20150302,... | \n", "0,1800,... | \n", "0 | \n", "167 | \n", "ea | \n", "oper | \n", "an | \n", "0001 | \n", "
<xarray.Dataset> Size: 82MB\n",
"Dimensions: (time: 365, number: 1, step: 1, surface: 1, latitude: 201,\n",
" longitude: 281)\n",
"Coordinates:\n",
" * number (number) int64 8B 0\n",
" * step (step) timedelta64[ns] 8B 00:00:00\n",
" * surface (surface) float64 8B 0.0\n",
" * latitude (latitude) float64 2kB 80.0 79.75 79.5 79.25 ... 30.5 30.25 30.0\n",
" * longitude (longitude) float64 2kB -10.0 -9.75 -9.5 ... 59.5 59.75 60.0\n",
" * time (time) datetime64[ns] 3kB 2015-01-01 2015-01-02 ... 2015-12-31\n",
"Data variables:\n",
" t2m (time, number, step, surface, latitude, longitude) float32 82MB ...\n",
"Attributes:\n",
" GRIB_edition: 1\n",
" GRIB_centre: ecmf\n",
" GRIB_centreDescription: European Centre for Medium-Range Weather Forecasts\n",
" GRIB_subCentre: 0\n",
" Conventions: CF-1.7\n",
" institution: European Centre for Medium-Range Weather Forecasts\n",
" history: 2024-07-29T09:06 GRIB to CDM+CF via cfgrib-0.9.1...<xarray.Dataset> Size: 3MB\n",
"Dimensions: (time: 12, number: 1, step: 1, surface: 1, latitude: 201,\n",
" longitude: 281)\n",
"Coordinates:\n",
" * number (number) int64 8B 0\n",
" * step (step) timedelta64[ns] 8B 00:00:00\n",
" * surface (surface) float64 8B 0.0\n",
" * latitude (latitude) float64 2kB 80.0 79.75 79.5 79.25 ... 30.5 30.25 30.0\n",
" * longitude (longitude) float64 2kB -10.0 -9.75 -9.5 ... 59.5 59.75 60.0\n",
" * time (time) datetime64[ns] 96B 2015-01-01 2015-02-01 ... 2015-12-01\n",
"Data variables:\n",
" t2m (time, number, step, surface, latitude, longitude) float32 3MB ...\n",
"Attributes:\n",
" GRIB_edition: 1\n",
" GRIB_centre: ecmf\n",
" GRIB_centreDescription: European Centre for Medium-Range Weather Forecasts\n",
" GRIB_subCentre: 0\n",
" Conventions: CF-1.7\n",
" institution: European Centre for Medium-Range Weather Forecasts\n",
" history: 2024-07-29T09:06 GRIB to CDM+CF via cfgrib-0.9.1...<xarray.Dataset> Size: 330MB\n",
"Dimensions: (number: 1, time: 1460, step: 1, surface: 1, latitude: 201,\n",
" longitude: 281)\n",
"Coordinates:\n",
" * number (number) int64 8B 0\n",
" * time (time) datetime64[ns] 12kB 2015-01-01 ... 2015-12-31T18:00:00\n",
" * step (step) timedelta64[ns] 8B 00:00:00\n",
" * surface (surface) float64 8B 0.0\n",
" * latitude (latitude) float64 2kB 80.0 79.75 79.5 79.25 ... 30.5 30.25 30.0\n",
" * longitude (longitude) float64 2kB -10.0 -9.75 -9.5 ... 59.5 59.75 60.0\n",
" valid_time (time, step) datetime64[ns] 12kB dask.array<chunksize=(1460, 1), meta=np.ndarray>\n",
"Data variables:\n",
" t2m (number, time, step, surface, latitude, longitude) float32 330MB dask.array<chunksize=(1, 1459, 1, 1, 201, 281), meta=np.ndarray>\n",
"Attributes:\n",
" GRIB_edition: 1\n",
" GRIB_centre: ecmf\n",
" GRIB_centreDescription: European Centre for Medium-Range Weather Forecasts\n",
" GRIB_subCentre: 0\n",
" Conventions: CF-1.7\n",
" institution: European Centre for Medium-Range Weather Forecasts\n",
" history: 2024-07-29T09:06 GRIB to CDM+CF via cfgrib-0.9.1...<xarray.Dataset> Size: 83MB\n",
"Dimensions: (time: 366, number: 1, step: 1, surface: 1, latitude: 201,\n",
" longitude: 281)\n",
"Coordinates:\n",
" * number (number) int64 8B 0\n",
" * step (step) timedelta64[ns] 8B 00:00:00\n",
" * surface (surface) float64 8B 0.0\n",
" * latitude (latitude) float64 2kB 80.0 79.75 79.5 79.25 ... 30.5 30.25 30.0\n",
" * longitude (longitude) float64 2kB -10.0 -9.75 -9.5 ... 59.5 59.75 60.0\n",
" * time (time) datetime64[ns] 3kB 2015-01-01 2015-01-02 ... 2016-01-01\n",
"Data variables:\n",
" t2m (time, number, step, surface, latitude, longitude) float32 83MB ...\n",
"Attributes:\n",
" GRIB_edition: 1\n",
" GRIB_centre: ecmf\n",
" GRIB_centreDescription: European Centre for Medium-Range Weather Forecasts\n",
" GRIB_subCentre: 0\n",
" Conventions: CF-1.7\n",
" institution: European Centre for Medium-Range Weather Forecasts\n",
" history: 2024-07-29T09:06 GRIB to CDM+CF via cfgrib-0.9.1...