Skip to main content

Onboard Methane Detection

This library provides an end-to-end pipeline for processing hyperspectral imagery to detect methane emissions. It includes tools for band selection, methane spectrum generation, preprocessing via Mag1c SAS, and model inference.

Citation arXiv:2606.03675

If you find our research useful, please cite our article:

@misc{herec2026fastmethanedetectionpipeline,
      title={A Fast Methane Detection Pipeline on Board Satellites Based on Mag1c-SAS and LinkNet}, 
      author={Jonáš Herec and Vít Růžička and Rado Pitoňák and Jan Sedmidubsky},
      year={2026},
      eprint={2606.03675},
      archivePrefix={arXiv},
      primaryClass={cs.CV},
      url={https://arxiv.org/abs/2606.03675}, 
}

Installation

pip install onboard-methane-detection

Dependencies and Performance

Onboard Methane Detection is lightweight and depends only on NumPy for processing. ONNX Runtime is required only if you want inference. You can omit ONNX Runtime by using the lightweight build (see Lightweight Onboard Package Build below).

Important: NumPy can be very slow without an acceleration library, so make sure one is installed on your device. We tested with OpenBLAS; the build was about 3.9 MB on ARM Cortex-A53 when compiled without LAPACK. After installing OpenBLAS, reinstall NumPy via pip so it can be detected and used.

End-to-End Example

The following example demonstrates a complete workflow, divided into distinct stages: on-ground preparation, and onboard session execution. The same example is available in showcase.ipynb .

On-Ground

# Core imports for on-ground processing
import numpy as np
from onboard_methane_detection import (
    select_the_bands_by_transmittance, 
    generate_methane_spectrum, 
    select_rgb_bands
)

# 1. Define or load sensor specifications
# wavelengths = [...]  # List of all available sensor wavelengths
# fwhms = [...]        # List of corresponding FWHMs

# 2. Select RGB bands
rgb_wavelengths, rgb_indices = select_rgb_bands(wavelengths)

# 3. Select bands specifically for Methane detection
# First, generate the baseline CH4 spectrum across all sensor bands
ch4_spectrum_full = generate_methane_spectrum(wavelengths, fwhms)

# Then, select the most informative bands based on transmittance
selected_wvs_ch4, selected_ch4_spectrum = select_the_bands_by_transmittance(
    wavelengths, ch4_spectrum_full, N=50, strategy="highest-variance"
)
selected_indices_ch4 = [wavelengths.tolist().index(w) for w in selected_wvs_ch4]

# 4. Export artifacts for the onboard inference session
np.save('rgb_indices.npy', np.array(rgb_indices))
np.save('selected_indices_ch4.npy', np.array(selected_indices_ch4))
np.save('selected_ch4_spectrum.npy', selected_ch4_spectrum)

Onboard

import numpy as np

# Core imports for onboard execution
from onboard_methane_detection import (
    mag1c_sas,
    initialize_model,
    normalize_image,
    model_inference
)

# 1. Load exported artifacts (indices and spectrum) from On-Ground preparation
rgb_indices = np.load('rgb_indices.npy')
selected_indices_ch4 = np.load('selected_indices_ch4.npy')
selected_ch4_spectrum = np.load('selected_ch4_spectrum.npy')

# 2. Session Initialization
# Initialize the inference model before the processing loop begins
session, input_name = initialize_model(dynamic_output_size=True)

# 3. Processing Images (Onboard Loop)
# acquired_images: list of images in shape (C, H, W)

for image in acquired_images:
    # Extract RGB channels using previously found indices
    rgb_image = image[rgb_indices, :, :]
    
    # Extract the CH4 detection bands from the image
    methane_bands_image = image[selected_indices_ch4, :, :]
    
    # Apply Mag1c SAS preprocessing.
    # Optional tiling args (`tiling`, `tile_size`) can be used if the image is too large.
    mag1c_output = mag1c_sas(methane_bands_image, selected_ch4_spectrum, tiling=False)
    
    # Concatenate Mag1c SAS output with local RGB context.
    # Correct channel order is R, G, B, Mag1c-SAS.
    model_input = np.concatenate([rgb_image, mag1c_output], axis=0)
    
    # Normalize input: sensor_or_factors can be "emit", "aviris_ng", 
    # or a custom array of 4 division factors for a different sensor.
    model_input = normalize_image(model_input, sensor_or_factors='emit') 
    
    # Run model inference.
    # Tiling arguments can also be provided here if the image is too large.
    predictions = model_inference(session, input_name, model_input, use_tiling=False, logits_to_probs=True)
    
    print("Processed image and generated predictions.")

Lightweight Onboard Package Build

For deployment on resource-constrained satellite hardware, a build script is provided that generates a minimal version of this library with only the modules you need. It supports optional subpackages (processing, inference, onground) and depends only on NumPy by default, adding ONNX Runtime only when inference is included.

For full usage instructions, available options, and details on what each subpackage includes, see the GitHub repository.

Acknowledgments

A huge thank you to the creators of Mag1c. This project uses core files and edited code from their original repository, and it wouldn't have been possible without their foundational work!

Metadata

Release files for onboard-methane-detection 0.1.2

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

Source distribution (sdist)

Source distribution for onboard-methane-detection 0.1.2
File Size Uploaded Provenance Actions
onboard_methane_detection-0.1.2.tar.gz 14.0 MB Without provenance Details for onboard_methane_detection-0.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for onboard-methane-detection 0.1.2
File Interpreter ABI Platform Actions
onboard_methane_detection-0.1.2-py3-none-any.whl Python 3 none any Details for onboard_methane_detection-0.1.2-py3-none-any.whl

Total release size: 27.9 MB

Release files / onboard_methane_detection-0.1.2.tar.gz

Download URL onboard_methane_detection-0.1.2.tar.gz
Size 14.0 MB
Tags Source
SHA-256 checksum
How to use checksums
366223f49e036893e68551fa9f1212cfd1641f08a2519fa81c192b237dcf81f2
BLAKE2b-256 checksum
How to use checksums
05fc8c725f7b0fbf2f8d69828a21c9e8a0fcd4fe42a9c0d49542add84e47ca90
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.4

Release files / onboard_methane_detection-0.1.2-py3-none-any.whl

Download URL onboard_methane_detection-0.1.2-py3-none-any.whl
Size 14.0 MB
Tags Python 3
SHA-256 checksum
How to use checksums
8bd17c52c12bac17016aa5b89a6005c74618331d31d6f8e465adc28f372c1340
BLAKE2b-256 checksum
How to use checksums
47c833ed10b4177da91b0b8078bf1aacdf1be6d606321c8e625791cb66b2c68f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.4

Security for onboard-methane-detection 0.1.2

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