Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Calculate country level aggregations by combining gridded data with geometry data

Using only the packages imported and data loaded in the first code block, produce a figure similar to the one show below.

figure1

All the information and code required to complete this task can be found in the earthkit-transforms Documentation pages.

The following code cell imports the required earthkit modules and uses earthkit-data to download the sample data. There are two data objects:

  1. era5_data is a grib file containing hourly 2m temperature data over Europe for the 1st January 2015.

  2. nuts_data is a geojson containing the country borders accroding to the Nomenclature of territorial units for statistics.

from earthkit.data.utils.testing import earthkit_remote_test_data_file

from earthkit import data as ekd
from earthkit import plots as ekp
from earthkit import transforms as ekt

# 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_temperature_europe_2015.grib") # Large file
remote_era5_file = earthkit_remote_test_data_file("era5_temperature_europe_20150101.grib")
era5_data = ekd.from_source("url", remote_era5_file)

# Use some demonstration polygons stored, this could be any url or path to geojson file
remote_nuts_url = earthkit_remote_test_data_file("NUTS_RG_60M_2021_4326_LEVL_0.geojson")
nuts_data = ekd.from_source("url", remote_nuts_url).to_geopandas()
# Insert your code here

Hints

Consider the following workflow:

  1. Optional, convert to xarray to have more control on the dimensionality of the results.

  2. Use the earthkit.transforms.spatial sub-module to calculate the country averages.

    • The time dimension should be averaged over at the same time as the spatial dimensions

    • Ensure the statistic you calculate is weighted by latitude

    • Return the result as a pandas DataFrame for simpler plotting

  3. Use earthkit.plots.geo.choropleth to create the plot