ezmsg-sigproc 1.5.0__tar.gz → 1.6.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. {ezmsg_sigproc-1.5.0 → ezmsg_sigproc-1.6.0}/.github/workflows/python-tests.yml +1 -1
  2. {ezmsg_sigproc-1.5.0 → ezmsg_sigproc-1.6.0}/PKG-INFO +2 -2
  3. {ezmsg_sigproc-1.5.0 → ezmsg_sigproc-1.6.0}/pyproject.toml +1 -1
  4. {ezmsg_sigproc-1.5.0 → ezmsg_sigproc-1.6.0}/src/ezmsg/sigproc/__version__.py +2 -2
  5. {ezmsg_sigproc-1.5.0 → ezmsg_sigproc-1.6.0}/src/ezmsg/sigproc/activation.py +3 -2
  6. {ezmsg_sigproc-1.5.0 → ezmsg_sigproc-1.6.0}/src/ezmsg/sigproc/affinetransform.py +9 -8
  7. {ezmsg_sigproc-1.5.0 → ezmsg_sigproc-1.6.0}/src/ezmsg/sigproc/aggregate.py +7 -7
  8. {ezmsg_sigproc-1.5.0 → ezmsg_sigproc-1.6.0}/src/ezmsg/sigproc/bandpower.py +2 -2
  9. ezmsg_sigproc-1.6.0/src/ezmsg/sigproc/butterworthfilter.py +160 -0
  10. ezmsg_sigproc-1.6.0/src/ezmsg/sigproc/cheby.py +119 -0
  11. {ezmsg_sigproc-1.5.0 → ezmsg_sigproc-1.6.0}/src/ezmsg/sigproc/decimate.py +11 -15
  12. {ezmsg_sigproc-1.5.0 → ezmsg_sigproc-1.6.0}/src/ezmsg/sigproc/downsample.py +2 -2
  13. {ezmsg_sigproc-1.5.0 → ezmsg_sigproc-1.6.0}/src/ezmsg/sigproc/ewmfilter.py +10 -5
  14. ezmsg_sigproc-1.6.0/src/ezmsg/sigproc/filter.py +199 -0
  15. {ezmsg_sigproc-1.5.0 → ezmsg_sigproc-1.6.0}/src/ezmsg/sigproc/filterbank.py +6 -5
  16. {ezmsg_sigproc-1.5.0 → ezmsg_sigproc-1.6.0}/src/ezmsg/sigproc/math/abs.py +2 -1
  17. {ezmsg_sigproc-1.5.0 → ezmsg_sigproc-1.6.0}/src/ezmsg/sigproc/math/clip.py +2 -1
  18. {ezmsg_sigproc-1.5.0 → ezmsg_sigproc-1.6.0}/src/ezmsg/sigproc/math/difference.py +2 -1
  19. {ezmsg_sigproc-1.5.0 → ezmsg_sigproc-1.6.0}/src/ezmsg/sigproc/math/invert.py +2 -1
  20. {ezmsg_sigproc-1.5.0 → ezmsg_sigproc-1.6.0}/src/ezmsg/sigproc/math/log.py +2 -1
  21. {ezmsg_sigproc-1.5.0 → ezmsg_sigproc-1.6.0}/src/ezmsg/sigproc/math/scale.py +2 -1
  22. {ezmsg_sigproc-1.5.0 → ezmsg_sigproc-1.6.0}/src/ezmsg/sigproc/messages.py +1 -2
  23. {ezmsg_sigproc-1.5.0 → ezmsg_sigproc-1.6.0}/src/ezmsg/sigproc/sampler.py +10 -14
  24. ezmsg_sigproc-1.6.0/src/ezmsg/sigproc/scaler.py +290 -0
  25. {ezmsg_sigproc-1.5.0 → ezmsg_sigproc-1.6.0}/src/ezmsg/sigproc/signalinjector.py +8 -7
  26. {ezmsg_sigproc-1.5.0 → ezmsg_sigproc-1.6.0}/src/ezmsg/sigproc/slicer.py +6 -6
  27. {ezmsg_sigproc-1.5.0 → ezmsg_sigproc-1.6.0}/src/ezmsg/sigproc/spectrogram.py +6 -6
  28. {ezmsg_sigproc-1.5.0 → ezmsg_sigproc-1.6.0}/src/ezmsg/sigproc/spectrum.py +11 -11
  29. {ezmsg_sigproc-1.5.0 → ezmsg_sigproc-1.6.0}/src/ezmsg/sigproc/synth.py +24 -23
  30. {ezmsg_sigproc-1.5.0 → ezmsg_sigproc-1.6.0}/src/ezmsg/sigproc/wavelets.py +39 -15
  31. {ezmsg_sigproc-1.5.0 → ezmsg_sigproc-1.6.0}/src/ezmsg/sigproc/window.py +12 -12
  32. {ezmsg_sigproc-1.5.0 → ezmsg_sigproc-1.6.0}/tests/helpers/util.py +4 -5
  33. {ezmsg_sigproc-1.5.0 → ezmsg_sigproc-1.6.0}/tests/test_butter.py +6 -7
  34. {ezmsg_sigproc-1.5.0 → ezmsg_sigproc-1.6.0}/tests/test_butterworth.py +2 -5
  35. ezmsg_sigproc-1.6.0/tests/test_decimate.py +59 -0
  36. {ezmsg_sigproc-1.5.0 → ezmsg_sigproc-1.6.0}/tests/test_downsample.py +2 -5
  37. ezmsg_sigproc-1.6.0/tests/test_filter_system.py +117 -0
  38. {ezmsg_sigproc-1.5.0 → ezmsg_sigproc-1.6.0}/tests/test_sampler.py +2 -3
  39. ezmsg_sigproc-1.6.0/tests/test_scaler.py +150 -0
  40. {ezmsg_sigproc-1.5.0 → ezmsg_sigproc-1.6.0}/tests/test_spectrogram.py +1 -4
  41. {ezmsg_sigproc-1.5.0 → ezmsg_sigproc-1.6.0}/tests/test_spectrum.py +2 -3
  42. {ezmsg_sigproc-1.5.0 → ezmsg_sigproc-1.6.0}/tests/test_synth.py +14 -15
  43. {ezmsg_sigproc-1.5.0 → ezmsg_sigproc-1.6.0}/tests/test_wavelets.py +39 -34
  44. {ezmsg_sigproc-1.5.0 → ezmsg_sigproc-1.6.0}/tests/test_window.py +8 -8
  45. {ezmsg_sigproc-1.5.0 → ezmsg_sigproc-1.6.0}/uv.lock +2 -57
  46. ezmsg_sigproc-1.5.0/src/ezmsg/sigproc/butterworthfilter.py +0 -162
  47. ezmsg_sigproc-1.5.0/src/ezmsg/sigproc/filter.py +0 -232
  48. ezmsg_sigproc-1.5.0/src/ezmsg/sigproc/scaler.py +0 -172
  49. ezmsg_sigproc-1.5.0/tests/test_scaler.py +0 -132
  50. {ezmsg_sigproc-1.5.0 → ezmsg_sigproc-1.6.0}/.github/workflows/python-publish-ezmsg-sigproc.yml +0 -0
  51. {ezmsg_sigproc-1.5.0 → ezmsg_sigproc-1.6.0}/.gitignore +0 -0
  52. {ezmsg_sigproc-1.5.0 → ezmsg_sigproc-1.6.0}/.pre-commit-config.yaml +0 -0
  53. {ezmsg_sigproc-1.5.0 → ezmsg_sigproc-1.6.0}/LICENSE.txt +0 -0
  54. {ezmsg_sigproc-1.5.0 → ezmsg_sigproc-1.6.0}/README.md +0 -0
  55. {ezmsg_sigproc-1.5.0 → ezmsg_sigproc-1.6.0}/src/ezmsg/sigproc/__init__.py +0 -0
  56. {ezmsg_sigproc-1.5.0 → ezmsg_sigproc-1.6.0}/src/ezmsg/sigproc/base.py +0 -0
  57. {ezmsg_sigproc-1.5.0 → ezmsg_sigproc-1.6.0}/src/ezmsg/sigproc/math/__init__.py +0 -0
  58. {ezmsg_sigproc-1.5.0 → ezmsg_sigproc-1.6.0}/src/ezmsg/sigproc/spectral.py +0 -0
  59. {ezmsg_sigproc-1.5.0 → ezmsg_sigproc-1.6.0}/tests/conftest.py +0 -0
  60. {ezmsg_sigproc-1.5.0 → ezmsg_sigproc-1.6.0}/tests/helpers/__init__.py +0 -0
  61. {ezmsg_sigproc-1.5.0 → ezmsg_sigproc-1.6.0}/tests/resources/xform.csv +0 -0
  62. {ezmsg_sigproc-1.5.0 → ezmsg_sigproc-1.6.0}/tests/test_activation.py +0 -0
  63. {ezmsg_sigproc-1.5.0 → ezmsg_sigproc-1.6.0}/tests/test_affine_transform.py +0 -0
  64. {ezmsg_sigproc-1.5.0 → ezmsg_sigproc-1.6.0}/tests/test_aggregate.py +0 -0
  65. {ezmsg_sigproc-1.5.0 → ezmsg_sigproc-1.6.0}/tests/test_bandpower.py +0 -0
  66. {ezmsg_sigproc-1.5.0 → ezmsg_sigproc-1.6.0}/tests/test_filterbank.py +0 -0
  67. {ezmsg_sigproc-1.5.0 → ezmsg_sigproc-1.6.0}/tests/test_math.py +0 -0
  68. {ezmsg_sigproc-1.5.0 → ezmsg_sigproc-1.6.0}/tests/test_slicer.py +0 -0
@@ -13,7 +13,7 @@ jobs:
13
13
  build:
14
14
  strategy:
15
15
  matrix:
16
- python-version: [3.9, "3.10", "3.11", "3.12"]
16
+ python-version: ["3.10", "3.11", "3.12"]
17
17
  os:
18
18
  - "ubuntu-latest"
19
19
  - "windows-latest"
@@ -1,10 +1,10 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: ezmsg-sigproc
3
- Version: 1.5.0
3
+ Version: 1.6.0
4
4
  Summary: Timeseries signal processing implementations in ezmsg
5
5
  Author-email: Griffin Milsap <griffin.milsap@gmail.com>, Preston Peranich <pperanich@gmail.com>, Chadwick Boulay <chadwick.boulay@gmail.com>
6
6
  License: MIT
7
- Requires-Python: >=3.9
7
+ Requires-Python: >=3.10.15
8
8
  Requires-Dist: ezmsg>=3.6.0
9
9
  Requires-Dist: numpy>=1.26.0
10
10
  Requires-Dist: pywavelets>=1.6.0
@@ -8,7 +8,7 @@ authors = [
8
8
  ]
9
9
  license = "MIT"
10
10
  readme = "README.md"
11
- requires-python = ">=3.9"
11
+ requires-python = ">=3.10.15"
12
12
  dynamic = ["version"]
13
13
  dependencies = [
14
14
  "ezmsg>=3.6.0",
@@ -12,5 +12,5 @@ __version__: str
12
12
  __version_tuple__: VERSION_TUPLE
13
13
  version_tuple: VERSION_TUPLE
14
14
 
15
- __version__ = version = '1.5.0'
16
- __version_tuple__ = version_tuple = (1, 5, 0)
15
+ __version__ = version = '1.6.0'
16
+ __version_tuple__ = version_tuple = (1, 6, 0)
@@ -3,7 +3,8 @@ import typing
3
3
  import numpy as np
4
4
  import scipy.special
5
5
  import ezmsg.core as ez
6
- from ezmsg.util.messages.axisarray import AxisArray, replace
6
+ from ezmsg.util.messages.axisarray import AxisArray
7
+ from ezmsg.util.messages.util import replace
7
8
  from ezmsg.util.generator import consumer
8
9
 
9
10
  from .spectral import OptionsEnum
@@ -40,7 +41,7 @@ ACTIVATIONS = {
40
41
 
41
42
  @consumer
42
43
  def activation(
43
- function: typing.Union[str, ActivationFunction],
44
+ function: str | ActivationFunction,
44
45
  ) -> typing.Generator[AxisArray, AxisArray, None]:
45
46
  """
46
47
  Transform the data with a simple activation function.
@@ -5,7 +5,8 @@ import typing
5
5
  import numpy as np
6
6
  import numpy.typing as npt
7
7
  import ezmsg.core as ez
8
- from ezmsg.util.messages.axisarray import AxisArray, AxisBase, replace
8
+ from ezmsg.util.messages.axisarray import AxisArray, AxisBase
9
+ from ezmsg.util.messages.util import replace
9
10
  from ezmsg.util.generator import consumer
10
11
 
11
12
  from .base import GenAxisArray
@@ -13,8 +14,8 @@ from .base import GenAxisArray
13
14
 
14
15
  @consumer
15
16
  def affine_transform(
16
- weights: typing.Union[np.ndarray, str, Path],
17
- axis: typing.Optional[str] = None,
17
+ weights: np.ndarray | str | Path,
18
+ axis: str | None = None,
18
19
  right_multiply: bool = True,
19
20
  ) -> typing.Generator[AxisArray, AxisArray, None]:
20
21
  """
@@ -46,7 +47,7 @@ def affine_transform(
46
47
 
47
48
  # State variables
48
49
  # New axis with transformed labels, if required
49
- new_axis: typing.Optional[AxisBase] = None
50
+ new_axis: AxisBase | None = None
50
51
 
51
52
  # Reset if any of these change.
52
53
  check_input = {"key": None}
@@ -132,8 +133,8 @@ class AffineTransformSettings(ez.Settings):
132
133
  See :obj:`affine_transform` for argument details.
133
134
  """
134
135
 
135
- weights: typing.Union[np.ndarray, str, Path]
136
- axis: typing.Optional[str] = None
136
+ weights: np.ndarray | str | Path
137
+ axis: str | None = None
137
138
  right_multiply: bool = True
138
139
 
139
140
 
@@ -156,7 +157,7 @@ def zeros_for_noop(data: npt.NDArray, **ignore_kwargs) -> npt.NDArray:
156
157
 
157
158
  @consumer
158
159
  def common_rereference(
159
- mode: str = "mean", axis: typing.Optional[str] = None, include_current: bool = True
160
+ mode: str = "mean", axis: str | None = None, include_current: bool = True
160
161
  ) -> typing.Generator[AxisArray, AxisArray, None]:
161
162
  """
162
163
  Perform common average referencing (CAR) on streaming data.
@@ -213,7 +214,7 @@ class CommonRereferenceSettings(ez.Settings):
213
214
  """
214
215
 
215
216
  mode: str = "mean"
216
- axis: typing.Optional[str] = None
217
+ axis: str | None = None
217
218
  include_current: bool = True
218
219
 
219
220
 
@@ -56,8 +56,8 @@ AGGREGATORS = {
56
56
 
57
57
  @consumer
58
58
  def ranged_aggregate(
59
- axis: typing.Optional[str] = None,
60
- bands: typing.Optional[typing.List[typing.Tuple[float, float]]] = None,
59
+ axis: str | None = None,
60
+ bands: list[tuple[float, float]] | None = None,
61
61
  operation: AggregationFunction = AggregationFunction.MEAN,
62
62
  ):
63
63
  """
@@ -75,9 +75,9 @@ def ranged_aggregate(
75
75
  msg_out = AxisArray(np.array([]), dims=[""])
76
76
 
77
77
  # State variables
78
- slices: typing.Optional[typing.List[typing.Tuple[typing.Any, ...]]] = None
79
- out_axis: typing.Optional[AxisBase] = None
80
- ax_vec: typing.Optional[npt.NDArray] = None
78
+ slices: list[tuple[typing.Any, ...]] | None = None
79
+ out_axis: AxisBase | None = None
80
+ ax_vec: npt.NDArray | None = None
81
81
 
82
82
  # Reset if any of these changes. Key not checked because continuity between chunks not required.
83
83
  check_inputs = {"gain": None, "offset": None, "len": None, "key": None}
@@ -163,8 +163,8 @@ class RangedAggregateSettings(ez.Settings):
163
163
  See :obj:`ranged_aggregate` for details.
164
164
  """
165
165
 
166
- axis: typing.Optional[str] = None
167
- bands: typing.Optional[typing.List[typing.Tuple[float, float]]] = None
166
+ axis: str | None = None
167
+ bands: list[tuple[float, float]] | None = None
168
168
  operation: AggregationFunction = AggregationFunction.MEAN
169
169
 
170
170
 
@@ -14,7 +14,7 @@ from .base import GenAxisArray
14
14
  @consumer
15
15
  def bandpower(
16
16
  spectrogram_settings: SpectrogramSettings,
17
- bands: typing.Optional[typing.List[typing.Tuple[float, float]]] = [
17
+ bands: list[tuple[float, float]] | None = [
18
18
  (17, 30),
19
19
  (70, 170),
20
20
  ],
@@ -58,7 +58,7 @@ class BandPowerSettings(ez.Settings):
58
58
  spectrogram_settings: SpectrogramSettings = field(
59
59
  default_factory=SpectrogramSettings
60
60
  )
61
- bands: typing.Optional[typing.List[typing.Tuple[float, float]]] = field(
61
+ bands: list[tuple[float, float]] | None = field(
62
62
  default_factory=lambda: [(17, 30), (70, 170)]
63
63
  )
64
64
 
@@ -0,0 +1,160 @@
1
+ import functools
2
+ import typing
3
+
4
+ import scipy.signal
5
+ from ezmsg.util.messages.axisarray import AxisArray
6
+ from scipy.signal import normalize
7
+
8
+ from .filter import (
9
+ FilterBaseSettings,
10
+ FilterCoefsMultiType,
11
+ FilterBase,
12
+ filter_gen_by_design,
13
+ )
14
+
15
+
16
+ class ButterworthFilterSettings(FilterBaseSettings):
17
+ """Settings for :obj:`ButterworthFilter`."""
18
+
19
+ order: int = 0
20
+ """
21
+ Filter order
22
+ """
23
+
24
+ cuton: float | None = None
25
+ """
26
+ Cuton frequency (Hz). If `cutoff` is not specified then this is the highpass corner. Otherwise,
27
+ if this is lower than `cutoff` then this is the beginning of the bandpass
28
+ or if this is greater than `cutoff` then this is the end of the bandstop.
29
+ """
30
+
31
+ cutoff: float | None = None
32
+ """
33
+ Cutoff frequency (Hz). If `cuton` is not specified then this is the lowpass corner. Otherwise,
34
+ if this is greater than `cuton` then this is the end of the bandpass,
35
+ or if this is less than `cuton` then this is the beginning of the bandstop.
36
+ """
37
+
38
+ wn_hz: bool = True
39
+ """
40
+ Set False if provided Wn are normalized from 0 to 1, where 1 is the Nyquist frequency
41
+ """
42
+
43
+ def filter_specs(
44
+ self,
45
+ ) -> tuple[str, float | tuple[float, float]] | None:
46
+ """
47
+ Determine the filter type given the corner frequencies.
48
+
49
+ Returns:
50
+ A tuple with the first element being a string indicating the filter type
51
+ (one of "lowpass", "highpass", "bandpass", "bandstop")
52
+ and the second element being the corner frequency or frequencies.
53
+
54
+ """
55
+ if self.cuton is None and self.cutoff is None:
56
+ return None
57
+ elif self.cuton is None and self.cutoff is not None:
58
+ return "lowpass", self.cutoff
59
+ elif self.cuton is not None and self.cutoff is None:
60
+ return "highpass", self.cuton
61
+ elif self.cuton is not None and self.cutoff is not None:
62
+ if self.cuton <= self.cutoff:
63
+ return "bandpass", (self.cuton, self.cutoff)
64
+ else:
65
+ return "bandstop", (self.cutoff, self.cuton)
66
+
67
+
68
+ def butter_design_fun(
69
+ fs: float,
70
+ order: int = 0,
71
+ cuton: float | None = None,
72
+ cutoff: float | None = None,
73
+ coef_type: str = "ba",
74
+ wn_hz: bool = True,
75
+ ) -> FilterCoefsMultiType | None:
76
+ """
77
+ See :obj:`ButterworthFilterSettings.filter_specs` for an explanation of specifying different
78
+ filter types (lowpass, highpass, bandpass, bandstop) from the parameters.
79
+ You are likely to want to use this function with :obj:`filter_by_design`, which only passes `fs` to the design
80
+ function (this), meaning that you should wrap this function with a lambda or prepare with functools.partial.
81
+
82
+ Args:
83
+ fs: The sampling frequency of the data in Hz.
84
+ order: Filter order.
85
+ cuton: Corner frequency of the filter in Hz.
86
+ cutoff: Corner frequency of the filter in Hz.
87
+ coef_type: "ba", "sos", or "zpk"
88
+ wn_hz: Set False if provided Wn are normalized from 0 to 1, where 1 is the Nyquist frequency
89
+
90
+ Returns:
91
+ The filter coefficients as a tuple of (b, a) for coef_type "ba", or as a single ndarray for "sos",
92
+ or (z, p, k) for "zpk".
93
+
94
+ """
95
+ coefs = None
96
+ if order > 0:
97
+ btype, cutoffs = ButterworthFilterSettings(
98
+ order=order, cuton=cuton, cutoff=cutoff
99
+ ).filter_specs()
100
+ coefs = scipy.signal.butter(
101
+ order,
102
+ Wn=cutoffs,
103
+ btype=btype,
104
+ fs=fs if wn_hz else None,
105
+ output=coef_type,
106
+ )
107
+ if coefs is not None and coef_type == "ba":
108
+ coefs = normalize(*coefs)
109
+ return coefs
110
+
111
+
112
+ class ButterworthFilter(FilterBase):
113
+ SETTINGS = ButterworthFilterSettings
114
+
115
+ def design_filter(
116
+ self,
117
+ ) -> typing.Callable[[float], FilterCoefsMultiType | None]:
118
+ return functools.partial(
119
+ butter_design_fun,
120
+ order=self.SETTINGS.order,
121
+ cuton=self.SETTINGS.cuton,
122
+ cutoff=self.SETTINGS.cutoff,
123
+ coef_type=self.SETTINGS.coef_type,
124
+ )
125
+
126
+
127
+ def butter(
128
+ axis: str | None,
129
+ order: int = 0,
130
+ cuton: float | None = None,
131
+ cutoff: float | None = None,
132
+ coef_type: str = "ba",
133
+ ) -> typing.Generator[AxisArray, AxisArray, None]:
134
+ """
135
+ Convenience generator wrapping filter_gen_by_design for Butterworth filters.
136
+ Apply Butterworth filter to streaming data. Uses :obj:`scipy.signal.butter` to design the filter.
137
+ See :obj:`ButterworthFilterSettings.filter_specs` for an explanation of specifying different
138
+ filter types (lowpass, highpass, bandpass, bandstop) from the parameters.
139
+
140
+ Args:
141
+ axis: The name of the axis to filter.
142
+ Note: The axis must be represented in the message .axes and be of type AxisArray.LinearAxis.
143
+ order: Filter order.
144
+ cuton: Corner frequency of the filter in Hz.
145
+ cutoff: Corner frequency of the filter in Hz.
146
+ coef_type: "ba" or "sos"
147
+
148
+ Returns:
149
+ A primed generator object which accepts an :obj:`AxisArray` via .send(axis_array)
150
+ and yields an :obj:`AxisArray` with filtered data.
151
+
152
+ """
153
+ design_fun = functools.partial(
154
+ butter_design_fun,
155
+ order=order,
156
+ cuton=cuton,
157
+ cutoff=cutoff,
158
+ coef_type=coef_type,
159
+ )
160
+ return filter_gen_by_design(axis, coef_type, design_fun)
@@ -0,0 +1,119 @@
1
+ import functools
2
+ import typing
3
+
4
+ import scipy.signal
5
+ from scipy.signal import normalize
6
+
7
+ from .filter import (
8
+ FilterBaseSettings,
9
+ FilterCoefsMultiType,
10
+ FilterBase,
11
+ )
12
+
13
+
14
+ class ChebyshevFilterSettings(FilterBaseSettings):
15
+ """Settings for :obj:`ButterworthFilter`."""
16
+
17
+ order: int = 0
18
+ """
19
+ Filter order
20
+ """
21
+
22
+ ripple_tol: float | None = None
23
+ """
24
+ The maximum ripple allowed below unity gain in the passband. Specified in decibels, as a positive number.
25
+ """
26
+
27
+ Wn: float | tuple[float, float] | None = None
28
+ """
29
+ A scalar or length-2 sequence giving the critical frequencies.
30
+ For Type I filters, this is the point in the transition band at which the gain first drops below -rp.
31
+ For digital filters, Wn are in the same units as fs unless wn_hz is False.
32
+ For analog filters, Wn is an angular frequency (e.g., rad/s).
33
+ """
34
+
35
+ btype: str = "lowpass"
36
+ """
37
+ {‘lowpass’, ‘highpass’, ‘bandpass’, ‘bandstop’}
38
+ """
39
+
40
+ analog: bool = False
41
+ """
42
+ When True, return an analog filter, otherwise a digital filter is returned.
43
+ """
44
+
45
+ cheby_type: str = "cheby1"
46
+ """
47
+ Which type of Chebyshev filter to design. Either "cheby1" or "cheby2".
48
+ """
49
+
50
+ wn_hz: bool = True
51
+ """
52
+ Set False if provided Wn are normalized from 0 to 1, where 1 is the Nyquist frequency
53
+ """
54
+
55
+
56
+ def cheby_design_fun(
57
+ fs: float,
58
+ order: int = 0,
59
+ ripple_tol: float | None = None,
60
+ Wn: float | tuple[float, float] | None = None,
61
+ btype: str = "lowpass",
62
+ analog: bool = False,
63
+ coef_type: str = "ba",
64
+ cheby_type: str = "cheby1",
65
+ wn_hz: bool = True,
66
+ ) -> FilterCoefsMultiType:
67
+ """
68
+ Chebyshev type I and type II digital and analog filter design.
69
+ Design an `order`th-order digital or analog Chebyshev type I or type II filter and return the filter coefficients.
70
+ See :obj:`ChebyFilterSettings` for argument description.
71
+
72
+ Returns:
73
+ The filter coefficients as a tuple of (b, a) for coef_type "ba", or as a single ndarray for "sos",
74
+ or (z, p, k) for "zpk".
75
+ """
76
+ coefs = None
77
+ if order > 0:
78
+ if cheby_type == "cheby1":
79
+ coefs = scipy.signal.cheby1(
80
+ order,
81
+ ripple_tol,
82
+ Wn,
83
+ btype=btype,
84
+ analog=analog,
85
+ output=coef_type,
86
+ fs=fs if wn_hz else None,
87
+ )
88
+ elif cheby_type == "cheby2":
89
+ coefs = scipy.signal.cheby2(
90
+ order,
91
+ ripple_tol,
92
+ Wn,
93
+ btype=btype,
94
+ analog=analog,
95
+ output=coef_type,
96
+ fs=fs,
97
+ )
98
+ if coefs is not None and coef_type == "ba":
99
+ coefs = normalize(*coefs)
100
+ return coefs
101
+
102
+
103
+ class ChebyshevFilter(FilterBase):
104
+ SETTINGS = ChebyshevFilterSettings
105
+
106
+ def design_filter(
107
+ self,
108
+ ) -> typing.Callable[[float], FilterCoefsMultiType | None]:
109
+ return functools.partial(
110
+ cheby_design_fun,
111
+ order=self.SETTINGS.order,
112
+ ripple_tol=self.SETTINGS.ripple_tol,
113
+ Wn=self.SETTINGS.Wn,
114
+ btype=self.SETTINGS.btype,
115
+ analog=self.SETTINGS.analog,
116
+ coef_type=self.SETTINGS.coef_type,
117
+ cheby_type=self.SETTINGS.cheby_type,
118
+ wn_hz=self.SETTINGS.wn_hz,
119
+ )
@@ -1,9 +1,8 @@
1
- import scipy.signal
2
1
  import ezmsg.core as ez
3
2
  from ezmsg.util.messages.axisarray import AxisArray
4
3
 
4
+ from .cheby import ChebyshevFilter, ChebyshevFilterSettings
5
5
  from .downsample import Downsample, DownsampleSettings
6
- from .filter import Filter, FilterCoefficients, FilterSettings
7
6
 
8
7
 
9
8
  class Decimate(ez.Collection):
@@ -17,24 +16,21 @@ class Decimate(ez.Collection):
17
16
  INPUT_SIGNAL = ez.InputStream(AxisArray)
18
17
  OUTPUT_SIGNAL = ez.OutputStream(AxisArray)
19
18
 
20
- FILTER = Filter()
19
+ FILTER = ChebyshevFilter()
21
20
  DOWNSAMPLE = Downsample()
22
21
 
23
22
  def configure(self) -> None:
23
+ cheby_settings = ChebyshevFilterSettings(
24
+ order=8 if self.SETTINGS.factor > 1 else 0,
25
+ ripple_tol=0.05,
26
+ Wn=0.8 / self.SETTINGS.factor if self.SETTINGS.factor > 1 else None,
27
+ btype="lowpass",
28
+ axis=self.SETTINGS.axis,
29
+ wn_hz=False,
30
+ )
31
+ self.FILTER.apply_settings(cheby_settings)
24
32
  self.DOWNSAMPLE.apply_settings(self.SETTINGS)
25
33
 
26
- if self.SETTINGS.factor < 1:
27
- raise ValueError("Decimation factor must be >= 1 (no decimation")
28
- elif self.SETTINGS.factor == 1:
29
- filt = FilterCoefficients()
30
- else:
31
- # See scipy.signal.decimate for IIR Filter Condition
32
- b, a = scipy.signal.cheby1(8, 0.05, 0.8 / self.SETTINGS.factor)
33
- system = scipy.signal.dlti(b, a)
34
- filt = FilterCoefficients(b=system.num, a=system.den) # type: ignore
35
-
36
- self.FILTER.apply_settings(FilterSettings(filt=filt))
37
-
38
34
  def network(self) -> ez.NetworkDefinition:
39
35
  return (
40
36
  (self.INPUT_SIGNAL, self.FILTER.INPUT_SIGNAL),
@@ -14,7 +14,7 @@ from .base import GenAxisArray
14
14
 
15
15
  @consumer
16
16
  def downsample(
17
- axis: typing.Optional[str] = None, factor: int = 1
17
+ axis: str | None = None, factor: int = 1
18
18
  ) -> typing.Generator[AxisArray, AxisArray, None]:
19
19
  """
20
20
  Construct a generator that yields a downsampled version of the data .send() to it.
@@ -96,7 +96,7 @@ class DownsampleSettings(ez.Settings):
96
96
  See :obj:`downsample` documentation for a description of the parameters.
97
97
  """
98
98
 
99
- axis: typing.Optional[str] = None
99
+ axis: str | None = None
100
100
  factor: int = 1
101
101
 
102
102
 
@@ -2,14 +2,15 @@ import asyncio
2
2
  import typing
3
3
 
4
4
  import ezmsg.core as ez
5
- from ezmsg.util.messages.axisarray import AxisArray, replace
5
+ from ezmsg.util.messages.axisarray import AxisArray
6
+ from ezmsg.util.messages.util import replace
6
7
  import numpy as np
7
8
 
8
9
  from .window import Window, WindowSettings
9
10
 
10
11
 
11
12
  class EWMSettings(ez.Settings):
12
- axis: typing.Optional[str] = None
13
+ axis: str | None = None
13
14
  """Name of the axis to accumulate."""
14
15
 
15
16
  zero_offset: bool = True
@@ -23,7 +24,8 @@ class EWMState(ez.State):
23
24
 
24
25
  class EWM(ez.Unit):
25
26
  """
26
- Exponentially Weighted Moving Average Standardization
27
+ Exponentially Weighted Moving Average Standardization.
28
+ This is deprecated. Please use :obj:`ezmsg.sigproc.scaler.AdaptiveStandardScaler` instead.
27
29
 
28
30
  References https://stackoverflow.com/a/42926270
29
31
  """
@@ -36,6 +38,9 @@ class EWM(ez.Unit):
36
38
  OUTPUT_SIGNAL = ez.OutputStream(AxisArray)
37
39
 
38
40
  async def initialize(self) -> None:
41
+ ez.logger.warning(
42
+ "EWM/EWMFilter is deprecated and will be removed in a future version. Use AdaptiveStandardScaler instead."
43
+ )
39
44
  self.STATE.signal_queue = asyncio.Queue()
40
45
  self.STATE.buffer_queue = asyncio.Queue()
41
46
 
@@ -99,7 +104,7 @@ class EWMFilterSettings(ez.Settings):
99
104
  history_dur: float
100
105
  """Previous data to accumulate for standardization."""
101
106
 
102
- axis: typing.Optional[str] = None
107
+ axis: str | None = None
103
108
  """Name of the axis to accumulate."""
104
109
 
105
110
  zero_offset: bool = True
@@ -112,7 +117,7 @@ class EWMFilter(ez.Collection):
112
117
  leads to :obj:`Window` which then feeds into :obj:`EWM` 's INPUT_BUFFER
113
118
  and another branch that feeds directly into :obj:`EWM` 's INPUT_SIGNAL.
114
119
 
115
- Consider :obj:`scaler` for a more efficient alternative.
120
+ This is deprecated. Please use :obj:`ezmsg.sigproc.scaler.AdaptiveStandardScaler` instead.
116
121
  """
117
122
 
118
123
  SETTINGS = EWMFilterSettings