initial commit

This commit is contained in:
2026-04-10 14:37:34 -04:00
commit 9641dae687
601 changed files with 1633613 additions and 0 deletions

View File

View File

@@ -0,0 +1,55 @@
"""Tests for HIC calculation."""
import numpy as np
import pytest
from impakt.criteria.hic import hic, hic15, hic36
class TestHIC:
def test_hic15_computation(self, head_group):
result = hic(head_group, window_ms=15)
assert result.criterion == "HIC15"
assert result.value > 0
assert result.window is not None
t1, t2 = result.window
assert 0 <= (t2 - t1) <= 0.015 + 1e-6 # Window <= 15ms
def test_hic36_computation(self, head_group):
result = hic(head_group, window_ms=36)
assert result.criterion == "HIC36"
assert result.value > 0
def test_hic36_gte_hic15(self, head_group):
"""HIC36 should always be >= HIC15 (larger search window)."""
h15 = hic(head_group, window_ms=15)
h36 = hic(head_group, window_ms=36)
assert h36.value >= h15.value - 1e-6 # Small tolerance for numerical issues
def test_hic_from_single_channel(self, head_accel_x):
# Just X component as a simple test
result = hic(head_accel_x, window_ms=15)
assert result.value > 0
def test_hic_body_region(self, head_group):
result = hic(head_group, window_ms=15)
assert result.body_region == "Head"
def test_hic_details(self, head_group):
result = hic(head_group, window_ms=15)
assert "t1" in result.details
assert "t2" in result.details
assert "window_ms" in result.details
assert result.details["window_ms"] == 15
def test_hic15_convenience(self, head_group):
result = hic15(head_group)
assert result.criterion == "HIC15"
def test_hic36_convenience(self, head_group):
result = hic36(head_group)
assert result.criterion == "HIC36"
def test_invalid_window(self, head_group):
with pytest.raises(ValueError, match="15 or 36"):
hic(head_group, window_ms=20)

View File

@@ -0,0 +1,50 @@
"""Tests for Nij calculation."""
import pytest
from impakt.channel.model import DummyInfo
from impakt.criteria.nij import NIJ_INTERCEPTS, nij
class TestNij:
def test_nij_computation(self, neck_fz_channel, neck_my_channel):
result = nij(fz_channel=neck_fz_channel, my_channel=neck_my_channel)
assert result.criterion == "Nij"
assert result.value > 0
assert result.body_region == "Neck"
def test_nij_with_channels_dict(self, neck_fz_channel, neck_my_channel):
result = nij(channels={"fz": neck_fz_channel, "my": neck_my_channel})
assert result.value > 0
def test_nij_mode_detail(self, neck_fz_channel, neck_my_channel):
result = nij(fz_channel=neck_fz_channel, my_channel=neck_my_channel)
assert "mode" in result.details
assert result.details["mode"] in ("NTE", "NTF", "NCE", "NCF")
def test_nij_with_dummy_info(self, neck_fz_channel, neck_my_channel):
dummy = DummyInfo(dummy_type="H3-50M")
result = nij(
fz_channel=neck_fz_channel,
my_channel=neck_my_channel,
dummy=dummy,
)
assert result.value > 0
def test_nij_different_dummies_give_different_results(self, neck_fz_channel, neck_my_channel):
result_50m = nij(
fz_channel=neck_fz_channel,
my_channel=neck_my_channel,
dummy=DummyInfo(dummy_type="H3-50M"),
)
result_5f = nij(
fz_channel=neck_fz_channel,
my_channel=neck_my_channel,
dummy=DummyInfo(dummy_type="H3-05F"),
)
# 5th female has lower intercepts, so Nij should be higher
assert result_5f.value > result_50m.value
def test_nij_requires_both_channels(self):
with pytest.raises(ValueError, match="required"):
nij(fz_channel=None, my_channel=None)