Skip to content

Commit

Permalink
linting is error free
Browse files Browse the repository at this point in the history
  • Loading branch information
ehsanolfat committed Mar 19, 2024
1 parent 6e3dde5 commit f000da5
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ addopts = [
]

[tool.ruff]
include = ["ssp/**"]
include = ["ssp/**", "tests/**"]

line-length = 100
indent-width = 4
Expand Down
1 change: 1 addition & 0 deletions tests/test_adaptive.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Test the adaptive module."""
1 change: 1 addition & 0 deletions tests/test_lattice.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Test functions for the lattice module."""
16 changes: 12 additions & 4 deletions tests/test_levinson.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand All @@ -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]
Expand All @@ -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])

Expand All @@ -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])

Expand All @@ -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
Expand All @@ -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])

Expand All @@ -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
Expand Down
16 changes: 12 additions & 4 deletions tests/test_modeling.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -39,6 +40,7 @@ def test_pade() -> None:


def test_prony():
"""Prony method."""
N = 21
T = 2 * (N - 1) + 1
xn = np.ones(T)
Expand All @@ -49,6 +51,7 @@ def test_prony():


def test_shanks():
"""Shank's method."""
N = 21
T = 10 * (N - 1) + 1
xn = np.ones(T)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion tests/test_optimal.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/test_spectrum.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Spectrum."""
2 changes: 2 additions & 0 deletions tests/test_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@


def test_convm():
"""Set up a convoluston matrix."""
x = np.array([1, 2, 3])
p = 4

Expand All @@ -20,6 +21,7 @@ def test_convm():


def test_covar():
"""Form a covariance matrix."""
x = np.array([1, 2, 3])
p = 4

Expand Down
1 change: 1 addition & 0 deletions tests/test_system.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Discrete-time system."""

0 comments on commit f000da5

Please sign in to comment.