Skip to content

EOA-team/PSPreprocessing

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PlanetScope Preprocessing

Project Description {#description}

The PlanetScope Preprocessing Pipeline is a comprehensive workflow designed to preprocess high-resolution PlanetScope satellite imagery for environmental monitoring, precision agriculture, and other remote sensing applications.

The pipeline handles:

  • Confidence Masking: Identifies and masks clouds, shadows, haze, and low-confidence pixels in PlanetScope RGB orthomosaics.
  • Coregistration: Aligns satellite images with high-resolution reference imagery (e.g., SwissImage) to correct for geometric offsets and ensure spatial consistency.
  • Empirical Line Correction (ELC): Uses Pseudo Invariant Targets (PIT) areas to calculate bandwise correction factors, standardizing image radiometry across time and improving comparability.

Table of Contents


Project Structure {#project-structure}

  • helpers/ — Helper scripts containing functions for each preprocessing step
  • config/ — Configuration file
  • main.py — Main script for the preprocessing pipeline
  • requirements_PSPreprocessing.txt — Python dependencies

Installation {#installation}

To set up the project, install the required Python packages using the provided requirements file:

pip install -r requirements_PSPreprocessing.txt

Ensure you have Python 3.8 or higher installed.


Usage {#usage}

The main script for running the preprocessing pipeline is main.py. This script allows users to selectively run specific preprocessing steps:

  1. Confidence Masking — Masks clouds, shadows, haze, and low-confidence pixels.
  2. Coregistration — Aligns images with high-resolution reference data for spatial consistency.
  3. ELC Correction — Applies elevation and radiometric corrections using PIT areas.

Steps

  1. Update the configuration:
    Edit config/config.json to specify input and output folders, as well as parameters for each preprocessing step (Confidence Masking, Coregistration, ELC).

  2. Run the pipeline:
    Execute the script from the command line:

    python main.py
  3. Select preprocessing steps:
    After running the script, you will be prompted to enter which steps to run. Enter the desired steps as a comma-separated list:

    Enter steps to run (comma-separated: confidence, coreg, elc):
    
    • confidence — Run confidence masking
    • coreg — Run coregistration
    • elc — Run ELC correction

    Example: To run confidence masking and coregistration only:

    Enter steps to run (comma-separated: confidence, coreg, elc): confidence, coreg
    

Parameters Explained — Confidence Masking

The ConfidenceMasking script applies masks for shadow, haze, cloud, and confidence layers to 8-band PlanetScope satellite images. Parameters are set in the config.json under the "confidence_masking" section.

Parameter Type Description Default / Example
input_folder string Path to the folder containing input satellite images. Each 8-band PlanetScope image (*_AnalyticMS_SR_8b_clip.tif) must have a corresponding mask file (*_udm2_clip.tif) in the same folder. "InputFolder"
output_folder string Path to the folder where masked images will be saved. If not provided, a Masked folder is created inside input_folder. "Masked"
apply_shadow boolean If true, the shadow mask (band 3 of the UDM2 file) is applied to exclude shadowed pixels. true
apply_haze boolean If true, the haze mask (band 5 of the UDM2 file) is applied to exclude hazy pixels. true
apply_cloud boolean If true, the cloud mask (band 6 of the UDM2 file) is applied to exclude cloud-covered pixels. true
confidence_threshold int Threshold for the confidence layer (band 7 of the UDM2 file). Pixels with confidence below this value are masked. Valid range: 0–100. 90

Notes:

  • Each input image (*_AnalyticMS_SR_8b_clip.tif) must have a corresponding mask (*_udm2_clip.tif) in the same folder. The script pairs them automatically.
  • Masks are combined using logical OR, so any pixel flagged by shadow, haze, cloud, or confidence threshold is excluded.
  • Masked pixels are set to 0 in all bands of the output image.
  • Output filenames are automatically suffixed with _masked.tif.

Parameters Explained — Coregistration

The Coregistration script aligns masked PlanetScope images to a high-resolution SwissImage reference. Parameters are set in the config.json under the "coregistration" section.

Parameter Type Description Default / Example
input_folder string Path to the folder containing masked PlanetScope images (*.tif). These are the images to be coregistered. "InputFolder/Masked"
swissimage_folder string Path to the folder containing SwissImage(10cm) Zarr reference files. Only tiles intersecting the PlanetScope images are used. "SwissImageFolder"
output_folder string Path to save coregistered GeoTIFF files. If not provided, a CoregFolder inside input_folder is created. "CoregFolder"
crs int EPSG code for the output GeoTIFFs. Determines the coordinate reference system of the saved images. 32632

Notes:

  • Input masked images are loaded as an xarray dataset and paired with the corresponding reference SwissImage tiles for alignment.
  • The script automatically selects the SwissImage tiles that intersect the extent of each PlanetScope image.
  • Coregistration is performed using the AROSICS package, aligning the PlanetScope images to the reference.
  • Output filenames are automatically suffixed with _coreg.tif.

Parameters Explained — ELC (Empirical Line Correction)

The ELC script calculates bandwise correction factors using PITs (Pseudo Invariant Targets) and applies them to PlanetScope images. Parameters are set in the config.json under the "ELC" section.

Parameter Type Description Example
pit_folder string Folder containing PIT KML files defining reference areas for correction. "PITFolder"
input_folder string Folder containing satellite images to be corrected (e.g., masked/coregistered GeoTIFFs). "SatelliteImagesFolder"
output_folder string Folder to save all output reports, corrected GeoTIFFs, and plots. A subfolder named <site>_ELC is automatically created. "OutputFolderELC"
plots_folder string Folder to save summary plots of correction factors, mean band values, and differences to mean corrections. "ELCPlotsFolder"

Notes:

  • The workflow extracts raster data for each PIT polygon, calculates mean values per band, computes baseline means across the timeseries, and derives correction factors.
  • PIT-specific and file-based filters ensure valid data is used (e.g., excluding files with missing or nodata values).
  • Reports include per-band mean, baseline mean, and correction factor for each image and PIT.
  • Output plots include:
    • Mean values per band across PITs
    • Band-specific correction factors
    • Difference to mean correction factors
  • Corrected TIF files are saved in the output_folder with _ELC.tif suffix.
  • Only bands with at least 2 valid PITs per timestamp are corrected to ensure reliability.

Data {#data}

The preprocessing pipeline uses imagery from the PlanetScope (SuperDove) satellites provided by Planet Labs. These are high-resolution, daily-revisit, RGB/8-band orthomosaics suitable for various Earth observation analyses.

Sources

  • PlanetScopeDownload Script: Images can be programmatically downloaded using the PlanetScopeDownload script via a Planet Labs API key.
  • Planet Labs Explorer: Alternatively, imagery can be accessed and downloaded manually through the Planet Labs Explorer platform.

Contributing {#contributing}

Thank you for your interest in contributing to the PlanetScope Preprocessing pipeline!

To maintain quality and consistency, please contact the project maintainer before submitting any changes, suggestions, or issues:
timon.boos.98@gmail.com

Thank you for your cooperation and support!


License {#license}

© 2025 Timon Boos. All rights reserved.

Permission to use, copy, modify, or distribute this code must be requested by contacting:
timon.boos.98@gmail.com


Acknowledgements {#acknowledgements}

I sincerely thank all collaborators, contributors, funding organizations, and data providers who supported this project. The coregistration script is based on code from Sélène Ledain, adapted from Sentinel-2 to PlanetScope data. Special thanks to the Earth Observation Team at Agroscope, particularly Dr. Helge Aasen, for their invaluable support.


References {#references}

  • Scheffler, D., Hollstein, A., Diedrich, H., Segl, K., and Hostert, P. (2017). AROSICS: An automated and robust open-source image co-registration software for multi-sensor satellite data. Remote Sensing, 9(7).
  • Planet Labs PBC (2024). Planet Application Program Interface: In Space for Life on Earth. https://api.planet.com
    Accessed: March 19, 2025.

About

Preprocessing Pipeline for PlanetScope data (masking, coregistration, empirical line correction)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages