diff --git a/.gitea/workflows/workflow.yml b/.gitea/workflows/workflow.yml new file mode 100644 index 0000000..e69de29 diff --git a/examples_py/test_aps.ipynb b/examples_py/test_aps.ipynb new file mode 100644 index 0000000..b8a636b --- /dev/null +++ b/examples_py/test_aps.ipynb @@ -0,0 +1,146 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "6763c6d0-878f-4492-840e-40d11a52f91e", + "metadata": {}, + "source": [ + "# Test Welch method implementation Python wrappers" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "6c06a0c3-dcf7-4d21-b1f3-eced84e31218", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "🍹 Building a mixed python/rust project\n", + "🔗 Found pyo3 bindings\n", + "🐍 Found CPython 3.10 at /home/anne/.pyenv/versions/lasprs/bin/python\n", + "Requirement already satisfied: numpy in /home/anne/.pyenv/versions/lasprs/lib/python3.10/site-packages (1.26.4)\n", + "\u001b[1m\u001b[32m Compiling\u001b[0m pyo3-build-config v0.21.2\n", + "\u001b[K\u001b[1m\u001b[32m Compiling\u001b[0m pyo3-macros-backend v0.21.2 178/189: pyo3-build-config \n", + "\u001b[K\u001b[1m\u001b[32m Compiling\u001b[0m pyo3-ffi v0.21.2=======> ] 178/189: pyo3-macros-backend, pyo3...\n", + "\u001b[1m\u001b[32m Compiling\u001b[0m pyo3 v0.21.2\n", + "\u001b[K\u001b[1m\u001b[32m Compiling\u001b[0m pyo3-macros v0.21.2=====> ] 183/189: pyo3-macros-backend, pyo3...\n", + "\u001b[K\u001b[1m\u001b[32m Compiling\u001b[0m numpy v0.21.0===========> ] 186/189: pyo3 \n", + "\u001b[K\u001b[1m\u001b[32m Compiling\u001b[0m lasprs v0.6.1 (/home/anne/wip/mycode/lasprs) \n", + "\u001b[K\u001b[0m\u001b[1m\u001b[33mwarning\u001b[0m\u001b[0m\u001b[1m: type alias `Vc` is never used\u001b[0m \n", + "\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m--> \u001b[0m\u001b[0msrc/config.rs:63:10\u001b[0m\n", + "\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\n", + "\u001b[0m\u001b[1m\u001b[38;5;12m63\u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\u001b[0m \u001b[0m\u001b[0mpub type Vc = Vec;\u001b[0m\n", + "\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[33m^^\u001b[0m\n", + "\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\n", + "\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m= \u001b[0m\u001b[0m\u001b[1mnote\u001b[0m\u001b[0m: `#[warn(dead_code)]` on by default\u001b[0m\n", + "\n", + "\u001b[K\u001b[0m\u001b[1m\u001b[33mwarning\u001b[0m\u001b[0m\u001b[1m: type alias `Cmat` is never used\u001b[0m \n", + "\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m--> \u001b[0m\u001b[0msrc/config.rs:75:10\u001b[0m\n", + "\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\n", + "\u001b[0m\u001b[1m\u001b[38;5;12m75\u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\u001b[0m \u001b[0m\u001b[0mpub type Cmat = Array2;\u001b[0m\n", + "\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[33m^^^^\u001b[0m\n", + "\n", + "\u001b[0m\u001b[1m\u001b[33mwarning\u001b[0m\u001b[0m\u001b[1m: methods `ninchannels` and `noutchannels` are never used\u001b[0m\n", + "\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m--> \u001b[0m\u001b[0msrc/daq/api/mod.rs:25:8\u001b[0m\n", + "\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\n", + "\u001b[0m\u001b[1m\u001b[38;5;12m20\u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\u001b[0m \u001b[0m\u001b[0mpub trait Stream {\u001b[0m\n", + "\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m------\u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12mmethods in this trait\u001b[0m\n", + "\u001b[0m\u001b[1m\u001b[38;5;12m...\u001b[0m\n", + "\u001b[0m\u001b[1m\u001b[38;5;12m25\u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\u001b[0m \u001b[0m\u001b[0m fn ninchannels(&self) -> usize;\u001b[0m\n", + "\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[33m^^^^^^^^^^^\u001b[0m\n", + "\u001b[0m\u001b[1m\u001b[38;5;12m...\u001b[0m\n", + "\u001b[0m\u001b[1m\u001b[38;5;12m28\u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\u001b[0m \u001b[0m\u001b[0m fn noutchannels(&self) -> usize;\u001b[0m\n", + "\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[33m^^^^^^^^^^^^\u001b[0m\n", + "\n", + "\u001b[K\u001b[0m\u001b[1m\u001b[33mwarning\u001b[0m\u001b[0m\u001b[1m: method `setPreFilter` is never used\u001b[0m \n", + "\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m--> \u001b[0m\u001b[0msrc/siggen.rs:320:12\u001b[0m\n", + "\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\n", + "\u001b[0m\u001b[1m\u001b[38;5;12m318\u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\u001b[0m \u001b[0m\u001b[0mimpl SiggenChannelConfig {\u001b[0m\n", + "\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m------------------------\u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12mmethod in this implementation\u001b[0m\n", + "\u001b[0m\u001b[1m\u001b[38;5;12m319\u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\u001b[0m \u001b[0m\u001b[0m /// Set new pre-filter that filters the source signal\u001b[0m\n", + "\u001b[0m\u001b[1m\u001b[38;5;12m320\u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\u001b[0m \u001b[0m\u001b[0m pub fn setPreFilter(&mut self, pref: Option>) {\u001b[0m\n", + "\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[33m^^^^^^^^^^^^\u001b[0m\n", + "\n", + "\u001b[K\u001b[1m\u001b[33mwarning\u001b[0m\u001b[1m:\u001b[0m `lasprs` (lib) generated 4 warningssprs \n", + "\u001b[1m\u001b[32m Finished\u001b[0m \u001b]8;;https://doc.rust-lang.org/cargo/reference/profiles.html#default-profiles\u001b\\`dev` profile [unoptimized + debuginfo]\u001b]8;;\u001b\\ target(s) in 6.04s\n", + "📦 Built wheel for CPython 3.10 to /tmp/.tmp03vGw7/lasprs-0.6.1-cp310-cp310-linux_x86_64.whl\n", + "✏️ Setting installed package as editable\n", + "🛠 Installed lasprs-0.6.1\n" + ] + } + ], + "source": [ + "!cd .. && maturin develop -F python-bindings" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "3e651371-e7a5-4013-a265-ab80f8b1eb41", + "metadata": {}, + "outputs": [], + "source": [ + "from lasprs import WindowType" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "9d6bdf3b-40f8-4c3b-85ac-4ff8b8c7dcae", + "metadata": {}, + "outputs": [], + "source": [ + "w = WindowType.all()" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "3a31899d-37de-4653-9b6e-61dcf7c683f4", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[WindowType.Hann,\n", + " WindowType.Hamming,\n", + " WindowType.Rect,\n", + " WindowType.Bartlett,\n", + " WindowType.Blackman]" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "w" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.10.12" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/src/ps/aps.rs b/src/ps/aps.rs index 100a58e..467d9f4 100644 --- a/src/ps/aps.rs +++ b/src/ps/aps.rs @@ -146,59 +146,6 @@ impl ApsSettings { } } -/// Provide the overlap of blocks for computing averaged (cross) power spectra. -/// Can be provided as a percentage of the block size, or as a number of -/// samples. -#[cfg_attr(feature = "python-bindings", pyclass)] -#[derive(Clone, Debug, PartialEq)] -pub enum Overlap { - /// Overlap specified as a percentage of the total FFT length. Value should - /// be 0<=pct<100. - Percentage { - /// Percentage - pct: Flt, - }, - /// Number of samples to overlap - Number { - /// N: Number of samples - N: usize, - }, - /// No overlap at all, which is the same as Overlap::Number(0) - NoOverlap {}, -} -impl Default for Overlap { - fn default() -> Self { - Overlap::Percentage { pct: 50. } - } -} - -#[cfg(feature = "python-bindings")] -#[cfg_attr(feature = "python-bindings", pymethods)] -impl Overlap { - #[inline] - fn __eq__(&self, other: &Self) -> bool { - self == other - } - - #[staticmethod] - #[pyo3(name = "default")] - fn default_py() -> Self { - Self::default() - } - - /// Export some typical settings to Python. Customs are also possible by - /// directly creating them. This is to fill up the list. - #[staticmethod] - fn some_settings() -> Vec { - use Overlap::*; - vec![ - NoOverlap {}, - Percentage { pct: 25. }, - Percentage { pct: 50. }, - Percentage { pct: 90. }, - ] - } -} /// The 'mode' used in computing averaged power spectra. When providing data in /// blocks to the [AvPowerSpectra] the resulting 'current estimate' responds diff --git a/src/ps/mod.rs b/src/ps/mod.rs index 3fae073..9fa52e2 100644 --- a/src/ps/mod.rs +++ b/src/ps/mod.rs @@ -15,6 +15,7 @@ use crate::config::*; pub use freqweighting::FreqWeighting; -pub use aps::{ApsSettings, ApsSettingsBuilder,ApsMode, AvPowerSpectra, Overlap}; +pub use overlap::Overlap; +pub use aps::{ApsSettings, ApsSettingsBuilder,ApsMode, AvPowerSpectra}; pub use ps::{CrossPowerSpecra, PowerSpectra, CPSResult}; pub use window::{Window, WindowType}; diff --git a/src/ps/overlap.rs b/src/ps/overlap.rs index 018ab88..1cee18f 100644 --- a/src/ps/overlap.rs +++ b/src/ps/overlap.rs @@ -2,7 +2,7 @@ use crate::config::*; /// Provide the overlap of blocks for computing averaged (cross) power spectra. /// Can be provided as a percentage of the block size, or as a number of /// samples. -#[cfg_attr(feature = "python-bindings", pyclass)] +#[cfg_attr(feature = "python-bindings", pyclass(frozen))] #[derive(Clone, Debug, PartialEq)] pub enum Overlap { /// Overlap specified as a percentage of the total FFT length. Value should @@ -33,6 +33,10 @@ impl Overlap { self == other } + fn __str__(&self) -> String { + self.name() + } + #[staticmethod] #[pyo3(name = "default")] fn default_py() -> Self { @@ -51,4 +55,24 @@ impl Overlap { Percentage { pct: 90. }, ] } -} \ No newline at end of file +} +impl Overlap { + fn name(&self) -> String { + use Overlap::*; + match &self { + NoOverlap {} => "No overlap".into(), + Percentage { pct } => format! {"{} %", pct}, + Number { N } => format! {"{} samples", N}, + } + } +} + +#[cfg(test)] +mod test { + use crate::ps::overlap::Overlap; + + #[test] + fn test_overlap1() { + assert_eq!(Overlap::NoOverlap {}.name(), "No overlap"); + } +}