32 lines
1.3 KiB
Python
32 lines
1.3 KiB
Python
import numpy as np
|
|
from sfm.shape_metrics import channel_shape, shape_from_samples
|
|
|
|
def test_needle_spike_high_crest_few_near_peak():
|
|
x = np.zeros(1024); x[500] = 1.0 # one isolated spike
|
|
s = channel_shape(x)
|
|
assert s["sample_count"] == 1024
|
|
assert s["crest_factor"] > 15 # peak towers over rms
|
|
assert s["near_peak_count"] <= 3 # almost nothing near the peak
|
|
|
|
def test_ringing_low_crest_many_near_peak():
|
|
t = np.arange(1024)
|
|
x = np.sin(2*np.pi*t/32) * np.exp(-t/4000) # decaying oscillation
|
|
s = channel_shape(x)
|
|
assert s["crest_factor"] < 6
|
|
assert s["near_peak_count"] > 30 # many samples near the peak
|
|
|
|
def test_channel_shape_none_for_unusable():
|
|
assert channel_shape(np.zeros(1024)) is None # flat / all-zero
|
|
assert channel_shape(np.array([1.0])) is None # too short
|
|
|
|
def test_shape_from_samples_picks_max_peak_axis():
|
|
chans = {"Tran": np.zeros(1024), "Vert": np.zeros(1024), "Long": np.zeros(1024)}
|
|
chans["Long"][10] = 0.5
|
|
chans["Vert"] = np.sin(np.arange(1024)/5) * 0.01
|
|
s = shape_from_samples(chans)
|
|
assert s["axis"] == "Long" # Long has the biggest peak
|
|
assert s["near_peak_count"] <= 3
|
|
|
|
def test_shape_from_samples_none_when_no_geo():
|
|
assert shape_from_samples({"MicL": np.ones(1024)}) is None
|