{ "cells": [ { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "# Daily statistics from six-hourly SEAS5 data" ] }, { "cell_type": "code", "execution_count": 10, "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": 11, "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 three initialisation of the SEAS5 2m temperature data on a 1.x1. spatial grid. The temporal resolution is 6 hourly, and we have the forecasts for January, February and March 2015.\n", "\n", "First we download (if not already cached) and lazily load the SEAS5 data (please see tutorials in `earthkit-data` for more details in cache management).\n", "\n", "We inspect the data using the to_xarray method and see we have some 2m air temperature data. Using the xarray representation each of the dimensions can be queried." ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
<xarray.Dataset> Size: 91MB\n",
"Dimensions: (number: 25, time: 3, step: 239, surface: 1, latitude: 31,\n",
" longitude: 41)\n",
"Coordinates:\n",
" * number (number) int64 200B 0 1 2 3 4 5 6 7 ... 17 18 19 20 21 22 23 24\n",
" * time (time) datetime64[ns] 24B 2015-01-01 2015-02-01 2015-03-01\n",
" * step (step) timedelta64[ns] 2kB 0 days 06:00:00 ... 59 days 18:00:00\n",
" * surface (surface) float64 8B 0.0\n",
" * latitude (latitude) float64 248B 70.0 69.0 68.0 67.0 ... 42.0 41.0 40.0\n",
" * longitude (longitude) float64 328B -10.0 -9.0 -8.0 -7.0 ... 28.0 29.0 30.0\n",
" valid_time (time, step) datetime64[ns] 6kB ...\n",
"Data variables:\n",
" t2m (number, time, step, surface, latitude, longitude) float32 91MB ...\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-12T08:58 GRIB to CDM+CF via cfgrib-0.9.1...<xarray.Dataset> Size: 23MB\n",
"Dimensions: (step: 60, number: 25, time: 3, surface: 1, latitude: 31,\n",
" longitude: 41)\n",
"Coordinates:\n",
" * number (number) int64 200B 0 1 2 3 4 5 6 7 ... 17 18 19 20 21 22 23 24\n",
" * time (time) datetime64[ns] 24B 2015-01-01 2015-02-01 2015-03-01\n",
" * surface (surface) float64 8B 0.0\n",
" * latitude (latitude) float64 248B 70.0 69.0 68.0 67.0 ... 42.0 41.0 40.0\n",
" * longitude (longitude) float64 328B -10.0 -9.0 -8.0 -7.0 ... 28.0 29.0 30.0\n",
" * step (step) timedelta64[ns] 480B 0 days 06:00:00 ... 59 days 06:00:00\n",
" valid_time (time, step) datetime64[ns] 1kB 2015-01-01T06:00:00 ... 2015-...\n",
"Data variables:\n",
" t2m (step, number, time, surface, latitude, longitude) float32 23MB ...\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-12T08:58 GRIB to CDM+CF via cfgrib-0.9.1...<xarray.Dataset> Size: 15MB\n",
"Dimensions: (date: 119, number: 25, surface: 1, latitude: 31, longitude: 41)\n",
"Coordinates:\n",
" * number (number) int64 200B 0 1 2 3 4 5 6 7 8 ... 17 18 19 20 21 22 23 24\n",
" * surface (surface) float64 8B 0.0\n",
" * latitude (latitude) float64 248B 70.0 69.0 68.0 67.0 ... 42.0 41.0 40.0\n",
" * longitude (longitude) float64 328B -10.0 -9.0 -8.0 -7.0 ... 28.0 29.0 30.0\n",
" * date (date) datetime64[ns] 952B 2015-01-01 2015-01-02 ... 2015-04-29\n",
"Data variables:\n",
" t2m (date, number, surface, latitude, longitude) float32 15MB 269....\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-12T08:59 GRIB to CDM+CF via cfgrib-0.9.1...