A comprehensive framework for detecting and quantifying intra-urban thermal anomalies in Landsat imagery using machine learning and spatial analysis
Project description
Tocantins Framework
A comprehensive Python framework for detecting and quantifying intra-urban thermal anomalies in Landsat imagery using machine learning and spatial analysis techniques.
Overview
The Tocantins Framework provides researchers and practitioners with robust tools for analyzing urban heat islands and thermal anomalies using Landsat satellite imagery. The framework implements a scientifically rigorous methodology combining statistical analysis, machine learning, and spatial morphology to produce two complementary metrics:
- Impact Score (IS): Quantifies the spatial extent and thermal significance of Extended Anomaly Zones (EAZs)
- Severity Score (SS): Quantifies the thermal intensity of anomaly cores
These metrics enable data-driven urban heat intervention planning and climate adaptation strategies.
Key Features
- Multi-Landsat Support: Works with Landsat 5, 7, 8, and 9 Level-2 Collection 2 imagery
- Flexible Band Mapping: User-defined or automatic band configuration
- Automated Processing Pipeline: End-to-end analysis from raw imagery to actionable metrics
- Machine Learning Integration: Random Forest-based residual analysis for robust anomaly detection
- Spatial Coherence: Morphological operations ensure spatially meaningful anomaly delineation
- Standardized Metrics: Reproducible, comparable thermal anomaly quantification
- Configurable Parameters: Customizable for different urban contexts
- Scientific Rigor: Implements peer-reviewed methodologies with full transparency
Installation
From PyPI (Recommended)
pip install tocantins-framework
From Source
git clone https://github.com/EcoAcao-Brasil/tocantins-framework
cd Tocantins-Framework
pip install -e .
Development Installation
pip install -e ".[dev]"
Quick Start
Landsat 8/9 (Default)
from tocantins_framework import calculate_tocantins_framework
# Run complete analysis on Landsat 8/9 imagery
calculator = calculate_tocantins_framework(
tif_path="path/to/LC08_scene.tif",
output_dir="results"
)
# Access results
feature_set = calculator.get_feature_set()
print(feature_set[['Anomaly_ID', 'Type', 'IS', 'SS']])
Landsat 5/7 (Custom Mapping)
from tocantins_framework import calculate_tocantins_framework
# Define Landsat 5 band mapping
l5_mapping = {
'blue': 'SR_B1',
'green': 'SR_B2',
'red': 'SR_B3',
'nir': 'SR_B4',
'swir1': 'SR_B5',
'swir2': 'SR_B7',
'thermal': 'ST_B6',
'qa_pixel': 'QA_PIXEL'
}
# Run analysis with custom band mapping
calculator = calculate_tocantins_framework(
tif_path="path/to/LT05_scene.tif",
band_mapping=l5_mapping,
output_dir="results"
)
Advanced Configuration
from tocantins_framework import TocantinsFrameworkCalculator
# Configure custom parameters
spatial_params = {
'min_anomaly_size': 5,
'agglutination_distance': 3,
'connectivity': 2
}
rf_params = {
'n_estimators': 300,
'max_depth': 30,
'random_state': 42
}
# Initialize with custom configuration
calculator = TocantinsFrameworkCalculator(
k_threshold=1.5,
spatial_params=spatial_params,
rf_params=rf_params
)
# Run analysis
success = calculator.run_complete_analysis(
tif_path="path/to/landsat_scene.tif",
output_dir="results",
save_results=True
)
Input Data Requirements
Supported Satellites
- Landsat 8/9: Works out-of-the-box (default configuration)
- Landsat 5/7: Requires custom band mapping
Data Format
Landsat Level-2 Collection 2 GeoTIFF files containing:
- Surface Reflectance bands (Blue, Green, Red, NIR, SWIR1, SWIR2)
- Surface Temperature band (Thermal)
- Quality Assessment band (QA_PIXEL)
Data Sources
Band Mapping Reference
Landsat 8/9 (Default)
No configuration needed - automatic detection.
Landsat 5
{
'blue': 'SR_B1', 'green': 'SR_B2', 'red': 'SR_B3',
'nir': 'SR_B4', 'swir1': 'SR_B5', 'swir2': 'SR_B7',
'thermal': 'ST_B6', 'qa_pixel': 'QA_PIXEL'
}
Landsat 7
{
'blue': 'SR_B1', 'green': 'SR_B2', 'red': 'SR_B3',
'nir': 'SR_B4', 'swir1': 'SR_B5', 'swir2': 'SR_B7',
'thermal': 'ST_B6', 'qa_pixel': 'QA_PIXEL'
}
Output Files
CSV Files
ml_features.csv: Complete feature set with IS and SS metricsimpact_scores.csv: Simplified Impact Scoresimpact_scores_detailed.csv: Detailed Impact Score breakdownseverity_scores.csv: Core-level Severity Scores
GeoTIFF Files
anomaly_classification.tif: Spatial classification map- 0 = Background
- 1 = Cold EAZ
- 2 = Hot EAZ
- 3 = Cold Core
- 4 = Hot Core
lst_residuals.tif: Land Surface Temperature residuals
Examples
See the examples/ directory for detailed usage examples:
basic_landsat8_analysis.py- Simple Landsat 8/9 analysislandsat5_custom_mapping.py- Landsat 5 with custom bandsadvanced_configuration.py- Full parameter customization
Methodology
Processing Pipeline
-
Preprocessing
- Band extraction and validation
- LST conversion (Kelvin to Celsius)
- Spectral index calculation (NDVI, NDWI, NDBI, NDBSI)
-
Statistical Anomaly Detection
- Percentile-based threshold identification (2nd and 98th percentiles)
- Initial hot/cold anomaly classification
-
Machine Learning Refinement
- Random Forest regression on non-anomalous pixels
- Residual calculation (observed - predicted LST)
- Core anomaly refinement using residual thresholds
-
Spatial Morphology
- Core unification through morphological operations
- Extended Anomaly Zone (EAZ) growth
- Spatial coherence enforcement
-
Metrics Calculation
- Impact Score: IS = sign(ΔT) × log(1 + severity × area × continuity)
- Severity Score: SS = sign(ΔT) × log(1 + thermal_intensity × area)
Configuration Parameters
Spatial Parameters
spatial_params = {
'min_anomaly_size': 1, # Minimum pixels for valid anomaly
'agglutination_distance': 4, # Dilation radius for core merging
'morphology_kernel_size': 3, # Morphological operation kernel size
'connectivity': 2 # Pixel connectivity (1=4-conn, 2=8-conn)
}
Detection Parameters
k_threshold = 1.5 # Residual threshold multiplier (k × σ_residual)
Random Forest Parameters
rf_params = {
'n_estimators': 200, # Number of trees
'max_depth': 25, # Maximum tree depth
'min_samples_split': 8, # Minimum samples to split node
'min_samples_leaf': 4, # Minimum samples per leaf
'max_features': 'sqrt', # Features per split
'random_state': 42, # Reproducibility seed
'n_jobs': -1 # Parallel processing
}
API Reference
Main Classes
TocantinsFrameworkCalculator: Main orchestrator for complete analysisLandsatPreprocessor: Imagery loading and preprocessingAnomalyDetector: Statistical and ML-based anomaly detectionMorphologyProcessor: Spatial morphological operationsMetricsCalculator: Impact and Severity Score calculationResultsWriter: Output file generation
Convenience Functions
calculate_tocantins_framework(): One-line complete analysis
Contributing
We welcome contributions from the scientific community! Please see CONTRIBUTING.md for guidelines.
Citation
If you use this framework in your research, please cite:
@software{tocantins_framework,
author = {Borges, Isaque Carvalho},
title = {Tocantins Framework: A Python Library for Assessment of Intra-Urban Thermal Anomaly},
year = {2025},
publisher = {EcoAção Brasil},
url = {https://github.com/EcoAcao-Brasil/tocantins-framework}
}
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
Developed by EcoAção Brasil to support climate resilience research and urban planning initiatives.
Support
- Issues: https://github.com/EcoAcao-Brasil/tocantins-framework/issues
- Email: isaque@ecoacaobrasil.org
Changelog
See CHANGELOG.md for version history and updates.
Keywords: urban heat island, thermal anomaly detection, Landsat, remote sensing, machine learning, spatial analysis, climate adaptation
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tocantins_framework-1.1.0.tar.gz.
File metadata
- Download URL: tocantins_framework-1.1.0.tar.gz
- Upload date:
- Size: 30.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2acc964cb07a70ec5e55b9b040e37bba86da72284bd04199bd57675ee05abcae
|
|
| MD5 |
7cc6fda4711057aaa7d61e29698f3249
|
|
| BLAKE2b-256 |
d645b9ac7982a1ced7c784cce83a35c881bef46532c4e6ca51f2465062a58151
|
Provenance
The following attestation bundles were made for tocantins_framework-1.1.0.tar.gz:
Publisher:
publish.yml on EcoAcao-Brasil/tocantins-framework
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tocantins_framework-1.1.0.tar.gz -
Subject digest:
2acc964cb07a70ec5e55b9b040e37bba86da72284bd04199bd57675ee05abcae - Sigstore transparency entry: 829790444
- Sigstore integration time:
-
Permalink:
EcoAcao-Brasil/tocantins-framework@8b76ef4e86c2da15ba2b606292efc83efabedb4c -
Branch / Tag:
refs/tags/v1.1.0 - Owner: https://github.com/EcoAcao-Brasil
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@8b76ef4e86c2da15ba2b606292efc83efabedb4c -
Trigger Event:
release
-
Statement type:
File details
Details for the file tocantins_framework-1.1.0-py3-none-any.whl.
File metadata
- Download URL: tocantins_framework-1.1.0-py3-none-any.whl
- Upload date:
- Size: 26.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3d61bb729425dffd0a7e711182ebcf7da31c0e882a4df0d0edbbd06a7209fe56
|
|
| MD5 |
e714cb3b28adca2820e18de1978f381f
|
|
| BLAKE2b-256 |
5231bc21f6118c783d4f6112bb2fbd66aec11fd7d7d7a5b848b7843fdb791a98
|
Provenance
The following attestation bundles were made for tocantins_framework-1.1.0-py3-none-any.whl:
Publisher:
publish.yml on EcoAcao-Brasil/tocantins-framework
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tocantins_framework-1.1.0-py3-none-any.whl -
Subject digest:
3d61bb729425dffd0a7e711182ebcf7da31c0e882a4df0d0edbbd06a7209fe56 - Sigstore transparency entry: 829790446
- Sigstore integration time:
-
Permalink:
EcoAcao-Brasil/tocantins-framework@8b76ef4e86c2da15ba2b606292efc83efabedb4c -
Branch / Tag:
refs/tags/v1.1.0 - Owner: https://github.com/EcoAcao-Brasil
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@8b76ef4e86c2da15ba2b606292efc83efabedb4c -
Trigger Event:
release
-
Statement type: