From f000da5aa4dd2f3cccdf5dc85831c8d6a4035ff1 Mon Sep 17 00:00:00 2001 From: Ehsan Olfat Date: Tue, 19 Mar 2024 16:09:47 -0400 Subject: [PATCH] linting is error free --- pyproject.toml | 2 +- tests/test_adaptive.py | 1 + tests/test_lattice.py | 1 + tests/test_levinson.py | 16 ++++++++++++---- tests/test_modeling.py | 16 ++++++++++++---- tests/test_optimal.py | 4 +++- tests/test_spectrum.py | 1 + tests/test_state.py | 2 ++ tests/test_system.py | 1 + 9 files changed, 34 insertions(+), 10 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 3787a60..65f44b7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -17,7 +17,7 @@ addopts = [ ] [tool.ruff] -include = ["ssp/**"] +include = ["ssp/**", "tests/**"] line-length = 100 indent-width = 4 diff --git a/tests/test_adaptive.py b/tests/test_adaptive.py index e69de29..570bd5c 100644 --- a/tests/test_adaptive.py +++ b/tests/test_adaptive.py @@ -0,0 +1 @@ +"""Test the adaptive module.""" diff --git a/tests/test_lattice.py b/tests/test_lattice.py index e69de29..97c1e48 100644 --- a/tests/test_lattice.py +++ b/tests/test_lattice.py @@ -0,0 +1 @@ +"""Test functions for the lattice module.""" diff --git a/tests/test_levinson.py b/tests/test_levinson.py index fca3ecc..3a43c82 100644 --- a/tests/test_levinson.py +++ b/tests/test_levinson.py @@ -3,14 +3,14 @@ import logging import numpy as np -from ssp import levinson +from ssp import levinson logger = logging.getLogger(__name__) def test_glev(): - '''Example 5.3.1, Page 266''' + """Example 5.3.1, Page 266.""" r = [4, 2, 1] b = [9, 6, 12] @@ -23,7 +23,7 @@ def test_glev(): def test_gtor() -> None: - '''Based on example 5.2.6''' + """Based on example 5.2.6.""" expected_rx = np.array([2, -1, -1/4, 1/8]) gamma = [1/2, 1/2, 1/2] @@ -33,7 +33,7 @@ def test_gtor() -> None: def test_atog() -> None: - + """The m-file for the step-down recursion.""" a = [1, 0.5, -0.1, -0.5] expected_g = np.array([0.5, 0.2, -0.5]) @@ -45,6 +45,11 @@ def test_atog() -> None: def test_rtog() -> None: + """Companion m-file. + + Performs mapping from a sequence of + autocorrelations r to the reflection coefficient g. + """ rx = [2, -1, -1/4, 1/8] expected_g = np.array([0.5, 0.5, 0.5]) @@ -56,6 +61,7 @@ def test_rtog() -> None: def test_ator() -> None: + """Finds the autocorrelation sequence from a set of filter coefficients.""" a = [1, 1, 7/8, 1/2] epsilon = 2 * (3 / 4)**3 b = epsilon**2 @@ -69,6 +75,7 @@ def test_ator() -> None: def test_gtoa() -> None: + """The step-up recursion.""" gamma = [0.5, 0.2, -0.5] expected_a = np.array([1, 0.5, -0.1, -0.5]) @@ -79,6 +86,7 @@ def test_gtoa() -> None: assert np.allclose(a, expected_a) def test_rtoa() -> None: + """m-file for the Levinson-Durbin recursion.""" rx = np.array([2, -1, -1/4, 1/8]) expected_a = [1, 1, 7/8, 1/2] expected_eps = 2 * (3 / 4)**3 diff --git a/tests/test_modeling.py b/tests/test_modeling.py index fed0d9d..43d177a 100644 --- a/tests/test_modeling.py +++ b/tests/test_modeling.py @@ -3,14 +3,15 @@ import logging import numpy as np -import scipy.signal as signal -from ssp import modeling, system +from scipy import signal +from ssp import modeling, system logger = logging.getLogger(__name__) def test_pade() -> None: + """Pade Approximation.""" x = [1, 1.5, 0.75, 0.1875, 0.0938] expected_a = [1, -1.5, 1.5] expected_b = [1] @@ -39,6 +40,7 @@ def test_pade() -> None: def test_prony(): + """Prony method.""" N = 21 T = 2 * (N - 1) + 1 xn = np.ones(T) @@ -49,6 +51,7 @@ def test_prony(): def test_shanks(): + """Shank's method.""" N = 21 T = 10 * (N - 1) + 1 xn = np.ones(T) @@ -66,6 +69,7 @@ def test_shanks(): def test_spike(): + """m-file to find the least squares inverse filter.""" gn = np.array([-0.2, 0, 1]) h, err = modeling.spike(gn, 4, 11) d = np.convolve(h, gn) @@ -74,10 +78,12 @@ def test_spike(): logger.info(f"{d=}, {np.argmax(d)=}") -def test_ipf(): ... +def test_ipf(): + """Iterative prefiltering.""" def test_acm(): + """m-file for the autocorrelation method.""" x = np.ones(20) x[1::2] = x[1::2] * -1 logger.info(x) @@ -88,6 +94,7 @@ def test_acm(): def test_covm(): + """Covariance method.""" x = np.ones(20) x[1::2] = x[1::2] * -1 logger.info(x) @@ -98,7 +105,8 @@ def test_covm(): def test_durbin(): - N = 64 + """Durbin's method.""" + #N = 64 ap = [1, 0.7348, 1.882, 0.7057, 0.8851] zeros, poles, _ = signal.tf2zpk([1], ap) diff --git a/tests/test_optimal.py b/tests/test_optimal.py index b82ed99..41890f9 100644 --- a/tests/test_optimal.py +++ b/tests/test_optimal.py @@ -1,10 +1,12 @@ -"""""" +"""Test optimal.""" import numpy as np + from ssp import optimal def test_kalman(): + """Discrete Kalman filter.""" av = 1 aw = 0.36 A = 0.8 diff --git a/tests/test_spectrum.py b/tests/test_spectrum.py index e69de29..af62d8c 100644 --- a/tests/test_spectrum.py +++ b/tests/test_spectrum.py @@ -0,0 +1 @@ +"""Spectrum.""" diff --git a/tests/test_state.py b/tests/test_state.py index 8f4b16f..6d874ed 100644 --- a/tests/test_state.py +++ b/tests/test_state.py @@ -7,6 +7,7 @@ def test_convm(): + """Set up a convoluston matrix.""" x = np.array([1, 2, 3]) p = 4 @@ -20,6 +21,7 @@ def test_convm(): def test_covar(): + """Form a covariance matrix.""" x = np.array([1, 2, 3]) p = 4 diff --git a/tests/test_system.py b/tests/test_system.py index e69de29..0c24e9f 100644 --- a/tests/test_system.py +++ b/tests/test_system.py @@ -0,0 +1 @@ +"""Discrete-time system."""