dea_tools.climate

Retrieving and manipulating gridded climate data.

Adapted from scripts by Andrew Cherry and Brian Killough.

License: The code in this notebook is licensed under the Apache License, Version 2.0 (https://www.apache.org/licenses/LICENSE-2.0). Digital Earth Australia data is licensed under the Creative Commons by Attribution 4.0 license (https://creativecommons.org/licenses/by/4.0/).

Contact: If you need assistance, please post a question on the Open Data Cube Slack channel (http://slack.opendatacube.org/) or on the GIS Stack Exchange (https://gis.stackexchange.com/questions/ask?tags=open-data-cube) using the open-data-cube tag (you can view previously asked questions here: https://gis.stackexchange.com/questions/tagged/open-data-cube).

If you would like to report an issue with this script, you can file one on Github digitalearthafrica/deafrica-sandbox-notebooks#issues

Last modified: October 2020

Functions

era5_area_crop(ds, lat, lon)

Crop a dataset containing European Centre for Medium Range Weather Forecasts (ECMWF) global climate reanalysis product (ERA5) variables to a location.

era5_area_nearest(ds, lat, lon)

Crop a dataset containing European Centre for Medium Range Weather Forecasts (ECMWF) global climate reanalysis product (ERA5) variables to a location.

get_era5_daily(var, date_from_arg[, ...])

Download and return an variable from the European Centre for Medium Range Weather Forecasts (ECMWF) global climate reanalysis product (ERA5) for a defined time window.

load_era5(var, lat, lon, time[, grid])

Returns a European Centre for Medium Range Weather Forecasts (ECMWF) global climate reanalysis product (ERA5) variable for a selected location and time window.

dea_tools.climate.era5_area_crop(ds, lat, lon)[source]

Crop a dataset containing European Centre for Medium Range Weather Forecasts (ECMWF) global climate reanalysis product (ERA5) variables to a location.

The output spatial grid will either include input grid points within lat/lon boundaries or the nearest point if none is within the search location.

Parameters:
  • ds (xarray dataset) – A dataset containing ERA5 variables of interest.

  • lat (tuple or list) – Latitude range for query.

  • lon (tuple or list) – Longitude range for query.

Returns:

  • An xarray dataset containing ERA5 variables for the selected

  • location.

dea_tools.climate.era5_area_nearest(ds, lat, lon)[source]

Crop a dataset containing European Centre for Medium Range Weather Forecasts (ECMWF) global climate reanalysis product (ERA5) variables to a location.

The output spatial grid is snapped to the nearest input grid points.

Parameters:
  • ds (xarray dataset) – A dataset containing ERA5 variables of interest.

  • lat (tuple or list) – Latitude range for query.

  • lon (tuple or list) – Longitude range for query.

Return type:

An xarray dataset containing ERA5 variables for the selected location.

dea_tools.climate.get_era5_daily(var, date_from_arg, date_to_arg=None, reduce_func=None, cache_dir='era5', resample='1D')[source]

Download and return an variable from the European Centre for Medium Range Weather Forecasts (ECMWF) global climate reanalysis product (ERA5) for a defined time window.

Parameters:
  • var (string) – Name of the ERA5 climate variable to download, e.g “air_temperature_at_2_metres”

  • date_from_arg (string or datetime object) – Starting date of the time window.

  • date_to_arg (string or datetime object) – End date of the time window. If not supplied, set to be the same as starting date.

  • reduce_func (numpy function) – lets you specify a function to apply to each day’s worth of data. The default is np.mean, which computes daily average. To get a sum, use np.sum.

  • cache_dir (sting) – Path to save downloaded ERA5 data. The path will be created if not already exists. The default is ‘era5’.

  • resample (string) – Temporal resampling frequency to be used for xarray’s resample function. The default is ‘1D’, which is daily. Since ERA5 data is provided as one file per month, maximum resampling period is ‘1M’.

Returns:

  • A lazy-loaded xarray dataset containing an ERA5 variable for the

  • selected time window.

dea_tools.climate.load_era5(var, lat, lon, time, grid='nearest', **kwargs)[source]

Returns a European Centre for Medium Range Weather Forecasts (ECMWF) global climate reanalysis product (ERA5) variable for a selected location and time window.

Parameters:
  • var (string) – Name of the ERA5 climate variable to download, e.g “air_temperature_at_2_metres”

  • lat (tuple or list) – Latitude range for query.

  • lon (tuple or list) – Longitude range for query.

  • time (tuple or list) – Time range for query.

  • grid (string) – Option for output spatial gridding. The default is ‘nearest’, for which output spatial grid is snapped to the nearest ERA5 input grid points. Alternatively, output spatial grid will either include input grid points within lat/lon boundaries or the nearest point if none is within the search location.

Returns:

  • An xarray dataset containing the variable for the selected location

  • and time window.