Calculate the spatial mean of gridded data over an area/bounding box¶
This notebook demonstrates how to compute the spatial mean of some sample 2m temperature data for a given rectangular area bounding box. This is done via the area keyword argument, it is a dictionary with keys "north", "south", "east", and "west".
[1]:
from earthkit import data as ekd
from earthkit import transforms as ekt
from earthkit.transforms._tools import earthkit_remote_test_data_file
remote_era5_file = earthkit_remote_test_data_file("era5-Europe-sfc-2m-temperature-3deg-2015-2017.grib")
era5_data = ekd.from_source("url", remote_era5_file)
ds = era5_data.to_xarray()
# Define a bounding box covering central Europe
area = {"north": 55, "south": 45, "east": 20, "west": 5}
# Calculate area mean using the bounding box
area_mean_bbox = ekt.spatial.reduce(ds, area=area, how="mean", weights="latitude")
area_mean_bbox
[1]:
<xarray.Dataset> Size: 70kB
Dimensions: (forecast_reference_time: 4384, index: 1)
Coordinates:
* forecast_reference_time (forecast_reference_time) datetime64[us] 35kB 20...
* index (index) int64 8B 0
Data variables:
2t (index, forecast_reference_time) float64 35kB 27...
Attributes:
Conventions: CF-1.8
institution: ECMWF