Skip to main content

Aboveground biomass extraction with footprint-weighted statistics.

Project description

CosmicBiomass

A modern Python package for extracting and analyzing aboveground biomass density (AGBD) from satellite data sources with support for geospatial footprint weighting and statistical analysis.

Features

  • 🌍 Geospatial biomass extraction from DLR STAC data sources (2017-2023)
  • 📊 Footprint-weighted statistics with circular, Gaussian, and CRNS weighting schemes
  • 🔬 CRNS weighting function implementing Schrön et al. (2017) for cosmic ray neutron sensing
  • 🎯 High precision analysis with uncertainty quantification and outlier detection
  • 🏗️ Modular architecture with pluggable data sources and processing components
  • 89% test coverage with comprehensive unit and integration tests
  • 🐍 Modern Python 3.10+ with type hints, uv-managed environments, and src/ layout

Quick Start

Installation

Option 1: Install from GitHub (Recommended)

# Install directly from GitHub using pip
pip install git+https://codebase.helmholtz.cloud/louis-ferdinand.trinkle/cosmicbiomass.git

# Or install in development mode for contributions
pip install -e git+hhttps://codebase.helmholtz.cloud/louis-ferdinand.trinkle/cosmicbiomass.git#egg=cosmicbiomass

Option 2: Install with conda/mamba

# First install dependencies via conda
conda install -c conda-forge numpy xarray matplotlib pyproj

# Then install cosmicbiomass from GitHub
pip install git+https://codebase.helmholtz.cloud/louis-ferdinand.trinkle/cosmicbiomass.git

Option 3: Development Installation (uv)

# Clone the repository
git clone https://codebase.helmholtz.cloud/louis-ferdinand.trinkle/cosmicbiomass.git
cd cosmicbiomass

# Create a virtual environment
uv venv .venv

# Activate the environment
source .venv/bin/activate

# Install the package in development mode
uv pip install -e .

# Lock dependencies for reproducibility
uv lock

Dependency Version Policy

We track minimum supported versions and avoid strict upper bounds for most dependencies. This keeps the project compatible with the newest stable releases and simplifies upgrades. If a breaking change appears, we will pin that specific package until a fix is available.

Reproducible Workflow Example

Here's a complete example extracting biomass data at the TERENO Hohes Holz station:

import cosmicbiomass

# TERENO Hohes Holz station coordinates
lat, lon = 52.09, 11.226  # degrees N, E
footprint_radius = 240    # meters

# Extract biomass data with 240m circular footprint
result = cosmicbiomass.get_average_biomass(
    lat=lat,
    lon=lon,
    radius=footprint_radius,
    source="dlr",
    dataset="agbd_2018"  # Available: 2017-2023
)

# Access results
biomass_mgha = result['summary']['mean_biomass_Mg_ha']
uncertainty_mgha = result['summary']['uncertainty_Mg_ha']

print(f"Mean AGBD: {biomass_mgha:.1f} ± {uncertainty_mgha:.1f} Mg/ha")
# Output: Mean AGBD: 202.6 ± 27.8 Mg/ha

# Access detailed information
print(f"Footprint coverage: {result['footprint']['effective_pixels']} pixels")
print(f"Data source: {result['data_info']['source']}")
print(f"Dataset: {result['data_info']['dataset']}")

Available Datasets

# List all available datasets
datasets = cosmicbiomass.list_available_datasets(source="dlr")
print("Available years:", list(datasets['datasets'].keys()))
# Output: ['agbd_2017', 'agbd_2018', 'agbd_2019', 'agbd_2020', 'agbd_2021', 'agbd_2022', 'agbd_2023']

API Reference

Core Functions

get_average_biomass(lat, lon, radius=500, source="dlr", dataset="agbd_2021", **kwargs)

Extract footprint-weighted biomass statistics for a location.

Parameters:

  • lat, lon (float): Center coordinates in WGS84 decimal degrees
  • radius (float): Footprint radius in meters (default: 500)
  • source (str): Data source name (default: "dlr")
  • dataset (str): Dataset identifier like "agbd_2018" (default: "agbd_2021")
  • footprint_shape (str): "circular", "gaussian", or "crns" (default: "crns")
  • include_uncertainty (bool): Include uncertainty estimation (default: True)
  • outlier_method (str): "iqr", "zscore", or None for outlier detection

Returns: Dictionary with biomass statistics, location info, and metadata.

list_available_datasets(source="dlr")

Get information about available datasets for a data source.

validate_coordinates(lat, lon)

Validate latitude/longitude coordinates are within valid ranges.

Directory Structure

cosmicbiomass/
├── README.md
├── pyproject.toml              # Python project configuration
├── src/
│   └── cosmicbiomass/
│       ├── __init__.py         # Public API
│       ├── core.py             # Main analysis functions  
│       ├── config.py           # Configuration classes
│       ├── registry.py         # Data source management
│       ├── processing/         # Statistical and footprint processing
│       └── sources/            # Data source implementations
└── tests/                      # Comprehensive test suite (89% coverage)

Dependency Lock

Use the lockfile for reproducible environments:

uv lock

Testing

# Run all tests
uv run pytest

# Run with coverage report
uv run pytest --cov=cosmicbiomass --cov-report=html

# Run specific test modules
uv run pytest tests/test_core.py -v

Publishing to PyPI

# Build wheel and sdist
uv build

# Publish to PyPI (requires credentials)
uv publish

CI/CD (GitLab)

See docs/CI_CD.md for the GitLab pipeline, runner tags, and release tag formats.

Advanced Usage

Custom Footprint Analysis

# CRNS footprint (default) - Schrön et al. (2017) weighting
result = cosmicbiomass.get_average_biomass(
    lat=52.09, lon=11.226,
    radius=500,
    footprint_shape="crns",  # Cosmic ray neutron sensing weighting
    dataset="agbd_2020"
)

# Gaussian footprint with outlier detection
result_gaussian = cosmicbiomass.get_average_biomass(
    lat=52.09, lon=11.226,
    radius=500,
    footprint_shape="gaussian",
    outlier_method="iqr",
    dataset="agbd_2020"
)

# Access detailed footprint info
print(f"Effective pixels: {result['footprint']['effective_pixels']}")
print(f"Total weight: {result['footprint']['total_weight']:.1f}")

Multi-year Analysis

series = cosmicbiomass.get_average_biomass_timeseries(
    lat=52.09,
    lon=11.226,
    radius=240,
    dataset="agbd_{year}",
    start_time="2017-01-01",
    end_time="2023-12-31",
)

biomass_time_series = [
    {
        "year": entry["year"],
        "biomass": entry["result"]["summary"]["mean_biomass_Mg_ha"],
        "uncertainty": entry["result"]["summary"]["uncertainty_Mg_ha"],
    }
    for entry in series
]

VI-driven Seasonal Interpolation (pandas output)

Use vegetation indices (LAI/EVI/NDVI) to create a higher-frequency biomass series. The frequency is inferred from your VI data or you can provide one (e.g., "1H", "1D").

seasonal = cosmicbiomass.get_seasonal_biomass_timeseries(
    lat=52.09,
    lon=11.226,
    radius=170,
    dataset="agbd_{year}",
    start_time="2017-01-01",
    end_time="2023-12-31",
    target_frequency="1D",
    vi_source="auto",  # fetch LAI via GEE, EVI/NDVI via Planetary Computer
)

print(seasonal.head())

## Data Sources

### DLR Global Aboveground Biomass Density

- **Coverage**: 2017-2023 annual products
- **Resolution**: 10m spatial resolution
- **Units**: Mg/ha (megagrams per hectare)
- **Uncertainty**: Available via data spread analysis
- **Access**: STAC catalog via `cubo` integration

## Contributing

- Follow PEP 8 and modern Python best practices
- Add tests for new features (maintain >85% coverage)
- Use f-strings, pathlib, and type hints
- Run `uv run pytest` before submitting changes

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

Copyright (c) 2025 Louis Ferdinand Trinkle

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

cosmicbiomass-0.1.6.tar.gz (279.1 kB view details)

Uploaded Source

Built Distribution

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

cosmicbiomass-0.1.6-py3-none-any.whl (27.3 kB view details)

Uploaded Python 3

File details

Details for the file cosmicbiomass-0.1.6.tar.gz.

File metadata

  • Download URL: cosmicbiomass-0.1.6.tar.gz
  • Upload date:
  • Size: 279.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for cosmicbiomass-0.1.6.tar.gz
Algorithm Hash digest
SHA256 ecaa1334a25f3b06a1be88566040adbc5e4e195d17e25a7fe376842da5e713d9
MD5 3c1031978f37218753a1939273b6a8aa
BLAKE2b-256 84a3e9aeb7a6a3e67cdd0353f4cceb72fea69799c3c9e92a59288525ece7b795

See more details on using hashes here.

File details

Details for the file cosmicbiomass-0.1.6-py3-none-any.whl.

File metadata

  • Download URL: cosmicbiomass-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 27.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for cosmicbiomass-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 cc8b7c29c71484d3ee991c308f2b72d2ad9f0ffc186842e2f7830dba87b15289
MD5 c8a81dd5ca8b82245f28fb59d962f1ef
BLAKE2b-256 5aa506457943125521d728d93b83d2b9e9afd6d06d3bb1d7778fef96e1752caa

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