Climatology meanΒΆ
This notebook demonstrates how to calculate a climatological mean of a long time-series of data.
[1]:
from earthkit import data as ekd
from earthkit import transforms as ekt
from earthkit.transforms._tools import earthkit_remote_test_data_file
# Get some demonstration ERA5 data, this could be any url or path to an ERA5 grib or netCDF file.
remote_era5_file = earthkit_remote_test_data_file("ERA5-Reading-2m-temperature-1940-2025.nc")
era5_data = ekd.from_source("url", remote_era5_file)
era5_xr = era5_data.to_xarray()
# Total climatology, i.e. the mean over all time steps:
climatology_mean = ekt.climatology.mean(era5_xr, climatology_range=("1991", "2020"))
climatology_mean
[1]:
<xarray.Dataset> Size: 20B
Dimensions: ()
Coordinates:
latitude float64 8B ...
longitude float64 8B ...
Data variables:
t2m float32 4B 283.7
Attributes:
Conventions: CF-1.7
GRIB_centre: ecmf
GRIB_centreDescription: European Centre for Medium-Range Weather Forecasts
GRIB_edition: 1
GRIB_subCentre: 0
history: 2024-09-02T04:48 GRIB to CDM+CF via cfgrib-0.9.1...
institution: European Centre for Medium-Range Weather Forecasts[2]:
# Monthly climatology, i.e. the mean for each month of the year:
climatology_monthly_mean = ekt.climatology.monthly_mean(era5_xr, climatology_range=("1991", "2020"))
climatology_monthly_mean
[2]:
<xarray.Dataset> Size: 160B
Dimensions: (month: 12)
Coordinates:
* month (month) int64 96B 1 2 3 4 5 6 7 8 9 10 11 12
latitude float64 8B 51.5
longitude float64 8B -1.0
Data variables:
t2m (month) float32 48B 278.0 278.2 280.0 282.3 ... 284.2 280.8 278.4
Attributes:
Conventions: CF-1.7
GRIB_centre: ecmf
GRIB_centreDescription: European Centre for Medium-Range Weather Forecasts
GRIB_edition: 1
GRIB_subCentre: 0
history: 2024-09-02T04:48 GRIB to CDM+CF via cfgrib-0.9.1...
institution: European Centre for Medium-Range Weather Forecasts[3]:
# Daily climatology, i.e. the mean for each day of the year:
climatology_daily_mean = ekt.climatology.daily_mean(era5_xr, climatology_range=("1991", "2020"))
climatology_daily_mean
[3]:
<xarray.Dataset> Size: 4kB
Dimensions: (dayofyear: 366)
Coordinates:
* dayofyear (dayofyear) int64 3kB 1 2 3 4 5 6 7 ... 361 362 363 364 365 366
latitude float64 8B 51.5
longitude float64 8B -1.0
Data variables:
t2m (dayofyear) float32 1kB 278.3 278.0 277.6 ... 277.9 277.9 276.0
Attributes:
Conventions: CF-1.7
GRIB_centre: ecmf
GRIB_centreDescription: European Centre for Medium-Range Weather Forecasts
GRIB_edition: 1
GRIB_subCentre: 0
history: 2024-09-02T04:48 GRIB to CDM+CF via cfgrib-0.9.1...
institution: European Centre for Medium-Range Weather Forecasts[ ]: