initial commit
This commit is contained in:
0
tests/test_transform/__init__.py
Normal file
0
tests/test_transform/__init__.py
Normal file
BIN
tests/test_transform/__pycache__/__init__.cpython-312.pyc
Normal file
BIN
tests/test_transform/__pycache__/__init__.cpython-312.pyc
Normal file
Binary file not shown.
BIN
tests/test_transform/__pycache__/__init__.cpython-314.pyc
Normal file
BIN
tests/test_transform/__pycache__/__init__.cpython-314.pyc
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
49
tests/test_transform/test_align.py
Normal file
49
tests/test_transform/test_align.py
Normal file
@@ -0,0 +1,49 @@
|
||||
"""Tests for alignment transforms."""
|
||||
|
||||
import numpy as np
|
||||
import pytest
|
||||
|
||||
from impakt.transform.align import XAlign, YAlign, x_align, y_align
|
||||
|
||||
|
||||
class TestXAlign:
|
||||
def test_manual_shift(self, head_accel_x):
|
||||
shifted = x_align(head_accel_x, method="manual", reference_time=0.01)
|
||||
# Time should be shifted by -0.01s
|
||||
assert np.isclose(shifted.time[0], head_accel_x.time[0] - 0.01, atol=1e-10)
|
||||
|
||||
def test_threshold_shift(self, head_accel_x):
|
||||
shifted = XAlign(
|
||||
method="threshold",
|
||||
threshold_value=5.0,
|
||||
threshold_direction="abs",
|
||||
).apply(head_accel_x)
|
||||
# Time should be shifted so the first crossing of 5g is at t=0
|
||||
# The first crossing should be very close to t=0 in the shifted signal
|
||||
assert shifted.time[0] < 0 # Pre-trigger still negative
|
||||
|
||||
def test_trigger_noop(self, head_accel_x):
|
||||
shifted = x_align(head_accel_x, method="trigger")
|
||||
assert np.array_equal(shifted.time, head_accel_x.time)
|
||||
|
||||
|
||||
class TestYAlign:
|
||||
def test_default_baseline(self, head_accel_x):
|
||||
aligned = y_align(head_accel_x)
|
||||
# Pre-trigger region should be very close to zero
|
||||
pre_mask = aligned.time < 0
|
||||
if np.any(pre_mask):
|
||||
pre_mean = np.mean(aligned.data[pre_mask])
|
||||
assert abs(pre_mean) < 0.1 # Should be near zero
|
||||
|
||||
def test_explicit_window(self, head_accel_x):
|
||||
aligned = y_align(head_accel_x, window=(-0.01, 0.0))
|
||||
# Mean over the window should be approximately zero
|
||||
mask = (aligned.time >= -0.01) & (aligned.time <= 0.0)
|
||||
window_mean = np.mean(aligned.data[mask])
|
||||
assert abs(window_mean) < 0.1
|
||||
|
||||
def test_original_unchanged(self, head_accel_x):
|
||||
original = head_accel_x.data.copy()
|
||||
_ = y_align(head_accel_x)
|
||||
assert np.array_equal(head_accel_x.data, original)
|
||||
53
tests/test_transform/test_cfc.py
Normal file
53
tests/test_transform/test_cfc.py
Normal file
@@ -0,0 +1,53 @@
|
||||
"""Tests for CFC filtering."""
|
||||
|
||||
import numpy as np
|
||||
import pytest
|
||||
|
||||
from impakt.transform.cfc import CFCFilter, cfc_filter
|
||||
|
||||
|
||||
class TestCFCFilter:
|
||||
def test_cfc60(self, head_accel_x):
|
||||
filtered = cfc_filter(head_accel_x, 60)
|
||||
assert filtered.cfc_class == 60
|
||||
assert len(filtered.data) == len(head_accel_x.data)
|
||||
# Filtered signal should be smoother (lower peak)
|
||||
assert filtered.peak <= head_accel_x.peak
|
||||
# But still retain the general shape
|
||||
assert filtered.peak > 20.0 # Not completely killed
|
||||
|
||||
def test_cfc180(self, head_accel_x):
|
||||
filtered = cfc_filter(head_accel_x, 180)
|
||||
assert filtered.cfc_class == 180
|
||||
|
||||
def test_cfc600(self, head_accel_x):
|
||||
filtered = cfc_filter(head_accel_x, 600)
|
||||
assert filtered.cfc_class == 600
|
||||
|
||||
def test_cfc1000(self, head_accel_x):
|
||||
filtered = cfc_filter(head_accel_x, 1000)
|
||||
assert filtered.cfc_class == 1000
|
||||
# CFC 1000 removes very little — peak should be close to original
|
||||
assert abs(filtered.peak - head_accel_x.peak) < 5.0
|
||||
|
||||
def test_invalid_cfc_class(self):
|
||||
with pytest.raises(ValueError, match="Invalid CFC class"):
|
||||
CFCFilter(cfc_class=42)
|
||||
|
||||
def test_transform_history(self, head_accel_x):
|
||||
filtered = cfc_filter(head_accel_x, 180)
|
||||
assert len(filtered.transform_history) == 1
|
||||
assert "CFC 180" in filtered.transform_history[0]
|
||||
|
||||
def test_original_unchanged(self, head_accel_x):
|
||||
original_data = head_accel_x.data.copy()
|
||||
_ = cfc_filter(head_accel_x, 180)
|
||||
assert np.array_equal(head_accel_x.data, original_data)
|
||||
|
||||
def test_progressive_filtering(self, head_accel_x):
|
||||
"""Lower CFC classes should produce smoother (lower peak) output."""
|
||||
peak_1000 = cfc_filter(head_accel_x, 1000).peak
|
||||
peak_600 = cfc_filter(head_accel_x, 600).peak
|
||||
peak_180 = cfc_filter(head_accel_x, 180).peak
|
||||
peak_60 = cfc_filter(head_accel_x, 60).peak
|
||||
assert peak_1000 >= peak_600 >= peak_180 >= peak_60
|
||||
Reference in New Issue
Block a user