Expand description
SARPRO — a high-performance Sentinel-1 GRD processing toolkit.
This crate provides a typed, ergonomic API for turning Sentinel-1 SAFE (GRD) products into high-quality GeoTIFFs or JPEGs, with optional resizing, padding, autoscaling, and polarization operations. It powers both the SARPRO CLI and GUI, and can be embedded in your own Rust applications.
§Stability
The public library API is experimental in initial releases. It is built on top of a working MVP used by the CLI/GUI and is robust, but may evolve as the crate stabilizes. Breaking changes can occur.
§Requirements
- GDAL development headers and runtime available on your system.
- Rust 2024 edition toolchain.
§Add dependency
[dependencies]
sarpro = { version = "0.3", features = ["full"] }
§Quick start: process a SAFE to a file
use std::path::Path;
use sarpro::{
process_safe_to_path,
ProcessingParams,
AutoscaleStrategy, BitDepthArg, OutputFormat, Polarization, InputFormat, SyntheticRgbMode,
};
fn main() -> sarpro::Result<()> {
let params = ProcessingParams {
format: OutputFormat::TIFF,
input_format: InputFormat::Safe,
bit_depth: BitDepthArg::U16,
polarization: Polarization::Multiband,
autoscale: AutoscaleStrategy::Clahe,
target_crs: Some("auto".to_string()),
resample_alg: Some("lanczos".to_string()),
synrgb_mode: SyntheticRgbMode::Default,
size: Some(2048),
pad: true,
};
process_safe_to_path(
Path::new("/data/S1A_example.SAFE"),
Path::new("/out/product.tiff"),
¶ms,
)
}
§Process in-memory to ProcessedImage
use std::path::Path;
use sarpro::{
process_safe_to_buffer_with_mode,
AutoscaleStrategy, BitDepth, OutputFormat, Polarization, SyntheticRgbMode
};
fn main() -> sarpro::Result<()> {
let img = process_safe_to_buffer_with_mode(
Path::new("/data/S1A_example.SAFE"),
Polarization::Multiband,
AutoscaleStrategy::Clahe,
BitDepth::U8,
Some(1024),
true,
OutputFormat::JPEG,
SyntheticRgbMode::Default,
)?;
// Use `img` buffers in your pipeline (TIFF grayscale/multiband or synthetic RGB JPEG)
// and/or consult its metadata.
Ok(())
}
§Typed save helpers (when you already have arrays)
use std::path::Path;
use ndarray::Array2;
use sarpro::{
save_image, save_multiband_image,
AutoscaleStrategy, BitDepth, OutputFormat, ProcessingOperation,
};
fn save_single(processed: &Array2<f32>) -> sarpro::Result<()> {
save_image(
processed,
Path::new("/out/single.tiff"),
OutputFormat::TIFF,
BitDepth::U16,
Some(2048),
None, // Optional SAFE metadata if available
true,
AutoscaleStrategy::Clahe,
ProcessingOperation::SingleBand,
)
}
fn save_dual(vv: &Array2<f32>, vh: &Array2<f32>) -> sarpro::Result<()> {
save_multiband_image(
vv,
vh,
Path::new("/out/multiband.tiff"),
OutputFormat::TIFF,
BitDepth::U8,
Some(1024),
None,
true,
AutoscaleStrategy::Clahe,
ProcessingOperation::MultibandVvVh,
)
}
§Batch helpers
use std::path::Path;
use sarpro::{
process_directory_to_path,
ProcessingParams, AutoscaleStrategy, BitDepthArg, OutputFormat, Polarization, InputFormat, SyntheticRgbMode,
};
fn main() -> sarpro::Result<()> {
let params = ProcessingParams {
format: OutputFormat::JPEG,
input_format: InputFormat::Safe,
bit_depth: BitDepthArg::U8,
polarization: Polarization::Multiband,
autoscale: AutoscaleStrategy::Clahe,
target_crs: Some("auto".to_string()),
resample_alg: Some("lanczos".to_string()),
synrgb_mode: SyntheticRgbMode::Default,
size: Some(1024),
pad: true,
};
let report = process_directory_to_path(
Path::new("/data/safe_root"),
Path::new("/out"),
¶ms,
true, // continue_on_error
)?;
println!("processed={} skipped={} errors={}", report.processed, report.skipped, report.errors);
Ok(())
}
§Error handling
All public functions return sarpro::Result<T>
; match on sarpro::Error
to handle specific
cases, e.g. GDAL or SAFE reader errors.
use std::path::Path;
use sarpro::{process_safe_to_path, Error, ProcessingParams, AutoscaleStrategy, BitDepthArg, OutputFormat, Polarization, InputFormat, SyntheticRgbMode};
fn main() {
let params = ProcessingParams {
format: OutputFormat::TIFF,
input_format: InputFormat::Safe,
bit_depth: BitDepthArg::U8,
polarization: Polarization::Vv,
autoscale: AutoscaleStrategy::Clahe,
target_crs: Some("EPSG:32630".to_string()),
resample_alg: Some("lanczos".to_string()),
synrgb_mode: SyntheticRgbMode::Default,
size: None,
pad: false,
};
match process_safe_to_path(Path::new("/bad/path.SAFE"), Path::new("/out.tiff"), ¶ms) {
Ok(()) => {}
Err(Error::Gdal(e)) => eprintln!("GDAL error: {e}"),
Err(Error::Safe(e)) => eprintln!("SAFE error: {e}"),
Err(other) => eprintln!("Other error: {other}"),
}
}
§Feature flags
gui
: builds the GUI crate module.full
: enables a complete feature set for typical end-to-end workflows.
§Useful modules
Re-exports§
pub use core::params::ProcessingParams;
pub use error::Error;
pub use error::Result;
pub use types::AutoscaleStrategy;
pub use types::BitDepth;
pub use types::BitDepthArg;
pub use types::InputFormat;
pub use types::OutputFormat;
pub use types::Polarization;
pub use types::SyntheticRgbMode;
pub use types::PolarizationOperation;
pub use types::ProcessingOperation;
pub use io::gdal::GdalError;
pub use io::gdal::GdalMetadata;
pub use io::gdal::GdalSarReader;
pub use io::sentinel1::ProductType;
pub use io::sentinel1::SafeError;
pub use io::sentinel1::SafeMetadata;
pub use io::sentinel1::SafeReader;
pub use io::writers::metadata::create_jpeg_metadata_sidecar;
pub use io::writers::metadata::embed_tiff_metadata;
pub use io::writers::metadata::extract_metadata_fields;
pub use api::BatchReport;
pub use api::ProcessedImage;
pub use api::iterate_safe_products;
pub use api::iterate_safe_products;
pub use api::load_operation;
pub use api::load_operation;
pub use api::load_polarization;
pub use api::load_polarization;
pub use api::process_directory_to_path;
pub use api::process_directory_to_path;
pub use api::process_safe_to_buffer;
pub use api::process_safe_to_buffer;
pub use api::process_safe_to_buffer_with_mode;
pub use api::process_safe_to_buffer_with_mode;
pub use api::process_safe_to_path;
pub use api::process_safe_to_path;
pub use api::process_safe_with_options;
pub use api::process_safe_with_options;
pub use api::save_image;
pub use api::save_image;
pub use api::save_multiband_image;
pub use api::save_multiband_image;
Modules§
- api
- High-level, ergonomic library API: process SAFE to files or in-memory buffers, batch helpers for directories, and typed save/load helpers. Prefer using these entrypoints over low-level processing modules when integrating SARPRO.
- core
- Core processing building blocks: autoscale strategies, resize/padding,
processing pipelines, and save helpers. These are internal primitives
consumed by the high-level
api
module. - error
- Crate-level error type and
Result
alias for stable, structured error handling. Converts underlying I/O, SAFE, and GDAL errors, and provides semantic variants for argument validation and processing failures. - gui
- io
- I/O layer for reading SAFE products and GDAL-backed rasters.
Provides the
sentinel1
SAFE reader,gdal
adapters, andwriters
for TIFF/JPEG outputs and metadata embedding/sidecars. - types
- Shared types and enums used across SARPRO.
Includes
Polarization
,AutoscaleStrategy
,InputFormat
,OutputFormat
, bit depths (BitDepth
,BitDepthArg
), andProcessingOperation
.