TimeWeighting __eq__ method added. Improved comments. Tested Python code. Now ready for implementing WindowType Python wrapper
This commit is contained in:
parent
eb94785a89
commit
d9fbe25dc1
@ -12,12 +12,17 @@ and processing of (multi) sensor data in real time on a PC and output results.
|
|||||||
|
|
||||||
Documentation is provided at [doc.rs](https://docs.rs/lasprs/latest/lasprs).
|
Documentation is provided at [doc.rs](https://docs.rs/lasprs/latest/lasprs).
|
||||||
|
|
||||||
|
|
||||||
## Python bindings and examples
|
## Python bindings and examples
|
||||||
|
|
||||||
The library has Python bindings (via [pyo3](https://pyo3.rs), which can be installed via:
|
The library has Python bindings (via [pyo3](https://pyo3.rs), which can be installed via:
|
||||||
|
|
||||||
```
|
```
|
||||||
$ pip install git+https://code.ascee.nl/ascee/lasprs --install-option "python-bindings"
|
$ pip install lasprs
|
||||||
```
|
```
|
||||||
|
|
||||||
|
which pulls the library from [Pypi](https://pypi.org).
|
||||||
|
|
||||||
|
Examples of how to use the library are provided in Jupyter Notebooks, which can be found in the repository, see [lasprs/examples_py](https://code.ascee.nl/ASCEE/lasprs/src/branch/main/examples_py).
|
||||||
|
|
||||||
|
More examples will follow in the near future.
|
||||||
|
|
||||||
|
@ -41,8 +41,8 @@
|
|||||||
"source": [
|
"source": [
|
||||||
"import numpy as np\n",
|
"import numpy as np\n",
|
||||||
"import matplotlib.pyplot as plt\n",
|
"import matplotlib.pyplot as plt\n",
|
||||||
"from numpy import log10, sqrt, exp, pi\n",
|
"from numpy import log10\n",
|
||||||
"from lasprs._lasprs import StandardFilterDescriptor, SLMSettings, FreqWeighting, TimeWeighting, SLM\n",
|
"from lasprs import StandardFilterDescriptor\n",
|
||||||
"def level(a):\n",
|
"def level(a):\n",
|
||||||
" return 20*np.log10(np.abs(a))"
|
" return 20*np.log10(np.abs(a))"
|
||||||
]
|
]
|
||||||
|
@ -41,8 +41,8 @@
|
|||||||
"source": [
|
"source": [
|
||||||
"import numpy as np\n",
|
"import numpy as np\n",
|
||||||
"import matplotlib.pyplot as plt\n",
|
"import matplotlib.pyplot as plt\n",
|
||||||
"from numpy import log10, sqrt, exp, pi\n",
|
"from numpy import log10\n",
|
||||||
"from lasprs._lasprs import ZPKModel, FreqWeighting\n",
|
"from lasprs import ZPKModel, FreqWeighting\n",
|
||||||
"def level(a):\n",
|
"def level(a):\n",
|
||||||
" return 20*np.log10(np.abs(a))"
|
" return 20*np.log10(np.abs(a))"
|
||||||
]
|
]
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
"source": [
|
"source": [
|
||||||
"# Prerequisites, uncomment below in case of errors. Also for ipympl, restart Jupyter Lab if it was not installed\n",
|
"# Prerequisites, uncomment below in case of errors. Also for ipympl, restart Jupyter Lab if it was not installed\n",
|
||||||
"\n",
|
"\n",
|
||||||
|
"# Only do the following if you are in develop mode\n",
|
||||||
"!cd .. && maturin develop -F python-bindings\n",
|
"!cd .. && maturin develop -F python-bindings\n",
|
||||||
"#!pip install ipympl scipy matplotlib"
|
"#!pip install ipympl scipy matplotlib"
|
||||||
]
|
]
|
||||||
@ -41,7 +42,7 @@
|
|||||||
"source": [
|
"source": [
|
||||||
"import numpy as np\n",
|
"import numpy as np\n",
|
||||||
"import matplotlib.pyplot as plt\n",
|
"import matplotlib.pyplot as plt\n",
|
||||||
"from numpy import log10, sqrt, exp, pi\n",
|
"from numpy import log10\n",
|
||||||
"from lasprs._lasprs import StandardFilterDescriptor, SLMSettings, FreqWeighting, TimeWeighting, SLM\n",
|
"from lasprs._lasprs import StandardFilterDescriptor, SLMSettings, FreqWeighting, TimeWeighting, SLM\n",
|
||||||
"def level(a):\n",
|
"def level(a):\n",
|
||||||
" return 20*np.log10(np.abs(a))"
|
" return 20*np.log10(np.abs(a))"
|
||||||
@ -105,27 +106,7 @@
|
|||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"t = np.linspace(0, N/fs, N, endpoint=False)\n",
|
"t = np.linspace(0, N/fs, N, endpoint=False)\n",
|
||||||
"out = slm.run(inp)"
|
"out = slm.run(inp, True)"
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"cell_type": "code",
|
|
||||||
"execution_count": null,
|
|
||||||
"id": "37af9b78-73b9-4228-a758-d9a5362f79f4",
|
|
||||||
"metadata": {},
|
|
||||||
"outputs": [],
|
|
||||||
"source": [
|
|
||||||
"len(out[0])"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"cell_type": "code",
|
|
||||||
"execution_count": null,
|
|
||||||
"id": "4609a63f-e350-4b6b-b898-93c9e6fef804",
|
|
||||||
"metadata": {},
|
|
||||||
"outputs": [],
|
|
||||||
"source": [
|
|
||||||
"# help(plt.legend)"
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -141,14 +122,6 @@
|
|||||||
"plt.ylim(-60, 0)\n",
|
"plt.ylim(-60, 0)\n",
|
||||||
"plt.legend(names)"
|
"plt.legend(names)"
|
||||||
]
|
]
|
||||||
},
|
|
||||||
{
|
|
||||||
"cell_type": "code",
|
|
||||||
"execution_count": null,
|
|
||||||
"id": "4303e20e-cc61-4d23-a5f0-cab683d55912",
|
|
||||||
"metadata": {},
|
|
||||||
"outputs": [],
|
|
||||||
"source": []
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"metadata": {
|
"metadata": {
|
||||||
|
@ -1 +0,0 @@
|
|||||||
from .._lasprs import (Biquad, BiquadBank, SeriesBiquad, ZPKModel, FilterSpec)
|
|
@ -569,7 +569,6 @@ impl ZPKModel {
|
|||||||
let p2 = 2. * pi * f2;
|
let p2 = 2. * pi * f2;
|
||||||
let p3 = 2. * pi * f3;
|
let p3 = 2. * pi * f3;
|
||||||
let p4 = 2. * pi * f4;
|
let p4 = 2. * pi * f4;
|
||||||
println!("{b} {p1}, {p2}, {p3}, {p4}");
|
|
||||||
|
|
||||||
let (zeros, poles) = match wt {
|
let (zeros, poles) = match wt {
|
||||||
FreqWeighting::Z => {
|
FreqWeighting::Z => {
|
||||||
@ -610,11 +609,21 @@ pub enum PoleOrZero {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test{
|
mod test{
|
||||||
|
use approx::assert_abs_diff_eq;
|
||||||
|
use num::complex::ComplexFloat;
|
||||||
|
|
||||||
|
use crate::TransferFunction;
|
||||||
use super::ZPKModel;
|
use super::ZPKModel;
|
||||||
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_A() {
|
fn test_A() {
|
||||||
let Aw = ZPKModel::freqWeightingFilter(crate::FreqWeighting::A);
|
let Aw = ZPKModel::freqWeightingFilter(crate::FreqWeighting::A);
|
||||||
|
assert_abs_diff_eq!(Aw.tf(0., &[1000.])[0].abs(), 1.0);
|
||||||
|
}
|
||||||
|
#[test]
|
||||||
|
fn test_C() {
|
||||||
|
let Cw = ZPKModel::freqWeightingFilter(crate::FreqWeighting::C);
|
||||||
|
assert_abs_diff_eq!(Cw.tf(0., &[1000.])[0].abs(), 1.0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -72,7 +72,11 @@ fn hamming(N: usize) -> Dcol {
|
|||||||
/// * Blackman
|
/// * Blackman
|
||||||
///
|
///
|
||||||
/// The [WindowType::default] is [WindowType::Hann].
|
/// The [WindowType::default] is [WindowType::Hann].
|
||||||
#[derive(Display,Default, Copy, Clone, Debug)]
|
#[derive(Display,Default, Copy, Clone, Debug, PartialEq)]
|
||||||
|
// Do the following when Pyo3 0.22 can finally be used combined with rust-numpy:
|
||||||
|
// #[cfg_attr(feature = "python-bindings", pyclass(eq))]
|
||||||
|
// For now:
|
||||||
|
// #[cfg_attr(feature = "python-bindings", pyclass(eq))]
|
||||||
pub enum WindowType {
|
pub enum WindowType {
|
||||||
/// Von Hann window
|
/// Von Hann window
|
||||||
#[default]
|
#[default]
|
||||||
|
@ -5,11 +5,12 @@ use crate::config::*;
|
|||||||
// #[cfg_attr(feature = "python-bindings", pyclass(eq))]
|
// #[cfg_attr(feature = "python-bindings", pyclass(eq))]
|
||||||
// For now:
|
// For now:
|
||||||
#[cfg_attr(feature = "python-bindings", pyclass)]
|
#[cfg_attr(feature = "python-bindings", pyclass)]
|
||||||
#[derive(Clone, Copy, PartialEq)]
|
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||||
pub enum TimeWeighting {
|
pub enum TimeWeighting {
|
||||||
// I know that the curly braces here are not required and add some
|
// I know that the curly braces here are not required and add some
|
||||||
// boilerplate, but this is the only way Pyo3 swallows complex enums at the
|
// boilerplate, but this is the only way Pyo3 swallows complex enums at the
|
||||||
// moment.
|
// moment.
|
||||||
|
|
||||||
/// Slow time weighting ~ 1 s
|
/// Slow time weighting ~ 1 s
|
||||||
Slow {},
|
Slow {},
|
||||||
/// Fast time weighting ~ 1/8 s
|
/// Fast time weighting ~ 1/8 s
|
||||||
@ -30,6 +31,15 @@ pub enum TimeWeighting {
|
|||||||
tdown: Flt,
|
tdown: Flt,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg_attr(feature = "python-bindings", pymethods)]
|
||||||
|
impl TimeWeighting {
|
||||||
|
// This method is still required in Pyo3 0.21, not anymore in 0.22
|
||||||
|
fn __eq__(&self, other: &Self) -> bool {
|
||||||
|
self == other
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Default for TimeWeighting {
|
impl Default for TimeWeighting {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
TimeWeighting::Fast {}
|
TimeWeighting::Fast {}
|
||||||
|
Loading…
Reference in New Issue
Block a user