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.6"

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,
)

# --- 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")

# --- 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 Notes
ENVI read_envi(path) BSQ, BIL, BIP; memory-mapped; all numeric types
Zarr V3 read_zarr(path) Auto-discovers reflectance/wavelengths/fwhm
Zarr V3 read_zarr_with_options(path, ...) Explicit dataset paths, scale/offset
Zarr V3 read_zarr_window(path, bands, rows, cols) Windowed reads for ML dataloaders

Write

Format Function Notes
ENVI write_envi(cube, path) Configurable dtype and interleave
Zarr V3 write_zarr(cube, path) Gzip compression, ML-friendly chunk_shape

Utilities

Function Description
zarr_cube_shape(path) Query (bands, lines, samples) without loading data

Algorithms

Spectral similarity

Operation Function
Spectral Angle Mapper sam(cube, reference)

Spectral preprocessing

Operation Function
Continuum removal continuum_removal(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

pyo3-hyperspec/             # PyO3 bindings → PyPI: hyperspec-py
├── src/lib.rs
└── python/hyperspec/
    └── __init__.py
  • Rust 2024 edition, using ndarray, rayon, 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.6.0.tar.gz (57.9 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.6.0-cp313-cp313-win_amd64.whl (2.2 MB view details)

Uploaded CPython 3.13Windows x86-64

hyperspec_py-0.6.0-cp313-cp313-manylinux_2_34_x86_64.whl (2.8 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

hyperspec_py-0.6.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.2 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64

hyperspec_py-0.6.0-cp313-cp313-macosx_11_0_arm64.whl (2.5 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

hyperspec_py-0.6.0-cp313-cp313-macosx_10_12_x86_64.whl (2.6 MB view details)

Uploaded CPython 3.13macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: hyperspec_py-0.6.0.tar.gz
  • Upload date:
  • Size: 57.9 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.6.0.tar.gz
Algorithm Hash digest
SHA256 8110bdab49619240882ab7297bb9cedb7debd68835b2a3164b9ae56452be6309
MD5 65f292394e71d98fef59b1c615b58b32
BLAKE2b-256 10641eecf10accd8f8fe2cffee22668a3010e44b21c52e5ea8fa8e5e722df4a5

See more details on using hashes here.

Provenance

The following attestation bundles were made for hyperspec_py-0.6.0.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.6.0-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for hyperspec_py-0.6.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 77b4be237d74567e7905819b53ce6adb452b86ecb521de9a670543942cc29945
MD5 cc8ec5f2b42a67bb800a4653e5daad69
BLAKE2b-256 c743e779970a5bd52804f2ff3f1d55c38b8191009f00bb27bfb4a4d1ac67ca88

See more details on using hashes here.

Provenance

The following attestation bundles were made for hyperspec_py-0.6.0-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.6.0-cp313-cp313-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for hyperspec_py-0.6.0-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 8ac45e22d2b031e7a0f96ead62fec412d33e3c6bc896831db17724b63363ea04
MD5 35d914a0092a7f288c4bc25e06121f46
BLAKE2b-256 3176c8f009488ecbe8297b3b28aa55599fd4a9523a6e4e6ac88546929e0a8cfb

See more details on using hashes here.

Provenance

The following attestation bundles were made for hyperspec_py-0.6.0-cp313-cp313-manylinux_2_34_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.6.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for hyperspec_py-0.6.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 e9b1c64ef986818777dae241580ef734b1563b2f56b4e5699cfcffb0562f2807
MD5 e02c1d1ba87a60a40e089e805033ba9b
BLAKE2b-256 6e52489b9ed4f8a154517dbd7bc67d0bd1a8aa7c8555df598907a07dc71c59fd

See more details on using hashes here.

Provenance

The following attestation bundles were made for hyperspec_py-0.6.0-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.6.0-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for hyperspec_py-0.6.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 75ff806914a53eb2e44f5192411c52d60f58aa14a52370d50918801a44747dce
MD5 51a1ee9863022c0b32e590f52bea833a
BLAKE2b-256 abd5f071fe935e6af9d99ca13319efbd3a99bf7b6b1b36b8a94e6d285ceefdf6

See more details on using hashes here.

Provenance

The following attestation bundles were made for hyperspec_py-0.6.0-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.6.0-cp313-cp313-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for hyperspec_py-0.6.0-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 5291e8bd6bd1bebb4a5852a88971359d55f4534f1b13e9e5b49fadf2ada20c1e
MD5 cf021031a148da69ba803f307961bab3
BLAKE2b-256 e3e637cb05c0724e8dbb568d3c1f5ca636cc83fa370c286714cb4870a045e680

See more details on using hashes here.

Provenance

The following attestation bundles were made for hyperspec_py-0.6.0-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