Skip to main content

topocorr

Tests License: MIT

Is a mountain trend real, or is it the sun? topocorr tests Landsat and Sentinel-2 time series for illumination artefacts on slopes and corrects them consistently through time, in Google Earth Engine.

On steep terrain the reflectance of a pixel depends on how directly the sun lights it. That illumination changes between acquisitions with the season, with orbit drift (Landsat 5 and 7) and with each sensor switch, so a vegetation index can show greening, browning or a break that comes from geometry, not from the vegetation. topocorr computes the illumination of every pixel and acquisition from the DEM and the image's sun angles, and:

  • flags cast shadow, self-shadow, low illumination and very steep slopes;
  • applies the standard corrections (cosine, C, SCS+C), fitted image by image;
  • fits a stack model once per site: the C coefficient as a smooth function of solar zenith, per band and stratum (land cover x slope class), so no image gets its own noisy coefficient;
  • splits an observed index trend into its illumination parts (diagnose): the drift artefact, the trend that the changing illumination itself creates (orbit drift, sensor switches), and the total illumination effect, the difference between the raw and the illumination-corrected trend, which also includes a real trend scaled by the pixel's mean illumination.
import ee
import topocorr

ee.Initialize(project="my-project")
aoi = ee.Geometry.Rectangle([72.44, 35.41, 72.71, 35.64])  # upper Swat, Pakistan
oli = topocorr.collection("L8", aoi, "2013-01-01", "2026-01-01", max_cloud=30)

# Image by image; c is fitted on tree cover (ESA WorldCover 2021) unless fit_mask says otherwise
corrected = topocorr.correct(oli, method="scsc", region=aoi)

# Stack model: c(solar zenith) per band and stratum, fitted once (one sensor family per fit).
# "worldcover-density" splits tree cover by canopy density (Hansen tree cover in 2000).
model = topocorr.fit(oli, strata="worldcover-density", region=aoi, cache="swat_l8_fit.json")
print(model.summary())
model.to_json("swat_l8_model.json")
stack_corrected = topocorr.correct(oli, model)  # scsc-stack (default); or "c-stack", "se-stack"

flags = topocorr.masks(oli)  # cos_i, cast_shadow, self_shadow, low_illumination, steep

# Ratio indices only from bands corrected together: ndvi_mixed = 1 where nir and red were not
ndvi = topocorr.normalized_difference(stack_corrected, "nir", "red", "ndvi")

# Is the NDVI trend real or illumination? Drift artefact, total effect and risk class per pixel
risk = topocorr.diagnose(oli, model, index="ndvi")

Comparing methods. compare runs in two steps, so the Earth Engine cost does not grow with the number of methods: one batch export of the raw data at fixed points, then every method and measure locally in NumPy.

# Step 1 (Earth Engine): two Export.table tasks to the Drive folder "topocorr_exports"
topocorr.compare_export(oli, model, region=aoi, n_points=500, manifest="swat_compare.json")
# Step 2 (local): when both tasks are done, download the two CSV files next to the manifest
table = topocorr.compare("swat_compare.json")  # one row per method

For one 24 km Landsat 8-9 tile in the Hindu Kush (269 images, 500 points per stratum, 5,761 points) the export used 0.58 EECU-hours and wrote a 113 MB CSV; compare then took about 30 s. The table gives, per method, the remaining dependence of NIR on illumination, the sunlit-shaded gap, temporal noise, the share of values out of range and the predicted drift left (from the stack model): each point's illumination-only series passed through the method, and the trend that remains. It assumes that the stack model is right. The data-based checks are diagnose and the Landsat 5 test in the documentation.

Ratio indices. A band whose fit is not usable is left unchanged (in winter forest this is often red), so a corrected image can hold corrected and uncorrected bands side by side. The band tc_corrected records, per pixel, which bands were corrected. Compute NDVI, NBR and other ratio indices only from bands corrected together, or from the raw bands; never from a mix. topocorr.normalized_difference flags the pixels where the two bands differ.

Canopy density. On mountain slopes canopy density often follows aspect: dense forest on shaded slopes, open forest on sunlit ones. A fit over all forest then learns composition as well as illumination. strata="worldcover-density" splits tree cover by Hansen tree cover in 2000 (below 30, 30-50, 50-70, at least 70 %) and leaves pixels with recorded forest loss out of the fit. The density layer is from 2000.

Orbit drift: east- and west-facing slopes. Landsat 5 crossed the equator later and later between 1995 and 2007, in steps (up to about an hour; Roy et al. 2020, Qiu et al. 2021). The sun then stood higher and further towards the afternoon, so west-facing slopes were lit more directly over the years and east-facing slopes less. In uncorrected series this shows as greening on west-facing and browning on east-facing slopes. It is strongest in NIR and NIR-based indices (NIRv, EVI); NDVI cancels part of it. diagnose maps where it is a large part of the trend, and the stack correction removes it.

Which index for drift checks. Use NIRv or EVI. In NDVI the drift artefact is small, often near the noise level of an NDVI trend, so noise can halve the estimated drift share: an NDVI "medium" can be a real artefact. On synthetic series with known truth (real terrain, dates and sun angles of two Landsat 5 test tiles), pixels whose true drift share was at least 0.7 were classed high in 99.6-100 % of cases for NIRv but in 80-90 % for NDVI (the rest medium).

Validation. Validated on synthetic data with known truth and on real Landsat time series at mountain forest sites on five continents; full results in a forthcoming paper. A summary is on the Validation page of the documentation.

Near the equator. Where the sun is north of the tile in some images and south of it in others (model.sun_both_sides), one c(zenith) curve cannot follow per-image c, and scsc-stack would bias trends on east- and west-facing slopes. correct then warns and uses per-image SCS+C (per-image C for c-stack). diagnose warns too and sets the property tc_sun_both_sides.

Sensors: Landsat 5, 7, 8 and 9 Collection 2 Level 2 and Sentinel-2 L2A. Default DEM: Copernicus GLO-30.

Status

Version 0.1.0: collection, masks, fit (stack model), correct (cosine, C, SCS+C per image; SCS+C, C and statistical-empirical with the stack model), diagnose and compare, validated for Landsat 5, 7, 8 and 9. Sentinel-2 validation and break checks at sensor switches follow in 0.2. Documentation: https://kmkamilkhel.github.io/topocorr/

Installation

pip install topocorr

topocorr needs a Google Earth Engine account and a Cloud project registered for Earth Engine (earthengine authenticate).

References

  • Qiu, S., Zhu, Z., Shang, R., Crawford, C. J. (2021). Can Landsat 7 preserve its science capability with a drifting orbit? Science of Remote Sensing 4, 100026. https://doi.org/10.1016/j.srs.2021.100026
  • Roy, D. P., Li, Z., Zhang, H. K., Huang, H. (2020). A conterminous United States analysis of the impact of Landsat 5 orbit drift on the temporal consistency of Landsat 5 Thematic Mapper data. Remote Sensing of Environment 240, 111701. https://doi.org/10.1016/j.rse.2020.111701

License

MIT. See LICENSE.

Metadata

Release files for topocorr 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for topocorr 0.1.0
File Size Uploaded Provenance Actions
topocorr-0.1.0.tar.gz 78.3 kB With provenance Details for topocorr-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for topocorr 0.1.0
File Interpreter ABI Platform Actions
topocorr-0.1.0-py3-none-any.whl Python 3 none any Details for topocorr-0.1.0-py3-none-any.whl

Total release size: 136.4 kB

Release files / topocorr-0.1.0.tar.gz

Download URL topocorr-0.1.0.tar.gz
Size 78.3 kB
Tags Source
SHA-256 checksum
How to use checksums
52e6878300c33f91882891bdd6c2887d2d558699ab83b676f408064ffd08e5e3
BLAKE2b-256 checksum
How to use checksums
8e7428e74e285c72b5584901d32816ccbc2c1ff795e778b66f31c4b9bc18f93e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 13, 2026.

Transparency log

Release files / topocorr-0.1.0-py3-none-any.whl

Download URL topocorr-0.1.0-py3-none-any.whl
Size 58.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7624b5b61e565321c4e20c86cfb36451867c0ffd5bdf559438aaad8a7111a7b4
BLAKE2b-256 checksum
How to use checksums
53b3a36604368e898a4359670faa899da37f0ee82e68139ee30226ea9687a688
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 13, 2026.

Transparency log

Security for topocorr 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for topocorr-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 13, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page