CHIRPS v3.0: quasi-global rainfall, 1981 to present, 0.05 degree (monthly and annual): sample notebook

A worked notebook for CHIRPS v3.0: quasi-global rainfall, 1981 to present, 0.05 degree (monthly and annual), with 5 code cells and the output each one printed. On Scigantic it opens in a hosted JupyterLab with the dataset already mounted, so nothing is downloaded first.

Provider
Climate Hazards Center, UC Santa Barbara
License
CC-BY-4.0
Size
597 objects, 17.56 GB (16.35 GiB) in chirps-v3.0/
Format
TIFF (in sampled files)
Stored at
Amazon S3, s3://scigantic-chc-climate/chirps-v3.0 (us-east-1)
Access
Free and public. No account with the data provider is needed.
DOI
10.15780/G2JQ0P

The notebook

Start here. Click the grey cell below and press Shift+Enter. It reads one year of rainfall straight off the mounted archive and draws it, so in a few seconds you will be looking at where it rained on Earth's land in 2025.

Change YEAR to anything from 1981 to 2025 and run it again.

# Start here: click this cell, press Shift+Enter.
YEAR = 2025                    # any year from 1981 to 2025

import os
from pathlib import Path
import numpy as np
import rasterio
import matplotlib.pyplot as plt
from matplotlib.colors import LogNorm
from matplotlib_inline.backend_inline import set_matplotlib_formats
set_matplotlib_formats("jpeg", pil_kwargs={"quality": 80})
plt.rcParams["figure.dpi"] = 72

ARCHIVE = Path(os.environ.get("SCIGANTIC_MOUNT_PATH", Path.home() / "archive"))

with rasterio.open(ARCHIVE / f"annual/tifs/chirps-v3.0.{YEAR}.tif") as src:
    rain = src.read(1)
    transform = src.transform
rain = np.where(rain < 0, np.nan, rain)          # the ocean is stored as -9999

row, col = np.unravel_index(np.nanargmax(rain), rain.shape)
lon, lat = transform * (col + 0.5, row + 0.5)
print(f"{YEAR}: {np.isfinite(rain).sum():,} land cells of 0.05 degrees (about 5 km), 60S to 60N")
print(f"median land cell: {np.nanmedian(rain):,.0f} mm of rain over the year")
print(f"wettest cell: {np.nanmax(rain):,.0f} mm, at {lat:.2f}, {lon:.2f}")

fig, ax = plt.subplots(figsize=(12, 4.4))
im = ax.imshow(rain[::4, ::4], extent=(-180, 180, -60, 60), cmap="YlGnBu",
               norm=LogNorm(vmin=50, vmax=5000), interpolation="nearest")
ax.set_facecolor("#e9eef2")
ax.set_title(f"CHIRPS v3.0 rainfall over land, {YEAR} (mm per year)", loc="left")
ax.set_xticks([]); ax.set_yticks([])
cb = fig.colorbar(im, ax=ax, shrink=0.8, pad=0.01)
cb.set_ticks([100, 300, 1000, 3000], labels=["100", "300", "1,000", "3,000"])
fig.tight_layout()
plt.show()

CHIRPS v3.0: rainfall over land, 1981 to now

CHIRPS (Climate Hazards Center InfraRed Precipitation with Stations) blends satellite cloud-top temperatures with rain-gauge records into one grid of rainfall over land, every 0.05 degrees from 60S to 60N, from January 1981 to a few weeks ago. It was built for drought early warning (it is what FEWS NET uses to call a failed season in East Africa), which is why it goes back so far and is so consistent through time.

Version 3.0 uses about four times as many station sources as v2.0 and corrects gauges for wind undercatch, so it reads wetter than v2.0 everywhere. Do not splice the two together. The v2.0 archive is on Scigantic too if you need to compare.

What is in this mount:

folderwhatfilesunits
annual/tifs/one GeoTIFF per year1981 to 2025mm per year
monthly/cogs/one Cloud Optimized GeoTIFF per month1981.01 to the latest monthmm per month

Every file is the same 7200 x 2400 grid in plain longitude/latitude (EPSG:4326). This is a byte-for-byte mirror of the Climate Hazards Center's files, refreshed monthly. It exists because the origin server bans clients that make many requests. CC BY 4.0: cite Funk et al. 2026, *Scientific Data* 13:718, doi:10.1038/s41597-026-07096-4.

1. The one thing that silently breaks every average

The ocean is stored as -9999, and the files do not declare that as a missing value. So rasterio, xarray and GDAL all hand you -9999 as if it were real rain. Two thirds of the grid is ocean, so any average you take without masking comes out large and negative, and a spatial mean, a resample or a regrid that mixes ocean into land cells comes out quietly too low.

The second trap is smaller: the grid is in degrees, and a degree of longitude near 60N covers half the ground it covers at the equator. A plain mean over cells over-weights the far north and south. Weight by the cosine of latitude.

with rasterio.open(ARCHIVE / f"annual/tifs/chirps-v3.0.{YEAR}.tif") as src:
    raw = src.read(1)
    print("declared nodata value:", src.nodata)

print(f"naive mean of every cell     : {raw.mean():>9,.0f} mm")
land = raw >= 0
print(f"mean of land cells only      : {raw[land].mean():>9,.0f} mm")

lat_centres = 60 - 0.05 * (np.arange(raw.shape[0]) + 0.5)
w = np.broadcast_to(np.cos(np.radians(lat_centres))[:, None], raw.shape)
print(f"area-weighted land mean      : {np.average(raw[land], weights=w[land]):>9,.0f} mm")
print()
print("Mask values below zero before doing anything else. Weight by cos(latitude)")
print("whenever you average over an area.")

Output:

declared nodata value: None
naive mean of every cell     :    -6,944 mm
mean of land cells only      :       906 mm
area-weighted land mean      :       965 mm

Mask values below zero before doing anything else. Weight by cos(latitude)
whenever you average over an area.

2. A month, cheaply

The monthly files are Cloud Optimized GeoTIFFs: the data is cut into 512 x 512 tiles and each file carries smaller copies of itself (overviews) at 1/2, 1/4, 1/8 and 1/16 resolution. Ask rasterio for a smaller output shape and it reads the matching overview instead of the whole file, which over a network mount is the difference between a fraction of a second and many. That makes it cheap to look at any month before deciding what to read at full resolution.

import time

months = sorted(p.name for p in (ARCHIVE / "monthly/cogs").iterdir() if p.suffix == ".cog")
print(f"{len(months)} monthly files, {months[0]} to {months[-1]}")

MONTH = months[-1][len("chirps-v3.0."):-len(".cog")]   # the latest month; or e.g. "2015.10"

t0 = time.perf_counter()
with rasterio.open(ARCHIVE / f"monthly/cogs/chirps-v3.0.{MONTH}.cog") as src:
    print("overview factors in the file:", src.overviews(1))
    small = src.read(1, out_shape=(src.height // 8, src.width // 8))
print(f"read {MONTH} at 1/8 resolution, {small.shape[1]} x {small.shape[0]}, "
      f"in {time.perf_counter() - t0:.2f} s")

small = np.where(small < 0, np.nan, small)
fig, ax = plt.subplots(figsize=(12, 4.4))
im = ax.imshow(small, extent=(-180, 180, -60, 60), cmap="YlGnBu",
               norm=LogNorm(vmin=5, vmax=800), interpolation="nearest")
ax.set_facecolor("#e9eef2")
ax.set_title(f"rainfall over land, {MONTH} (mm in the month)", loc="left")
ax.set_xticks([]); ax.set_yticks([])
cb = fig.colorbar(im, ax=ax, shrink=0.8, pad=0.01)
cb.set_ticks([10, 30, 100, 300], labels=["10", "30", "100", "300"])
fig.tight_layout()
plt.show()

Output:

121 monthly files, chirps-v3.0.2016.09.cog to chirps-v3.0.2026.09.cog
overview factors in the file: [2, 4, 8, 16]
read 2026.09 at 1/8 resolution, 900 x 300, in 0.01 s

3. Rain at one place, month by month

To follow one place through time you only need one pixel from each file. A window read pulls just the tile that holds it, so the cost is the number of files, not their size. Through the mount each file open takes around half a second, so the cell below reads them in parallel.

Nairobi is the default because it shows something a yearly total hides: two rainy seasons, the long rains around April and the short rains around November. Change PLACE to anywhere on land between 60S and 60N, and YEARS to go further back (the files start in 1981).

from concurrent.futures import ThreadPoolExecutor
from rasterio.windows import Window
import pandas as pd

PLACE = ("Nairobi", -1.29, 36.82)    # name, latitude, longitude
YEARS = 10                            # how many years back from the latest month

name, plat, plon = PLACE
files = months[-12 * YEARS:]
with rasterio.open(ARCHIVE / "monthly/cogs" / files[0]) as src:
    prow, pcol = src.index(plon, plat)

def one_pixel(fname):
    with rasterio.open(ARCHIVE / "monthly/cogs" / fname) as src:
        return float(src.read(1, window=Window(pcol, prow, 1, 1))[0, 0])

t0 = time.perf_counter()
with ThreadPoolExecutor(16) as pool:
    values = list(pool.map(one_pixel, files))
print(f"read {len(files)} months at {name} in {time.perf_counter() - t0:.1f} s")

series = pd.Series(values, index=pd.PeriodIndex([f[12:19].replace(".", "-") for f in files], freq="M"))
if (series < 0).any():
    raise ValueError(f"{PLACE} falls on an ocean cell (-9999). Move it onto land.")
clim = series.groupby(series.index.month).mean()
by_year = series.groupby(series.index.year).agg(["sum", "count"])
full = by_year[by_year["count"] == 12]["sum"]
print(f"mean year at {name}: {full.mean():,.0f} mm ({len(full)} complete years)")
print(f"wettest month on average: {pd.Timestamp(2000, clim.idxmax(), 1):%B} ({clim.max():.0f} mm)")

fig, (a1, a2) = plt.subplots(1, 2, figsize=(12, 3.6), gridspec_kw={"width_ratios": [1, 2.2]})
a1.bar(range(1, 13), clim.values, color="#2b7bb9")
a1.set_xticks(range(1, 13), list("JFMAMJJASOND"))
a1.set_title(f"{name}: average month, last {YEARS} years (mm)", loc="left", fontsize=10)
a2.plot(series.index.to_timestamp(), series.values, color="#2b7bb9", linewidth=1)
a2.set_title(f"{name}: every month (mm)", loc="left", fontsize=10)
for a in (a1, a2):
    a.spines[["top", "right"]].set_visible(False)
fig.tight_layout()
plt.show()

Output:

read 120 months at Nairobi in 0.3 s
mean year at Nairobi: 1,161 mm (9 complete years)
wettest month on average: April (286 mm)

4. Was this month unusual?

Rainfall only means something against what is normal for that place and that time of year. The cell below compares one month with the same calendar month in the years before it, as a percentage of the average. Brown is drier than usual, green is wetter. Places that barely see rain in that month are left blank, because a few millimetres either way would show as a huge percentage.

The baseline here is the previous ten years so the cell stays quick. The standard climate normal is the 30 years 1991 to 2020, and those files are all in the mount: set BASE_YEARS to range(1991, 2021) for a result you could quote.

import warnings
from matplotlib.colors import TwoSlopeNorm

TARGET = MONTH                                     # e.g. "2015.10"
ty, tm = TARGET.split(".")
BASE_YEARS = range(int(ty) - 10, int(ty))          # set range(1991, 2021) for the WMO normal

def month_small(stamp, factor=4):
    with rasterio.open(ARCHIVE / f"monthly/cogs/chirps-v3.0.{stamp}.cog") as src:
        a = src.read(1, out_shape=(src.height // factor, src.width // factor))
    return np.where(a < 0, np.nan, a)

t0 = time.perf_counter()
with ThreadPoolExecutor(12) as pool:
    base = np.stack(list(pool.map(month_small, [f"{y}.{tm}" for y in BASE_YEARS])))
now = month_small(TARGET)
print(f"read {len(base) + 1} months at 1/4 resolution in {time.perf_counter() - t0:.1f} s")

with np.errstate(divide="ignore", invalid="ignore"), warnings.catch_warnings():
    warnings.simplefilter("ignore", RuntimeWarning)              # all-NaN ocean columns
    normal = np.nanmean(base, axis=0)
    pct = np.where(normal >= 10, 100 * now / normal, np.nan)  # skip places with < 10 mm normal
print(f"{TARGET} against {BASE_YEARS.start}-{BASE_YEARS.stop - 1}: "
      f"{np.nanmean(pct < 50):.0%} of comparable land had under half its usual rain, "
      f"{np.nanmean(pct > 150):.0%} had over one and a half times")

fig, ax = plt.subplots(figsize=(12, 4.4))
im = ax.imshow(np.clip(pct, 0, 300), extent=(-180, 180, -60, 60), cmap="BrBG",
               norm=TwoSlopeNorm(vmin=0, vcenter=100, vmax=300), interpolation="nearest")
ax.set_facecolor("#e9eef2")
ax.set_title(f"{TARGET} rainfall as % of the {BASE_YEARS.start}-{BASE_YEARS.stop - 1} "
             f"average for that month", loc="left")
ax.set_xticks([]); ax.set_yticks([])
fig.colorbar(im, ax=ax, shrink=0.8, pad=0.01)
fig.tight_layout()
plt.show()

Output:

read 11 months at 1/4 resolution in 0.1 s
2026.09 against 2016-2025: 4% of comparable land had under half its usual rain, 3% had over one and a half times

Where to go from here

src.transform)` gives a window for any box; read that instead of the whole grid. The annual files are stored one row at a time, so a box read only touches the rows it spans.

long rains, June to September for the Sahel and the Indian monsoon) before comparing years.

at 1/4 resolution, or windows of them at full resolution for a region.

2025 compared with the 1991 to 2020 average across East Africa" is a good first question.

Run it

Open this notebook to run it, see the dataset page for the full description, or browse the full catalog.