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.1

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.1
File Size Uploaded Provenance Actions
analysis_pipeline-0.2.1.tar.gz 13.9 kB Without provenance Details for analysis_pipeline-0.2.1.tar.gz

Built distribution (wheel)

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

Total release size: 25.7 kB

Release files / analysis_pipeline-0.2.1.tar.gz

Download URL analysis_pipeline-0.2.1.tar.gz
Size 13.9 kB
Tags Source
SHA-256 checksum
How to use checksums
894b4feef2a99d1762d78e1b4152e567003fd6270a6cac627e8e6436999622ba
BLAKE2b-256 checksum
How to use checksums
f4c5afaac492fae58f8222f6ce8951b229ef899fe46c9a6ecb661445047820eb
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.1-py3-none-any.whl

Download URL analysis_pipeline-0.2.1-py3-none-any.whl
Size 11.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
225e69a4f78b82b8117f5ddebadbb547e8091293d5b3f7ee8a92ece36ddcd41b
BLAKE2b-256 checksum
How to use checksums
a2fbb82eaec77ac37aab1ea29a4ae186cbf0ed1e7c897af876b2f0c951510e04
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.1

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