docs.rs failed to build astro-metrics-0.4.0
Please check the
build logs for more information.
See
Builds for ideas on how to fix a failed build,
or
Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault,
open an issue.
astro-metrics
Statistical metrics and analysis for astronomical images.
Overview
astro-metrics provides functionality for analyzing astronomical images, including star detection, measurement, and quality assessment. It uses the Source Extractor as a Library (SEP) for efficient star detection and implements various metrics for evaluating image quality.
Features
- Star detection using Source Extractor (SEP)
- Star measurements (FWHM, eccentricity, elongation, etc.)
- Background analysis (median, RMS, uniformity)
- Quality scoring for image comparison
- Comprehensive metrics for astronomical image evaluation
Installation
Add to your Cargo.toml:
[dependencies]
astro-metrics = "0.4.0"
API Reference
Core Types
StarMetrics
pub struct StarMetrics {
pub x: f64, pub y: f64, pub flux: f32, pub peak: f32, pub a: f32, pub b: f32, pub theta: f32, pub eccentricity: f32, pub fwhm: f32, pub kron_radius: f32, pub flux_auto: f32, pub fluxerr_auto: f32, pub npix: usize, pub elongation: f32, pub flag: u8, }
Key methods:
impl StarMetrics {
pub fn calc_fwhm(&mut self)
pub fn calc_eccentricity(&mut self)
}
StarStats
pub struct StarStats {
pub count: usize, pub median_fwhm: f32, pub median_eccentricity: f32, pub fwhm_std_dev: f32, pub eccentricity_std_dev: f32, pub median_kron_radius: f32, pub median_flux: f32, pub median_snr: f32, pub median_elongation: f32, pub flagged_fraction: f32, pub kron_radius_std_dev: f32, pub flux_std_dev: f32, pub snr_std_dev: f32, }
Key methods:
impl StarStats {
pub fn from_stars(stars: &[StarMetrics], max_stars: Option<usize>) -> Self
}
BackgroundMetrics
pub struct BackgroundMetrics {
pub median: f32, pub rms: f32, pub min: f32, pub max: f32, pub uniformity: f32, }
QualityScores
pub struct QualityScores {
pub fwhm: f32, pub eccentricity: f32, pub background: f32, pub kron_radius: f32, pub snr: f32, pub flag: f32, pub overall: f32, }
QualityWeights
pub struct QualityWeights {
pub fwhm: f32, pub eccentricity: f32, pub background: f32, pub kron_radius: f32, pub snr: f32, pub flag: f32, }
FrameQualityMetrics
pub struct FrameQualityMetrics {
pub frame_id: String, pub star_stats: StarStats, pub background: BackgroundMetrics, pub scores: QualityScores, }
SEP Detection
pub fn detect_stars_with_sep_background(
data: &[f32],
width: usize,
height: usize,
max_stars: Option<usize>,
) -> Result<(StarStats, BackgroundMetrics)>
pub fn detect_stars_sep(
data: &[f32],
width: usize,
height: usize,
background: f32,
std_dev: f32,
max_stars: Option<usize>,
) -> Result<StarStats>
- Parameters:
data: Flattened pixel data as 32-bit floats
width: Width of the image in pixels
height: Height of the image in pixels
max_stars: Optional maximum number of stars to use for statistics
background: Background level (for detect_stars_sep)
std_dev: Background standard deviation (for detect_stars_sep)
- Returns:
StarStats: Statistics about detected stars
BackgroundMetrics: Background metrics
- Errors:
- If the image is too small
- If SEP encounters an error during detection
Quality Metrics
pub fn calculate_quality_scores(
star_stats: &StarStats,
background: &BackgroundMetrics,
) -> QualityScores
pub fn calculate_overall_score(
fwhm_score: f32,
eccentricity_score: f32,
background_score: f32,
kron_score: f32,
snr_score: f32,
flag_score: f32,
weights: &QualityWeights,
) -> f32
pub fn create_frame_metrics(
path: &Path,
star_stats: StarStats,
background: BackgroundMetrics,
) -> FrameQualityMetrics
pub fn create_frame_metrics_with_weights(
path: &Path,
star_stats: StarStats,
background: BackgroundMetrics,
weights: QualityWeights,
) -> FrameQualityMetrics
Usage Examples
Detecting stars and calculating quality metrics
use astro_metrics::sep_detect;
use astro_metrics::quality_metrics;
use std::path::Path;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let image_data: Vec<f32> = vec![];
let width = 1024;
let height = 768;
let (star_stats, background) = sep_detect::detect_stars_with_sep_background(
&image_data, width, height, None)?;
println!("Found {} stars", star_stats.count);
println!("Median FWHM: {:.2} pixels", star_stats.median_fwhm);
println!("Background uniformity: {:.3}", background.uniformity);
let scores = quality_metrics::calculate_quality_scores(&star_stats, &background);
println!("FWHM score: {:.3}", scores.fwhm);
println!("Eccentricity score: {:.3}", scores.eccentricity);
println!("Background score: {:.3}", scores.background);
println!("Overall quality score: {:.3}", scores.overall);
let path = Path::new("/path/to/image.fits");
let frame_metrics = quality_metrics::create_frame_metrics(
path, star_stats, background);
println!("Frame ID: {}", frame_metrics.frame_id);
Ok(())
}
Using custom weights for quality scoring
use astro_metrics::quality_metrics::{self, QualityWeights};
use astro_metrics::sep_detect;
use std::path::Path;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let image_data: Vec<f32> = vec![];
let width = 1024;
let height = 768;
let (star_stats, background) = sep_detect::detect_stars_with_sep_background(
&image_data, width, height, None)?;
let weights = QualityWeights {
fwhm: 0.5, eccentricity: 0.2,
background: 0.1,
kron_radius: 0.1,
snr: 0.05,
flag: 0.05,
};
let path = Path::new("/path/to/image.fits");
let frame_metrics = quality_metrics::create_frame_metrics_with_weights(
path, star_stats, background, weights);
println!("Overall quality score: {:.3}", frame_metrics.scores.overall);
Ok(())
}
Additional Documentation
For more detailed information about the quality metrics and how they're calculated, see the Quality Metrics Documentation.
License
This project is dual-licensed under the MIT License or the Apache License, Version 2.0.