diff --git a/tests/test_shape_metrics_h5.py b/tests/test_shape_metrics_h5.py new file mode 100644 index 0000000..c601675 --- /dev/null +++ b/tests/test_shape_metrics_h5.py @@ -0,0 +1,22 @@ +import numpy as np, h5py +from sfm.shape_metrics import shape_from_h5 + +def _write_h5(path, chans): + with h5py.File(path, "w") as f: + g = f.create_group("samples") + for k, v in chans.items(): + g.create_dataset(k, data=np.asarray(v, dtype="float32")) + +def test_shape_from_h5_reads_dominant_axis(tmp_path): + p = tmp_path / "ev.h5" + long = np.zeros(1024, dtype="float32"); long[100] = 0.48 + _write_h5(p, {"Tran": np.zeros(1024), "Vert": np.zeros(1024), "Long": long, + "MicL": np.ones(1024)}) + s = shape_from_h5(str(p)) + assert s["axis"] == "Long" and s["near_peak_count"] <= 3 + +def test_shape_from_h5_none_on_missing_or_degenerate(tmp_path): + assert shape_from_h5(str(tmp_path / "nope.h5")) is None + p = tmp_path / "degen.h5" + _write_h5(p, {"Tran": np.zeros(1), "Vert": np.zeros(1), "Long": np.zeros(1)}) + assert shape_from_h5(str(p)) is None