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
2 changes: 1 addition & 1 deletion src/giant_python/extraction/raster/solver_baseline.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def _shorth_center(vals: np.ndarray) -> float | None:
return None
s = np.sort(vals)
m = max(n // 2, 1)
idx = int(np.argmin(s[m:] - s[:-m]))
idx = int(np.argmin(s[m - 1 :] - s[: n - m + 1]))
return float(np.median(s[idx : idx + m]))


Expand Down
19 changes: 19 additions & 0 deletions tests/raster/test_raster_variance_interp.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,3 +497,22 @@ def test_apply_trial_sd_finv_and_discard_masked_read_varfac(tmp_path):
np.testing.assert_allclose(
trial_spike.finv[0] / trial_spike.finv[0, 0], [1.0, 2.0, 1.5]
)


def test_shorth_center_exact_m_window_and_final_window():
"""_shorth_center scores exact m-element windows including the final
window."""
from giant_python.extraction.raster.solver_baseline import _shorth_center

low = np.array(
[0.0 + 0.01 * k for k in range(8)]
+ [100.0 + 0.001 * k for k in range(7)]
+ [101.0]
)
assert np.isclose(_shorth_center(low), 0.035)
high = np.array(
[0.0]
+ [0.5 + 0.001 * k for k in range(7)]
+ [200.0 + 0.0001 * k for k in range(8)]
)
assert np.isclose(_shorth_center(high), 200.00035)