lasprs 0.14.0

Library for Acoustic Signal Processing (Rust edition, with optional Python bindings via pyo3)
//! # Library for acoustic signal processing
//!
//! This crate contains structures and functions to perform acoustic
//! measurements, interact with data acquisition devices and apply common
//! acoustic analysis operations on them.
//!
//! You will find the following stuff in this crate:
//!
//! - Data acquisition, recording, signal generation: [daq].
//! - Power spectra estimation, transfer function estimation tools: [ps].
//! - Sound Level Meter implementation: [slm].
//! - Filter design tools. I.e. [filter::ZPKModel::butter].
//!   - Includes bilinear transforms
//! - Tools for real time displaying of sensor data: [rt].
//!
//! ## Note to potential users
//!
//! **This crate is still under heavy development. API changes happen on the
//! fly. Documentation is not finished. Use with caution and expect things to be
//! broken and buggy. Use at your own risk and responsibility.**
//!
//! ## Author information
//!
//! The main developer is J.A. de Jong from [ASCEE](https://www.ascee.nl). In
//! case of bug reports, please file them to [info@ascee.nl](info@ascee.nl).
//!
//! If you have particular interest in this library, please also contact us.
//!
#![warn(missing_docs)]
#![allow(non_snake_case)]
#![allow(non_upper_case_globals)]
#![allow(unused_imports)]
#![allow(clippy::module_inception)]
mod common;
mod config;
mod math;
pub mod prelude;
mod tools;

pub use config::*;
use hdf5_metno::plist::file_create;
use pkg_version::{pkg_version_major, pkg_version_minor};
pub mod daq;
pub mod filter;
pub mod measurement;
pub mod ps;
pub mod rt;
pub mod siggen;
pub mod slm;
pub use common::*;

/// A Python module implemented in Rust.
#[cfg(all(
    feature = "python-bindings",
    not(feature = "python-bindings-nostandalone")
))]
#[pymodule(name = "_lasprs")]
mod lasprs {
    use pyo3::prelude::*;
    #[pymodule_init]
    fn init<'py>(m: &Bound<'py, PyModule>) -> PyResult<()> {
        // Arbitrary code to run at the module initialization
        super::add_lasprs_base_module_components(m)?;
        Ok(())
    }
}

#[cfg(feature = "python-bindings")]
/// Adds all LaspRS classes and functions to the base module.
pub fn add_lasprs_base_module_components<'py>(m: &Bound<'py, PyModule>) -> PyResult<()> {
    // Add version info constants
    m.add("LASP_VERSION_MAJOR", LASP_VERSION_MAJOR)?;
    m.add("LASP_VERSION_MINOR", LASP_VERSION_MINOR)?;

    m.add_function(wrap_pyfunction!(ps::getFreq_py, m)?)?;
    m.add_function(wrap_pyfunction!(ps::smoothSpectralData_py, m)?)?;

    m.add_class::<common::Positive>()?;
    m.add_class::<common::ValidationError>()?;

    // Add all data-acquisition types
    daq::add_py_classses(m)?;

    // Add filter submodule
    m.add_class::<filter::Biquad>()?;
    m.add_class::<filter::SeriesBiquad>()?;
    m.add_class::<filter::BiquadBank>()?;
    m.add_class::<filter::FilterSpec>()?;
    m.add_class::<filter::FIR>()?;
    m.add_class::<filter::ZPKModel>()?;
    m.add_class::<filter::StandardFilterDescriptor>()?;
    m.add_class::<filter::ParametricFilterDescriptor>()?;
    m.add_class::<filter::ParametricFilterType>()?;
    // Eq related
    m.add_class::<filter::Equalizer>()?;
    m.add_class::<filter::GraphicEqualizer>()?;
    m.add_class::<filter::GraphicEqualizerType>()?;
    m.add_class::<filter::ParametricEqualizer>()?;
    m.add_class::<filter::ParametricFilterDescriptor>()?;
    m.add_class::<filter::ParametricFilterType>()?;
    m.add_class::<filter::AdaptableFIR>()?;

    // Signal generator
    m.add_class::<siggen::SourceDescriptor>()?;
    m.add_class::<siggen::SiggenCommand>()?;
    m.add_class::<siggen::SweepType>()?;
    m.add_class::<siggen::SweepSettings>()?;
    m.add_class::<siggen::InterruptTime>()?;
    m.add_class::<siggen::PySiggenError>()?;
    m.add_class::<siggen::SiggenError>()?;

    // Measurement classes
    m.add_class::<measurement::SharedMeasurement>()?;
    m.add_class::<measurement::MeasurementType>()?;
    m.add_class::<measurement::ILInfo>()?;
    m.add_class::<measurement::FrameMismatchPolicy>()?;
    m.add_class::<measurement::WavInfo>()?;
    m.add_class::<measurement::ExportWavDtype>()?;
    m.add_class::<measurement::ExportWavSettings>()?;
    m.add_function(wrap_pyfunction!(measurement::read_wav_info, m)?)?;

    // Measurement exceptions
    m.add_class::<measurement::MeasurementError>()?;
    m.add_class::<measurement::PyMeasurementError>()?;

    // SLM
    m.add_class::<TimeWeighting>()?;
    m.add_class::<slm::SLMSettings>()?;
    m.add_class::<slm::SLM>()?;
    m.add_class::<slm::SLMResult>()?;
    m.add("Lref_default", slm::Lref_default)?;

    // Power spectra classes
    m.add_class::<common::FreqWeighting>()?;
    m.add_class::<common::WindowType>()?;
    m.add_class::<common::Overlap>()?;
    m.add_class::<common::StrictlyPositive>()?;
    m.add_class::<common::Positive>()?;
    m.add_class::<ps::ApsMode>()?;
    m.add_class::<ps::ApsSettings>()?;
    m.add_class::<ps::AvPowerSpectra>()?;
    m.add_class::<ps::CPSSettings>()?;
    m.add_class::<ps::CPSResult>()?;
    m.add_class::<ps::SpectrogramResult>()?;
    m.add_class::<ps::SmoothingWidth>()?;
    m.add_class::<ps::SmoothingType>()?;
    m.add_class::<ps::FreqSmoothError>()?;
    m.add_class::<ps::PyFreqSmoothError>()?;

    // Real time classes
    m.add_class::<rt::PPMWrapper>()?;
    m.add_class::<rt::PPMDropSpeed>()?;
    m.add_class::<rt::ClipState>()?;
    m.add_class::<rt::RtAps>()?;
    m.add_class::<rt::RtSlm>()?;
    m.add_class::<rt::RtViewer>()?;

    Ok(())
}

cfg_select! {
    all(feature = "python-bindings", not(feature = "python-bindings-nostandalone"))=> {
        use pyo3_stub_gen::define_stub_info_gatherer;
        define_stub_info_gatherer!(stub_info);
    }
    _=>{}
}