{ "cells": [ { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "# Providing a bespoke function to the temporal reduce methods" ] }, { "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": 29, "metadata": {}, "outputs": [], "source": [ "from statsmodels import api as sm\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", "\n", "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\")" ] }, { "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: 230kB\n",
"Dimensions: (number: 1, step: 1, surface: 1, latitude: 201, 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",
"Data variables:\n",
" t2m (number, step, surface, latitude, longitude) float32 226kB 0.0...\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-10-15T14:46 GRIB to CDM+CF via cfgrib-0.9.1...