lasprs 0.14.2

Library for Acoustic Signal Processing (Rust edition, with optional Python bindings via pyo3)
//! Measurement type enumeration
//!
//! This module defines the types of measurements that can be performed
//! and stored in LASP measurement files.
use crate::*;
use anyhow::{Result, anyhow};
use hdf5_metno::File;
#[cfg(feature = "python-bindings")]
use pyo3::prelude::*;
use serde::{Deserialize, Serialize};
use strum::EnumMessage;
use strum_macros::{Display, EnumMessage, FromRepr};
use uuid::Uuid;

use crate::tools::h5::{read_h5_attr_scalar, read_h5_attr_string};

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
#[cfg_attr(
    feature = "python-bindings",
    gen_stub_pyclass_complex_enum,
    pyclass(from_py_object)
)]
/// Insertion loss type specific information
pub enum ILInfo {
    /// Normal measurement
    NormalMeasurement {},
    /// Reference measurement
    ReferenceMeasurement {},
}

#[cfg_attr(
    feature = "python-bindings",
    gen_stub_pyclass_complex_enum,
    pyclass(from_py_object)
)]
#[derive(Serialize, Deserialize, Debug, Clone, strum_macros::EnumMessage, PartialEq)]
/// Metadata about the measurement type. Tells us what kind of measurement it
/// is, and some information about how it is performed. This is used in ACME for
/// processing measurements, and exposing available options on the measurement.
pub enum MeasurementType {
    /// Not a specific measurement type
    #[strum(message = "Not specific")]
    NotSpecific {},
    /// General calibration measurement
    #[strum(message = "General calibration")]
    GeneralCalibration {},
    /// Insertion loss measurement
    #[strum(message = "Insertion loss")]
    IL {
        /// Insertion loss type specific information
        info: ILInfo,
    },
    /// µZ measurement. Specific configuration details are implemented
    /// elsewhere, in private modules.
    #[strum(message = "µZ measurement")]
    MuZ {
        /// µZ specific information, interpreted elsewhere
        muZSpecific_serialized: String,
    },
    /// Sound level measurement, requires pre-captured data
    #[strum(message = "Sound levels")]
    SoundLevels {},
}
#[cfg(feature = "python-bindings")]
#[cfg_attr(feature = "python-bindings", gen_stub_pymethods, pymethods)]
impl MeasurementType {
    /// Get the message associated with the measurement type
    fn __str__(&self) -> String {
        self.get_message().unwrap().into()
    }
    fn __repr__(&self) -> String {
        format!("{:?}", self)
    }
    #[pyo3(name = "requiresPreCapturedData")]
    fn requiresPreCapturedData_py(&self) -> bool {
        self.requiresPreCapturedData()
    }
}

impl MeasurementType {
    /// Returns `true` if this measurement type requires pre-captured data.
    pub fn requiresPreCapturedData(&self) -> bool {
        matches!(self, MeasurementType::SoundLevels {})
    }
}

impl Default for MeasurementType {
    fn default() -> Self {
        MeasurementType::NotSpecific {}
    }
}