deafrica_tools.load_era5

Functions to retrieve ERA5 gridded climate data.

Updated Apr 2020 to directly access Zarr format data in PDS

Pervious code for downloading and loading netcdf adpated 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 Africa 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 https://github.com/digitalearthafrica/deafrica-sandbox-notebooks/issues

Functions

era5_area_crop(ds, lat, lon)

Crop a dataset containing EAR5 variables to a location.

era5_area_nearest(ds, lat, lon)

Crop a dataset containing EAR5 variables to a location.

get_era5_daily(var, date_from_arg[, …])

Download and return an ERA5 variable for a defined time window.

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

Download and return an ERA5 variable for a defined time window.

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

Returns a ERA5 variable for a selected location and time window.

deafrica_tools.load_era5.era5_area_crop(ds, lat, lon)

Crop a dataset containing EAR5 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

Return type

An xarray dataset containing ERA5 variables for the selected location.

deafrica_tools.load_era5.era5_area_nearest(ds, lat, lon)

Crop a dataset containing EAR5 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.

Returns

Return type

An xarray dataset containing ERA5 variables for the selected location.

deafrica_tools.load_era5.get_era5_daily(var, date_from_arg, date_to_arg=None, reduce_func=None, cache_dir='era5', resample='1D')

Download and return an ERA5 variable 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

Return type

A lazy-loaded xarray dataset containing an ERA5 variable for the selected time window.

deafrica_tools.load_era5.load_era5(var, lat, lon, time, reduce_func=None, resample='1D')

Download and return an ERA5 variable for a defined 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 (string or datetime object or a list or tuple of strings or datetime objects) – Used to define starting and end date dates of the time window.

  • 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.

  • resample (string) – Temporal resampling frequency to be used for xarray’s resample function. The default is ‘1D’, which is daily. Since this is applied on monthly ERA5 data, maximum resampling period is ‘1M’.

Returns

Return type

A lazy-loaded xarray dataset containing an ERA5 variable for the selected region and time window.

deafrica_tools.load_era5.load_era5_netcdf(var, lat, lon, time, grid='nearest', **kwargs)

Returns a 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

Return type

An xarray dataset containing the variable for the selected location and time window.