Skip to main content

Fast hyperspectral data processing for remote sensing and ML pipelines

Project description

hyperspec

Crates.io PyPI License

Fast hyperspectral data processing for remote sensing and ML pipelines. Rust core with Python bindings.

Built by Hyperstate — foundation models for Earth intelligence.

Why hyperspec?

Hyperspectral imagery produces hundreds of bands per pixel, orders of magnitude more than RGB or multispectral. Most existing tools are slow, have heavy system dependencies, and were not designed for modern ML training pipelines.

hyperspec provides:

  • Fast Rust implementations of standard hyperspectral algorithms
  • A SpectralCube abstraction that keeps data, wavelengths, and metadata together
  • Zarr V3 storage with chunking optimized for ML dataloaders
  • Python bindings with zero-copy NumPy interop

Install

Python:

pip install hyperspec-py
# or
uv add hyperspec-py

Rust:

cargo add hyperspec

or

[dependencies]
hyperspec = "0.7"

Quickstart

import numpy as np
from hyperspec import (
    SpectralCube, read_envi, write_zarr, read_zarr_window, zarr_cube_shape,
    sam, continuum_removal, pca, mnf_denoise,
    band_stats, normalize_zscore, savitzky_golay, derivative,
)

# --- I/O ---

# Read ENVI format (AVIRIS-NG, etc.)
cube = read_envi("scene.hdr")

# Process
cr_cube = continuum_removal(cube)
denoised = mnf_denoise(cube, n_components=20)

# Write to Zarr with ML-friendly chunks
write_zarr(cube, "chips.zarr", chunk_shape=(cube.bands, 256, 256))

# Read a single training tile without loading the full cube
tile = read_zarr_window(
    "chips.zarr",
    bands=(0, cube.bands),
    rows=(0, 256),
    cols=(0, 256),
)

# Query shape without loading data
bands, lines, samples = zarr_cube_shape("chips.zarr")

# --- Preprocessing ---

# Per-band statistics
stats = band_stats(cube)        # .mean, .std, .min, .max, .valid_count

# Normalize for ML training
normed = normalize_zscore(cube)

# Smooth noisy spectra, then compute derivatives
smooth = savitzky_golay(cube, window=7, polyorder=2)
d1 = derivative(smooth, order=1)

# --- Spectral analysis ---

# Compare every pixel to a reference spectrum
reference = cube.spectrum(50, 50)
angles = sam(cube, reference)

# Dimensionality reduction
pca_result = pca(cube, n_components=10)

SpectralCube

Category Methods
Dimensions bands, height, width, shape
Data access data(), wavelengths(), fwhm(), nodata
Pixel access spectrum(row, col)
Band access band(index), band_at(nm), band_nearest(nm)
Wavelength lookup wavelength(index), wavelength_index(nm), nearest_band_index(nm)
Statistics mean_spectrum()
Subsetting sel_bands([i, j]), sel_wavelengths(min, max)

I/O

Read

Format Function
ENVI read_envi(path)
Zarr V3 read_zarr(path)
Zarr V3 read_zarr_with_options(path, ...)
Zarr V3 read_zarr_window(path, bands, rows, cols)

Write

Format Function
ENVI write_envi(cube, path)
Zarr V3 write_zarr(cube, path)

Utilities

Format Function
Zarr V3 zarr_cube_shape(path)

Algorithms

Spectral similarity

Operation Function
Spectral Angle Mapper sam(cube, reference)

Spectral preprocessing

Operation Function
Continuum removal continuum_removal(cube)
Savitzky-Golay smoothing savitzky_golay(cube, window, polyorder)
Derivative spectra derivative(cube, order)
Min-max normalization normalize_minmax(cube)
Z-score normalization normalize_zscore(cube)

Statistics

Operation Function
Per-band stats band_stats(cube)BandStats
Covariance matrix covariance(cube)
Correlation matrix correlation(cube)

Spectral indices

Operation Function
Normalized difference normalized_difference(cube, a, b)
Band ratio band_ratio(cube, a, b)
NDVI ndvi(cube, nir, red)

Dimensionality reduction

Operation Function
PCA pca(cube, n_components)
MNF mnf(cube, n_components)
MNF denoise mnf_denoise(cube, n_components)

Spectral utilities

Operation Function
Resample resample(cube, target_wl, method)

Architecture

crates/hyperspec/           # Pure Rust library → crates.io
└── src/
    ├── cube.rs             # SpectralCube type
    ├── error.rs            # HyperspecError
    ├── io/
    │   ├── envi.rs         # ENVI read/write (BSQ, BIL, BIP)
    │   └── zarr.rs         # Zarr V3 read/write/window
    └── algorithms/
        ├── sam.rs
        ├── continuum.rs
        ├── indices.rs
        ├── pca.rs
        ├── mnf.rs
        ├── resample.rs
        ├── stats.rs
        ├── normalize.rs
        ├── derivative.rs
        └── smooth.rs

pyo3-hyperspec/             # PyO3 bindings → PyPI: hyperspec-py
├── src/lib.rs
└── python/hyperspec/
    └── __init__.py
  • Rust 2024 edition, using ndarray, rayon, faer, zarrs, thiserror
  • Minimal system dependencies — no LAPACK or GDAL
  • Python 3.12+, NumPy bindings via PyO3

Roadmap

  • Cloud-native Zarr stores (Azure, GCS, S3)
  • More algorithms and utilities

Development

uv venv && source .venv/bin/activate
uv pip install maturin pytest
cargo test
maturin develop
pytest

License

Apache-2.0

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

hyperspec_py-0.7.2.tar.gz (75.7 kB view details)

Uploaded Source

Built Distributions

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

hyperspec_py-0.7.2-cp313-cp313-win_amd64.whl (2.8 MB view details)

Uploaded CPython 3.13Windows x86-64

hyperspec_py-0.7.2-cp313-cp313-manylinux_2_39_x86_64.whl (3.5 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.39+ x86-64

hyperspec_py-0.7.2-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.5 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64

hyperspec_py-0.7.2-cp313-cp313-macosx_11_0_arm64.whl (2.7 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

hyperspec_py-0.7.2-cp313-cp313-macosx_10_12_x86_64.whl (3.2 MB view details)

Uploaded CPython 3.13macOS 10.12+ x86-64

File details

Details for the file hyperspec_py-0.7.2.tar.gz.

File metadata

  • Download URL: hyperspec_py-0.7.2.tar.gz
  • Upload date:
  • Size: 75.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for hyperspec_py-0.7.2.tar.gz
Algorithm Hash digest
SHA256 edac5f577a1b53f7f21a23356c30f8572ef35d5899b719dccfb0c875eb9522eb
MD5 632cccbd5a918d64912308e5e6a86df5
BLAKE2b-256 ff51f4c8371b236a6f68e96438735c398bd7c4490ec43a9b1051b07181b4d5c8

See more details on using hashes here.

Provenance

The following attestation bundles were made for hyperspec_py-0.7.2.tar.gz:

Publisher: publish.yml on hyperstateco/hyperspec

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file hyperspec_py-0.7.2-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for hyperspec_py-0.7.2-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 2042f1cb81a8ef092e35e8ede7a0a36689aa2f75c18e3573c3a62f3e5c54fd55
MD5 40b95dc41a568fae2a43e65f8a47e27e
BLAKE2b-256 72bc5f1a0295cfe9b7a4f3847bfd7d7c76b0187ecc2fe5dcd8e857f9860086fd

See more details on using hashes here.

Provenance

The following attestation bundles were made for hyperspec_py-0.7.2-cp313-cp313-win_amd64.whl:

Publisher: publish.yml on hyperstateco/hyperspec

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file hyperspec_py-0.7.2-cp313-cp313-manylinux_2_39_x86_64.whl.

File metadata

File hashes

Hashes for hyperspec_py-0.7.2-cp313-cp313-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 a6ccb7f5826d60d5746f153ec3f899c857665b93f9aa9a5b4a4fc217334d85d1
MD5 b99d931dce09f1938a405b98243117d7
BLAKE2b-256 6a039e729d3e47875eb056a41b900e2ff66c2825485f37c9789e442327c0b55a

See more details on using hashes here.

Provenance

The following attestation bundles were made for hyperspec_py-0.7.2-cp313-cp313-manylinux_2_39_x86_64.whl:

Publisher: publish.yml on hyperstateco/hyperspec

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file hyperspec_py-0.7.2-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for hyperspec_py-0.7.2-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 c7221773044716b31ee2ddac8e4aee9fcac1d24e18b77e54b29cb5cf85408251
MD5 73c8c033427a854657ee56a9388cea50
BLAKE2b-256 75b4193a9284be305223274d809367f473ea8b02e11d5b8367d19c7ef8532d52

See more details on using hashes here.

Provenance

The following attestation bundles were made for hyperspec_py-0.7.2-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: publish.yml on hyperstateco/hyperspec

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file hyperspec_py-0.7.2-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for hyperspec_py-0.7.2-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9038483beb5563f6abbfcf8646b503f1afe7bbf9ed9bab63a80939b98493aa97
MD5 ad9761541b3e3d538c99eedff3e1745c
BLAKE2b-256 4b039e1b264ef1ce7e56c4374c5436b59786e32348208a6474fc13659b78e0ab

See more details on using hashes here.

Provenance

The following attestation bundles were made for hyperspec_py-0.7.2-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: publish.yml on hyperstateco/hyperspec

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file hyperspec_py-0.7.2-cp313-cp313-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for hyperspec_py-0.7.2-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 f790d64d852696923613d5f365c8f70445d408ab58ec68005d7e1f1ef458177e
MD5 183d07303b94d56f662ffbb728ce729e
BLAKE2b-256 614b0cf012ba150ed832d93f3c307a50c6cb88e9f3029d5da2f7cfd3686eefa5

See more details on using hashes here.

Provenance

The following attestation bundles were made for hyperspec_py-0.7.2-cp313-cp313-macosx_10_12_x86_64.whl:

Publisher: publish.yml on hyperstateco/hyperspec

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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