Skip to main content

Generate synthetic STAC (SpatioTemporal Asset Catalog) items with realistic metadata

Project description

STAC Sample Maker

Tests PyPI version Python 3.10+ License: MIT

Generate synthetic STAC (SpatioTemporal Asset Catalog) items with realistic metadata for testing, development, and demonstration purposes.

Features

  • 🌍 Complete STAC compliance: Generates valid STAC v1.1.0 items
  • 🔧 All stable extensions: Supports EO, File, Projection, View, SAR, Scientific, and Landsat extensions
  • 📝 Template-based generation: Create items matching existing STAC item structures
  • Schema validation: Optional validation using stac-validator
  • 🎯 Realistic data: Uses Faker to generate believable synthetic metadata
  • 📊 Common metadata: Includes STAC common metadata fields (license, providers, etc.)
  • 🔄 Flexible output: NDJSON format with stdout or file output
  • 🎲 Reproducible: Seed support for consistent outputs

Installation

Basic Installation

pip install stac-sample-maker

With Validation Support

pip install stac-sample-maker[validation]

Development Installation

git clone https://github.com/developmentseed/stac-sample-maker.git
cd stac-sample-maker
pip install -e ".[dev,validation]"

Quick Start

Command Line Usage

Generate 5 synthetic STAC items:

stac-sample-maker --num-items 5

Generate items with validation:

stac-sample-maker --num-items 3 --validate

Generate items from a template:

stac-sample-maker --template my-stac-item.json --num-items 10

Save to a file:

stac-sample-maker --num-items 5 --output samples.ndjson

Library Usage

from stac_sample_maker import generate_stac_items

# Generate basic items
items = generate_stac_items(num_items=5)

# Generate with specific parameters
items = generate_stac_items(
    num_items=10,
    start_date="2020-01-01T00:00:00Z",
    end_date="2023-12-31T23:59:59Z",
    bbox=[-122.5, 37.7, -122.3, 37.8],  # San Francisco area
    seed=42,  # For reproducible results
    validate=True  # Requires stac-validator
)

# Generate from template
from stac_sample_maker import generate_stac_items_from_template

items = generate_stac_items_from_template(
    template_path="example-item.json",
    num_items=5
)

Command Line Interface

stac-sample-maker [OPTIONS]

Options

Option Description Default
--num-items N Number of STAC items to generate 1
--template PATH Path to template STAC item JSON file None
--output PATH Output file path (NDJSON format) stdout
--start DATE Start of datetime range (ISO 8601) None
--end DATE End of datetime range (ISO 8601) None
--interval-percent FLOAT Fraction of items using intervals (0-1) 0.2
--bbox MINX MINY MAXX MAXY Bounding box for geometry None
--seed INT Random seed for reproducibility None
--validate Validate items against STAC schema False

Examples

# Generate 100 items for 2023 with 50% using time intervals
stac-sample-maker --num-items 100 \
  --start "2023-01-01T00:00:00Z" \
  --end "2023-12-31T23:59:59Z" \
  --interval-percent 0.5

# Generate items within a bounding box (San Francisco)
stac-sample-maker --num-items 20 \
  --bbox -122.5 37.7 -122.3 37.8

# Generate reproducible items with validation
stac-sample-maker --num-items 10 \
  --seed 42 \
  --validate \
  --output validated-items.ndjson

Library API

Core Functions

generate_stac_items()

Generate synthetic STAC items with all extensions.

def generate_stac_items(
    num_items: int,
    start_date: Optional[str] = None,
    end_date: Optional[str] = None,
    interval_percent: float = 0.2,
    bbox: Optional[Tuple[float, float, float, float]] = None,
    seed: Optional[int] = None,
    extensions: Optional[List[str]] = None,
    validate: bool = False,
) -> List[dict]:

generate_stac_items_from_template()

Generate STAC items matching a template structure.

def generate_stac_items_from_template(
    template_path: str,
    num_items: int,
    start_date: Optional[str] = None,
    end_date: Optional[str] = None,
    bbox: Optional[Tuple[float, float, float, float]] = None,
    seed: Optional[int] = None,
    validate: bool = False,
) -> List[Dict[str, Any]]:

validate_stac_item()

Validate a STAC item against JSON schema.

def validate_stac_item(
    item: Dict[str, Any],
    strict: bool = True
) -> bool:

Supported Extensions

  • EO (Electro-Optical): Cloud cover, snow cover, spectral bands
  • File: File size, checksums, header information
  • Projection: EPSG codes, transforms, shapes, bounding boxes
  • View: Viewing angles, sun position, off-nadir angles
  • SAR: Radar-specific metadata (frequency, polarization, etc.)
  • Scientific: DOI citations, publications
  • Landsat: Landsat-specific metadata (WRS path/row, etc.)

Template Mode

Template mode analyzes an existing STAC item and generates new items with the same structure:

  1. Extensions: Matches the exact extensions used
  2. Properties: Generates new values for the same property fields
  3. Assets: Creates assets with the same keys and structure
  4. Temporal: Preserves instant vs. interval temporal patterns

Example template workflow:

# Save one generated item as a template
items = generate_stac_items(num_items=1)
with open("template.json", "w") as f:
    json.dump(items[0], f)

# Generate more items matching the template
similar_items = generate_stac_items_from_template(
    template_path="template.json",
    num_items=100
)

STAC Compliance

Generated items are fully compliant with:

  • STAC Specification v1.1.0
  • All stable STAC extensions
  • STAC Common Metadata (license, providers, platform, etc.)
  • GeoJSON standards for geometry
  • ISO 8601 for datetime formatting

Development

Setup

git clone https://github.com/developmentseed/stac-sample-maker.git
cd stac-sample-maker
pip install -e ".[dev,validation]"
pre-commit install

Running Tests

# Run all tests
pytest

# Run with coverage
pytest --cov=stac_sample_maker --cov-report=html

# Run specific tests
pytest tests/test_generator.py -v

Code Quality

# Format code
ruff format

# Lint code
ruff check

# Type checking
mypy stac_sample_maker

Pre-commit Hooks

The project uses pre-commit hooks for code quality:

pre-commit run --all-files

Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes
  4. Run tests and linting (pytest && ruff check && mypy stac_sample_maker)
  5. Commit your changes (git commit -m 'Add amazing feature')
  6. Push to the branch (git push origin feature/amazing-feature)
  7. Open a Pull Request

License

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

Acknowledgments

Related Projects

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

stac_sample_maker-0.0.2.tar.gz (26.3 kB view details)

Uploaded Source

Built Distribution

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

stac_sample_maker-0.0.2-py3-none-any.whl (22.2 kB view details)

Uploaded Python 3

File details

Details for the file stac_sample_maker-0.0.2.tar.gz.

File metadata

  • Download URL: stac_sample_maker-0.0.2.tar.gz
  • Upload date:
  • Size: 26.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.12

File hashes

Hashes for stac_sample_maker-0.0.2.tar.gz
Algorithm Hash digest
SHA256 2817058891ebd1f8959763625ec9c7a2365caa5bfd80b71177e48503d47388a0
MD5 657b21402a2fb0436e9e7c8555d2244c
BLAKE2b-256 1392e0ec1a40e434cbccb8333c625194525802bad7b700de1c5d8150495c541c

See more details on using hashes here.

File details

Details for the file stac_sample_maker-0.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for stac_sample_maker-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 245f2ab29749f126ed932c0c734b6fe8e6d241edb75270c3d2e6d65da4c22b79
MD5 80c878e324c0c46ff67989f4a0f92657
BLAKE2b-256 94f236c21e40435f2b30f9f728838e4f0830331c6639d134f51a688254d5a43f

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