{ "cells": [ { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "# Climatology calculations" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "# Imports\n", "from earthkit.transforms import aggregate as ek_aggregate\n", "from earthkit import data as ek_data\n", "from earthkit.data.testing import earthkit_remote_test_data_file\n", "ek_data.settings.set(\"cache-policy\", \"user\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "## Load some test data\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; and we will use the NUTS geometries which are stored in a geojson file.\n", "\n", "All `earthkit-transforms` methods can be called with `earthkit-data` objects (Readers and Wrappers) or with a pre-loaded `xarray`. To reduce the number of conversions in the example, we will convert to xarray in the first cell and use that data object for all subsequent steps." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "18b52a343a9849a7862e37ad763a862c", "version_major": 2, "version_minor": 0 }, "text/plain": [ "era5_temperature_france_2015_2016_2017_3deg.grib: 0%| | 0.00/109k [00:00, ?B/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
<xarray.Dataset> Size: 111kB\n",
"Dimensions: (number: 1, valid_time: 542, surface: 1, latitude: 7,\n",
" longitude: 7)\n",
"Coordinates:\n",
" * number (number) int64 8B 0\n",
" * valid_time (valid_time) datetime64[ns] 4kB 2015-01-01 ... 2017-03-31T12:...\n",
" * surface (surface) float64 8B 0.0\n",
" * latitude (latitude) float64 56B 48.0 45.0 42.0 39.0 36.0 33.0 30.0\n",
" * longitude (longitude) float64 56B 0.0 3.0 6.0 9.0 12.0 15.0 18.0\n",
"Data variables:\n",
" t2m (number, valid_time, surface, latitude, longitude) float32 106kB ...\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...<xarray.Dataset> Size: 740B\n",
"Dimensions: (month: 3, number: 1, surface: 1, latitude: 7, longitude: 7)\n",
"Coordinates:\n",
" * number (number) int64 8B 0\n",
" * surface (surface) float64 8B 0.0\n",
" * latitude (latitude) float64 56B 48.0 45.0 42.0 39.0 36.0 33.0 30.0\n",
" * longitude (longitude) float64 56B 0.0 3.0 6.0 9.0 12.0 15.0 18.0\n",
" * month (month) int64 24B 1 2 3\n",
"Data variables:\n",
" t2m (month, number, surface, latitude, longitude) float32 588B 278...\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...<xarray.Dataset> Size: 19kB\n",
"Dimensions: (dayofyear: 91, number: 1, surface: 1, latitude: 7, longitude: 7)\n",
"Coordinates:\n",
" * number (number) int64 8B 0\n",
" * surface (surface) float64 8B 0.0\n",
" * latitude (latitude) float64 56B 48.0 45.0 42.0 39.0 36.0 33.0 30.0\n",
" * longitude (longitude) float64 56B 0.0 3.0 6.0 9.0 12.0 15.0 18.0\n",
" * dayofyear (dayofyear) int64 728B 1 2 3 4 5 6 7 8 ... 85 86 87 88 89 90 91\n",
"Data variables:\n",
" t2m (dayofyear, number, surface, latitude, longitude) float32 18kB ...\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...<xarray.Dataset> Size: 748B\n",
"Dimensions: (month: 3, number: 1, step: 1, surface: 1, latitude: 7,\n",
" longitude: 7)\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 56B 48.0 45.0 42.0 39.0 36.0 33.0 30.0\n",
" * longitude (longitude) float64 56B 0.0 3.0 6.0 9.0 12.0 15.0 18.0\n",
" * month (month) int64 24B 1 2 3\n",
"Data variables:\n",
" t2m (month, number, step, surface, latitude, longitude) float32 588B ...\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...<xarray.Dataset> Size: 4kB\n",
"Dimensions: (quantile: 3, month: 3, number: 1, surface: 1, latitude: 7,\n",
" longitude: 7)\n",
"Coordinates:\n",
" * number (number) int64 8B 0\n",
" * surface (surface) float64 8B 0.0\n",
" * latitude (latitude) float64 56B 48.0 45.0 42.0 39.0 36.0 33.0 30.0\n",
" * longitude (longitude) float64 56B 0.0 3.0 6.0 9.0 12.0 15.0 18.0\n",
" * quantile (quantile) float64 24B 0.1 0.5 0.9\n",
" * month (month) int64 24B 1 2 3\n",
"Data variables:\n",
" t2m (quantile, month, number, surface, latitude, longitude) float64 4kB dask.array<chunksize=(1, 1, 1, 1, 7, 7), meta=np.ndarray>