Skip to main content

pop_analysis_pipeline (analysis-pipeline, module spectra_core)

Core runtime of the spectral processing pipelines shared by ONE-PIX and PRO-PIX: plugin discovery, a pipeline of plugins, and a runner for real measurements.

pip install analysis-pipeline          # or, for development: pip install -e .

Python 3.8 or later. Only dependency: numpy.

Plugins

Plugins are packages declared on the spectra.providers entry point. Every module of the package that defines name and transform (or analyze) is a plugin:

[project.entry-points."spectra.providers"]
basic_treatments = "basic_treatments"
name = "crop"

def transform(spectrum, wavelengths, min_wl: float = 500.0, max_wl: float = 700.0):
    ...
    return new_spectrum, new_wavelengths        # transform: a spectrum on a grid

name = "indices"

def analyze(spectrum, wavelengths, indices: Optional[List[Literal["ndvi", "savi"]]] = None):
    return {"ndvi": 0.72}                       # analysis: {name: number}

One spectrum at a time (1D arrays). The parameters are described from the signature (discover_transforms() / discover_analyses() fill TRANSFORMS / ANALYSES with {"fn", "params": {name: {"type", "default"}}}). A Literal annotation adds "options" (the values to pick from) and "multiple" (a list of them); "type" and "default" are unchanged.

Existing providers: basic-treatments (crop, smoothing, SNV, derivative...), spectral-indices (NDVI, PRI, Brix...).

Pipeline

from spectra_core.data import SpectralData
from spectra_core.pipeline import Pipeline
from spectra_core.plugins.discovery import discover_transforms, discover_analyses

discover_transforms(); discover_analyses()
result = Pipeline([("snv", {}), ("crop", {"min_wl": 600, "max_wl": 1800}),
                   ("indices", {"indices": ["ndvi"]})]).run(SpectralData(values, wavelengths))
# transforms only: SpectralData; with analyses: one {index: value} per spectrum

Transforms first, then analyses. Pipeline.run processes the matrix as it is: a spectrum with a missing band (NaN) gives NaN.

Runner for real measurements (spectra_core.engine)

The plugins are not NaN-safe, while real spectra have bands that were not measured (beyond a detector, too little light...). run handles them, checks the pipeline, and processes identical spectra once:

from spectra_core.engine import run, validate, PipelineError

res = run(values, wavelengths, steps, missing="per_spectrum")   # (n, bands), NaN allowed
res.kind                   # "spectra" or "indices"
res.values, res.wavelengths    # transformed spectra (n, bands'), NaN where not processed
res.indices["ndvi"]        # one value per spectrum
res.to_legacy()            # what Pipeline.run returns
missing Use What it does
"per_spectrum" (default) a few spectra, exact each spectrum alone, on its measured bands; one output grid
"fill" thousands of spectra (hypercubes) leaves out bands measured in < 50 % of the spectra and spectra measured in < 80 % of the other bands, interpolates the few NaN left, runs once; interpolated values are NaN again in the transformed spectra

unique=True processes identical spectra once. The result is compact (rows / row_indices: one row per distinct spectrum, row_of: the row of each input spectrum) and is expanded only by values / indices. validate(steps, allow_analyses=True) raises PipelineError for an unknown plugin, a transform after an analysis, or analyses where they are not allowed; res.notes says what was left out or interpolated.

Tests

python -m pytest tests          # tests/test_engine.py: fake plugins, no provider needed

Release

Every push to main builds the package and uploads it to PyPI (.gitlab-ci.yml): change version in pyproject.toml first.

Metadata

Release files for analysis-pipeline 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for analysis-pipeline 0.2.0
File Size Uploaded Provenance Actions
analysis_pipeline-0.2.0.tar.gz 11.8 kB Without provenance Details for analysis_pipeline-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for analysis-pipeline 0.2.0
File Interpreter ABI Platform Actions
analysis_pipeline-0.2.0-py3-none-any.whl Python 3 none any Details for analysis_pipeline-0.2.0-py3-none-any.whl

Total release size: 23.0 kB

Release files / analysis_pipeline-0.2.0.tar.gz

Download URL analysis_pipeline-0.2.0.tar.gz
Size 11.8 kB
Tags Source
SHA-256 checksum
How to use checksums
42cb6605a122ee5134b44c2a2bb508ebc0f89dae9bf3b59d8c6ae213494f0d84
BLAKE2b-256 checksum
How to use checksums
25146c68cddbbb4146439d57a09ca2560345dfb8fc88bf12f6f687511e4ea30b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.22

Release files / analysis_pipeline-0.2.0-py3-none-any.whl

Download URL analysis_pipeline-0.2.0-py3-none-any.whl
Size 11.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7fe804583271f545ac8819ff84eda083487775805870f22b1745372cbe5f9325
BLAKE2b-256 checksum
How to use checksums
139ce97bfb8131174a648159381cafea8d9d35a438e3aa881c18b729d07b892c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.22

Security for analysis-pipeline 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page