Rainfall - Climate Hazards Group InfraRed Precipitation with Station data (CHIRPS)
Products used: rainfall_chirps_monthly
Keywords: datasets; CHIRPS, climate, rainfall, monthly
This notebook demonstrates how to access and use the Monthly Climate Hazards Group InfraRed Precipitation with Station data (CHIRPS) from the DE Africa Open Data Cube.
For offical information on this dataset, see CHIRPS. The abstract from this documentation is copied below:
Estimating rainfall variations in space and time is a key aspect of drought early warning and environmental monitoring. An evolving drier-than-normal season must be placed in a historical context so that the severity of rainfall deficits can be quickly evaluated. However, estimates derived from satellite data provide areal averages that suffer from biases due to complex terrain, which often underestimate the intensity of extreme precipitation events. Conversely, precipitation grids produced from station data suffer in more rural regions where there are less rain-gauge stations. CHIRPS was created in collaboration with scientists at the USGS Earth Resources Observation and Science (EROS) Center in order to deliver complete, reliable, up-to-date data sets for a number of early warning objectives, like trend analysis and seasonal drought monitoring.
The current CHIRPS dataset that is accessible from DE Africa’s platforms is the
CHIRPS-2.0 Africa Monthly dataset, copied from here, converted to cloud-opitmized geotiffs, and indexed into DE Africa’s Open-Data-Cube.
Datacube product name:
Measurement Type: Monthly Atmospheric Precipitation
Precipitation Units: Total mm/month
Spatial resolution: 0.05 degrees, approximately 5.55 km
In this notebook we will load CHIRPS data using
dc.load() to return a time series of datasets.
Topics covered include: 1. Inspecting the monthly CHIRPS product and measurements available in the datacube 2. Using the native
dc.load() function to load CHIRPS data 3. Facet plotting the CHIRPS datasets 4. Conduct a simple analysis workflow: finding the long-term monthly mean rainfall
To run this analysis, run all the cells in the notebook, starting with the “Load packages” cell.
Import Python packages that are used for the analysis.
%matplotlib inline import datacube from matplotlib import pyplot as plt from deafrica_tools.plotting import display_map
/env/lib/python3.8/site-packages/geopandas/_compat.py:106: UserWarning: The Shapely GEOS version (3.8.0-CAPI-1.13.1 ) is incompatible with the GEOS version PyGEOS was compiled with (3.9.1-CAPI-1.14.2). Conversions between both will be slow. warnings.warn(
Connect to the datacube
dc = datacube.Datacube(app="rainfall_chirps")
This section defines the analysis parameters, including
lat, lon, buffer: center lat/lon and analysis window size for the area of interest
time_period: time period to be investigated
output_crs: projection for loading data; output resolution is not defined so different resolutions can be used for Landsat and Sentinel-2
The default location cover all of Nigeria
lat, lon = 9.4707, 8.3899 buffer_lat, buffer_lon = 6, 6 time_period = ('2020') output_crs = 'epsg:6933' #join lat,lon,buffer to get bounding box lon_range = (lon - buffer_lon, lon + buffer_lon) lat_range = (lat + buffer_lat, lat - buffer_lat)
View the selected location
The next cell will display the selected area on an interactive map. Feel free to zoom in and out to get a better understanding of the area you’ll be analysing. Clicking on any point of the map will reveal the latitude and longitude coordinates of that point.
Available products and measurements
We can use datacube’s
list_products functionality to inspect the CHIRPS rainfall datasets available in the datacube. The table below shows the product names that we will use to load the data and a brief description of the data
|rainfall_chirps_monthly||rainfall_chirps_monthly||Rainfall Estimates from Rain Gauge and Satelli...||None||EPSG:4326||(-0.05000000074505806, 0.05000000074505806)|
We can further inspect the data available for CHIRPS using datacube’s
list_measurements functionality. The table below lists each of the measurements available in the data.
measurements = dc.list_measurements() measurements.loc["rainfall_chirps_monthly"]
Load CHIRPS data using
Now that we know what products and measurements are available for the products, we can load data from the datacube using
In the first example below, we will load CHIRPS data for region covering Nigeria
Note: For a more general discussion of how to load data using the datacube, refer to the Introduction to loading data notebook.
ds_rf = dc.load(product='rainfall_chirps_monthly', time='2020', y = lat_range, x = lon_range, resolution=(-5000, 5000), output_crs=output_crs) print(ds_rf)
<xarray.Dataset> Dimensions: (time: 12, x: 232, y: 303) Coordinates: * time (time) datetime64[ns] 2020-01-16T11:59:59.500000 ... 2020-12... * y (y) float64 1.952e+06 1.948e+06 ... 4.475e+05 4.425e+05 * x (x) float64 2.325e+05 2.375e+05 ... 1.382e+06 1.388e+06 spatial_ref int32 6933 Data variables: rainfall (time, y, x) float32 0.0 0.0 0.0 ... 79.18779 76.52623 79.77302 Attributes: crs: epsg:6933 grid_mapping: spatial_ref
Plotting CHIRPS Monthly Rainfall
Let’s facet plot the time-series to see the total rainfall each month during 2020 over Nigeria.
# set -9999 no-data values to NaN ds_rf = ds_rf.where(ds_rf !=-9999.) #facet plot rainfall ds_rf['rainfall'].plot.imshow(col='time', col_wrap=6, cmap='YlGnBu', label=False);
Example application: finding the monthly mean rainfall over a region
The following section will demonstrate a simple analysis workflow based on CHIRPS rainfall. We will use a 10-year time-series of rainfall over Nigeria to find the long-term monthly mean rainfall total.
First we will load the data, the parameters here are the same as the example above only we’ve increased to time-range from one year to 10 years.
ds_rf = dc.load( product="rainfall_chirps_monthly", time=('2010', '2010'), y=lat_range, x=lon_range, resolution=(-5000, 5000), output_crs=output_crs, ) print(ds_rf)
<xarray.Dataset> Dimensions: (time: 12, x: 232, y: 303) Coordinates: * time (time) datetime64[ns] 2010-01-16T11:59:59.500000 ... 2010-12... * y (y) float64 1.952e+06 1.948e+06 ... 4.475e+05 4.425e+05 * x (x) float64 2.325e+05 2.375e+05 ... 1.382e+06 1.388e+06 spatial_ref int32 6933 Data variables: rainfall (time, y, x) float32 0.0 0.0 0.0 ... 47.229477 51.054344 Attributes: crs: epsg:6933 grid_mapping: spatial_ref
Find the long-term monthly mean rainfall
We find the mean rainfall across the region (
ds_rf.mean(['x', 'y'])), then we group all the same months together and find the mean of the all the January’s, February’s etc. (
groupby('time.month').mean()). Lastly we convert the result to a pandas dataframe (
.drop('spatial_ref').to_dataframe()) to faciliate the plotting of a bar-chart
# set -9999 no-data values to NaN ds_rf = ds_rf.where(ds_rf !=-9999.) #find the mean ds_rf_mean = ds_rf.mean(['x', 'y']).groupby('time.month').mean().drop('spatial_ref').to_dataframe() ds_rf_mean.head()
Plot the result
ds_rf_mean.plot.bar(figsize=(17,5)) plt.title('Average monthly rainfall 2010-2020') plt.ylabel('Rainfall (mm/month)');
Contact: If you need assistance, please post a question on the Open Data Cube Slack channel or on the GIS Stack Exchange using the
open-data-cube tag (you can view previously asked questions here). If you would like to report an issue with this notebook, you can file one on
Compatible datacube version:
from datetime import datetime datetime.today().strftime('%Y-%m-%d')