Skip to main content

Professional Python library for land use change analysis implementing the Pontius-Aldwaik intensity analysis methodology. Features factory-pattern analyzers (AnalyzerFactory/AnalyzerManager), comprehensive visualization suite (Sankey diagrams, heatmaps, spatial plots), modular architecture with core/processing/visualization modules, and complete workflow automation from raster data to publication-ready outputs.

Project description

๐ŸŒ LandUse Intensity Analysis

PyPI version Python 3.8+ License: MIT Tests

Modern Python library for comprehensive land use change analysis using clean architecture principles and the Pontius-Aldwaik intensity analysis methodology


๐Ÿš€ Quick Start

Installation

pip install landuse-intensity-analysis

Basic Usage

import landuse_intensity as lui

# Load your raster data
from landuse_intensity.processing import read_raster
data_2000, _ = read_raster("landuse_2000.tiff")
data_2010, _ = read_raster("landuse_2010.tiff")

# Create analyzer
analyzer = lui.AnalyzerFactory.create_analyzer("intensity")

# Perform analysis
results = analyzer.analyze(data_2000, data_2010)

# Generate visualizations
lui.plot_sankey(data_2000, data_2010, save_path="transition_flow.png")
lui.plot_transition_matrix_heatmap(data_2000, data_2010, save_path="matrix.png")

๐Ÿงฉ Package Architecture

The library follows clean architecture principles with modular structure:

Core Modules

from landuse_intensity import (
    AnalyzerFactory,      # Factory pattern for creating analyzers
    AnalyzerManager,      # Central management of analysis workflows
    # Core analysis functions
    transition_matrix_calculation,
    loss_gain_table,
    interval_level_analysis,
    category_level_analysis,
    transition_level_analysis,
    # Visualization functions
    plot_sankey,
    plot_transition_matrix_heatmap,
    plot_loss_gain_bar,
    plot_comprehensive_analysis,
    # Statistics and utilities
    calculate_statistics,
    export_results
)

Main Components

AnalyzerFactory

Creates different types of analyzers based on your needs:

# Create an intensity analyzer
analyzer = AnalyzerFactory.create_analyzer("intensity")

# Create a multi-step analyzer
multi_analyzer = AnalyzerFactory.create_analyzer("multi_step")

# Create a change analyzer
change_analyzer = AnalyzerFactory.create_analyzer("change")

AnalyzerManager

Manages the complete analysis workflow:

# Initialize manager
manager = AnalyzerManager()

# Add multiple datasets
manager.add_dataset("2000", data_2000)
manager.add_dataset("2010", data_2010)
manager.add_dataset("2020", data_2020)

# Run comprehensive analysis
results = manager.run_analysis(output_dir="./results/")

๐Ÿ”ฌ Analysis Methods

Standard Intensity Analysis

# Load your raster data
from landuse_intensity.processing import read_raster

data_2000, profile_2000 = read_raster("landuse_2000.tiff")
data_2010, profile_2010 = read_raster("landuse_2010.tiff")

# Calculate transition matrix
transition_matrix = transition_matrix_calculation(data_2000, data_2010)

# Perform interval-level analysis
interval_results = interval_level_analysis(transition_matrix)

# Perform category-level analysis  
category_results = category_level_analysis(transition_matrix)

# Perform transition-level analysis
transition_results = transition_level_analysis(transition_matrix)

Multi-Period Analysis

# Analyze multiple time periods
datasets = {
    "2000": data_2000,
    "2005": data_2005, 
    "2010": data_2010,
    "2015": data_2015,
    "2020": data_2020
}

manager = AnalyzerManager()
for year, data in datasets.items():
    manager.add_dataset(year, data)

# Run analysis for all periods
results = manager.run_analysis(
    output_dir="./multi_period_results/",
    generate_plots=True,
    export_excel=True
)

Advanced Spatial Analysis

from landuse_intensity.plots.spatial_plots import (
    plot_change_map,
    plot_persistence_map,
    plot_transition_hotspots
)

# Generate spatial change maps
plot_change_map(data_2000, data_2010, save_path="change_map.png")

# Show areas of persistence vs change
plot_persistence_map(data_2000, data_2010, save_path="persistence.png")

# Identify transition hotspots
plot_transition_hotspots(data_2000, data_2010, save_path="hotspots.png")

๐ŸŽจ Visualization Gallery

Graph Visualizations

# Sankey diagram for transition flows
plot_sankey(data_t1, data_t2, save_path="flows.png")

# Transition matrix heatmap
plot_transition_matrix_heatmap(data_t1, data_t2, save_path="matrix.png")

# Loss and gain bar chart
plot_loss_gain_bar(loss_gain_data, save_path="losses_gains.png")

# Comprehensive analysis with multiple plots
plot_comprehensive_analysis(data_t1, data_t2, save_directory="./output/")

๐Ÿ“ฆ Output Organization

All analysis outputs are automatically organized into structured directories:

analysis_results/
โ”œโ”€โ”€ plots/
โ”‚   โ”œโ”€โ”€ sankey_diagrams/
โ”‚   โ”œโ”€โ”€ heatmaps/
โ”‚   โ”œโ”€โ”€ bar_charts/
โ”‚   โ””โ”€โ”€ spatial_maps/
โ”œโ”€โ”€ tables/
โ”‚   โ”œโ”€โ”€ transition_matrices/
โ”‚   โ”œโ”€โ”€ loss_gain_tables/
โ”‚   โ””โ”€โ”€ intensity_analysis/
โ”œโ”€โ”€ reports/
โ”‚   โ”œโ”€โ”€ analysis_summary.html
โ”‚   โ”œโ”€โ”€ data_validation.pdf
โ”‚   โ””โ”€โ”€ methodology_notes.txt
โ””โ”€โ”€ validation/
    โ”œโ”€โ”€ data_quality_checks.json
    โ””โ”€โ”€ processing_log.txt

๐Ÿ› ๏ธ Development and PyPI Release

PyPI Publishing Guide

This package is designed for professional PyPI distribution. See detailed guides:

Quick PyPI Release

# Build package
python -m build

# Upload to PyPI
python -m twine upload dist/*

# Install from PyPI
pip install landuse-intensity-analysis

Development Setup

# Clone the repository
git clone https://github.com/ils15/LandUse-Intensity-Analysis.git
cd LandUse-Intensity-Analysis

# Install in development mode
pip install -e ".[dev]"

# Run tests
pytest tests/ -v

# Run code quality checks
black landuse_intensity/
flake8 landuse_intensity/
mypy landuse_intensity/

๐Ÿงช Testing and Validation

Built-in Data Validation

from landuse_intensity.utils import validate_raster_data

# Comprehensive data validation
validation = validate_raster_data([data_2000, data_2010])
print(f"Validation passed: {validation['status']}")
print(f"Issues found: {validation['issues']}")

Example Data for Testing

from landuse_intensity import load_example_data

# Load Rio de Janeiro example data (5 years)
rio_data = load_example_data("rio_de_janeiro")
print(f"Years available: {list(rio_data.keys())}")

# Quick analysis with example data
results = run_comprehensive_analysis(
    data_t1=rio_data["2000"],
    data_t2=rio_data["2004"],
    output_dir="./rio_analysis/"
)

๐ŸŒ Real-World Example: Brazilian Cerrado

import landuse_intensity as lui
import numpy as np

# Simulate Brazilian Cerrado data
print("๐ŸŒ Cerrado Biome Analysis")

# Simulated data (replace with real data)
cerrado_classes = ['Cerrado', 'Cerradรฃo', 'Campo', 'Agriculture', 'Pasture', 'Silviculture']

# Create simulated rasters
np.random.seed(42)
raster_2000 = np.random.choice([0,1,2,3,4,5], size=(500, 500), p=[0.4, 0.2, 0.2, 0.1, 0.05, 0.05])
raster_2020 = np.random.choice([0,1,2,3,4,5], size=(500, 500), p=[0.3, 0.15, 0.15, 0.2, 0.15, 0.05])

# Analysis
ct_cerrado = lui.ContingencyTable.from_rasters(
    raster_2000, raster_2020,
    labels1=cerrado_classes,
    labels2=cerrado_classes
)

analyzer_cerrado = lui.IntensityAnalyzer(ct_cerrado)
results_cerrado = analyzer_cerrado.full_analysis()

# Report
print("\n๐Ÿ“Š REPORT - CERRADO CHANGES (2000-2020)")
print("=" * 50)
print(f"Total analyzed area: {ct_cerrado.total_area:,} hectares")
print(f"Changed area: {ct_cerrado.total_change:,} hectares ({ct_cerrado.total_change/ct_cerrado.total_area*100:.1f}%)")
print(f"Annual change rate: {results_cerrado.interval.annual_change_rate:.2f}%")

print("\n๐Ÿ”„ Main Transitions:")
transitions = ct_cerrado.table.stack()
top_transitions = transitions[transitions > 0].sort_values(ascending=False).head(5)

for (from_class, to_class), area in top_transitions.items():
    if from_class != to_class:
        print(f"  {from_class} โ†’ {to_class}: {area:,} hectares")

# Generate visualizations
from landuse_intensity.sankey_visualization import plot_single_step_sankey

plot_single_step_sankey(
    ct_cerrado.table,
    output_dir="cerrado_results",
    filename="cerrado_transitions",
    title="Cerrado Biome Transitions (2000-2020)",
    export_formats=['html', 'png', 'pdf']
)

print("\nโœ… Report and visualizations saved in: cerrado_results/")
print("๐ŸŒ Interactive file: cerrado_results/cerrado_transitions.html")

๐Ÿ”ง Troubleshooting

Common Issues

Error: "Module not found"

# Verify installation
import landuse_intensity as lui
print("Version:", lui.__version__)

# If not working, reinstall
pip uninstall landuse-intensity-analysis
pip install landuse-intensity-analysis

Error: "Invalid data"

# Validate data before analysis
from landuse_intensity.utils import validate_raster_data

is_valid, message = validate_raster_data(raster_t1, raster_t2)
if not is_valid:
    print(f"Data error: {message}")

Performance with Large Rasters

# For very large rasters, process in chunks
from landuse_intensity.utils import process_raster_in_chunks

results = process_raster_in_chunks(
    raster_t1, raster_t2,
    chunk_size=(1000, 1000),
    overlap=50
)

๐Ÿ“š Scientific Background

This library implements the Pontius-Aldwaik Intensity Analysis methodology, a rigorous approach for analyzing land use change patterns. The methodology provides three levels of analysis:

  1. Interval Level: Overall rate of change
  2. Category Level: Category-specific gain/loss patterns
  3. Transition Level: Systematic vs random transitions

Key Publications

  • Pontius Jr., R.G. & Aldwaik, S.Z. (2012). "Intensity analysis to unify measurements of size and stationarity of land changes." Landscape and Urban Planning, 106(1), 103-114.

  • Aldwaik, S.Z. & Pontius Jr., R.G. (2012). "Map errors that could account for deviations from a uniform intensity of land change." Environmental Modelling & Software, 31, 36-49.


๐Ÿ“š References

Methodology

  • Aldwaik, S. Z., & Pontius Jr, R. G. (2012). Intensity analysis to unify measurements of size and stationarity of land changes by interval, category, and transition. Landscape and Urban Planning, 106(1), 103-114.

  • Pontius Jr, R. G., & Millones, M. (2011). Death to Kappa: birth of quantity disagreement and allocation disagreement for accuracy assessment. International Journal of Remote Sensing, 32(15), 4407-4429.

Implementation


๐Ÿค Contributing

Contributions are welcome!

  1. Fork the project
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -am 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

For major changes, please open an issue first to discuss what you would like to change.


๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


๐ŸŽฏ Citation

If you use this library in your research, please cite:

@software{landuse_intensity_analysis,
  title = {LandUse Intensity Analysis},
  author = {LandUse Intensity Analysis Contributors},
  url = {https://github.com/ils15/LandUse-Intensity-Analysis},
  version = {2.0.0a3},
  year = {2025}
}

๐Ÿ“ž Support


Ready to analyze land use changes? Get started today! ๐Ÿš€

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

landuse_intensity_analysis-2.0.0a4.tar.gz (94.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

landuse_intensity_analysis-2.0.0a4-py3-none-any.whl (112.6 kB view details)

Uploaded Python 3

File details

Details for the file landuse_intensity_analysis-2.0.0a4.tar.gz.

File metadata

File hashes

Hashes for landuse_intensity_analysis-2.0.0a4.tar.gz
Algorithm Hash digest
SHA256 12b4ca342f29f257b53507b3f1e3d5f215e6bbfad8d67562da82ba18bf2bc479
MD5 1745888b3d9b83833cb91a6b14eb8540
BLAKE2b-256 be8d5dee2e78a10622c0275dffc0f888d53de627ddf0f3d8adcfc9da9567e8db

See more details on using hashes here.

File details

Details for the file landuse_intensity_analysis-2.0.0a4-py3-none-any.whl.

File metadata

File hashes

Hashes for landuse_intensity_analysis-2.0.0a4-py3-none-any.whl
Algorithm Hash digest
SHA256 de4a93b17f050e4769a15c49b621c8510ffbe9d7c40a4c22c93b2540f936d7cb
MD5 ba5ac4fefd64d9f010f2adb88b2f2896
BLAKE2b-256 c2843f44e235c624ec13fb0d4a50796afe2e9f7f344bb52b74defd5d9a24ad0c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page