Skip to content

Commit

Permalink
Merge pull request #1971 from h-mayorquin/separate_scaling_test
Browse files Browse the repository at this point in the history
Pin down z-scale normalized to integer (!) failure by separating the tests
  • Loading branch information
alejoe91 authored Sep 11, 2023
2 parents c9a5136 + dadf849 commit a26cb84
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/spikeinterface/preprocessing/normalize_scale.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ def __init__(
means = means[None, :]
stds = np.std(random_data, axis=0)
stds = stds[None, :]
gain = 1 / stds
gain = 1.0 / stds
offset = -means / stds

if int_scale is not None:
Expand Down
15 changes: 10 additions & 5 deletions src/spikeinterface/preprocessing/tests/test_normalize_scale.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,18 @@ def test_zscore():
assert np.all(np.abs(np.mean(tr, axis=0)) < 0.01)
assert np.all(np.abs(np.std(tr, axis=0) - 1) < 0.01)


def test_zscore_int():
seed = 1
rec = generate_recording(seed=seed, mode="legacy")
rec_int = scale(rec, dtype="int16", gain=100)
with pytest.raises(AssertionError):
rec4 = zscore(rec_int, dtype=None)
rec4 = zscore(rec_int, dtype="int16", int_scale=256, mode="mean+std", seed=seed)
tr = rec4.get_traces(segment_index=0)
trace_mean = np.mean(tr, axis=0)
trace_std = np.std(tr, axis=0)
zscore(rec_int, dtype=None)

zscore_recording = zscore(rec_int, dtype="int16", int_scale=256, mode="mean+std", seed=seed)
traces = zscore_recording.get_traces(segment_index=0)
trace_mean = np.mean(traces, axis=0)
trace_std = np.std(traces, axis=0)
assert np.all(np.abs(trace_mean) < 1)
assert np.all(np.abs(trace_std - 256) < 1)

Expand Down

0 comments on commit a26cb84

Please sign in to comment.