Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/ezmsg/sigproc/butterworthfilter.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,13 @@ def butter_design_fun(

"""
coefs = None
if order > 0:
btype, cutoffs = ButterworthFilterSettings(order=order, cuton=cuton, cutoff=cutoff).filter_specs()
# order > 0 with neither corner set is a valid "no filter" request:
# filter_specs() returns None, which we treat as passthrough (coefs stays
# None -> the transformer returns the input unchanged) rather than crashing
# on an unpack of None.
specs = ButterworthFilterSettings(order=order, cuton=cuton, cutoff=cutoff).filter_specs()
if order > 0 and specs is not None:
btype, cutoffs = specs
coefs = scipy.signal.butter(
order,
Wn=cutoffs,
Expand Down
20 changes: 20 additions & 0 deletions tests/unit/test_butter.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,26 @@ def test_butterworth_empty_order0_passthrough():
check_empty_result(result)


def test_butterworth_order_no_corners_passthrough():
"""order > 0 with neither cuton nor cutoff is a valid "no filter" request.

Regression test: this used to crash in butter_design_fun on an unpack of
None from filter_specs(); now it designs no filter and passes data through.
"""
from ezmsg.sigproc.butterworthfilter import (
ButterworthFilterSettings,
ButterworthFilterTransformer,
butter_design_fun,
)

assert butter_design_fun(fs=1000.0, order=4) is None

proc = ButterworthFilterTransformer(ButterworthFilterSettings(order=4, axis="time"))
msg = make_msg()
result = proc(msg)
assert np.array_equal(result.data, msg.data)


def test_butterworth_empty_first():
from ezmsg.sigproc.butterworthfilter import ButterworthFilterSettings, ButterworthFilterTransformer

Expand Down
Loading