Skip to content

Commit 5b0d887

Browse files
committed
Move interpolators tests to sortingcomponents
1 parent 90547f5 commit 5b0d887

4 files changed

Lines changed: 54 additions & 37 deletions

File tree

pyproject.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,6 @@ test_core = [
123123
"pytest",
124124
"pytest-dependency",
125125
"psutil",
126-
"scipy", # for motion interpolators
127-
"s3fs", # for streaming tests
128126

129127
# for github test : probeinterface and neo from master
130128
# for release we need pypi, so this need to be commented

src/spikeinterface/core/tests/test_loading.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,13 +176,15 @@ def test_load_motion(tmp_path, generate_motion_object):
176176
assert motion == motion_loaded
177177

178178

179+
@pytest.mark.streaming_extractors
179180
@pytest.mark.skipif(not HAVE_S3, reason="s3fs not installed")
180181
def test_remote_recording():
181182
s3_path = "s3://spikeinterface-sorting-analyzer-test/recording_for_analyzer_short.zarr/"
182183
rec = load(s3_path)
183184
assert isinstance(rec, ZarrRecordingExtractor)
184185

185186

187+
@pytest.mark.streaming_extractors
186188
@pytest.mark.skipif(not HAVE_S3, reason="s3fs not installed")
187189
def test_remote_analyzer():
188190
s3_path = "s3://spikeinterface-sorting-analyzer-test/analyzer_remote_test.zarr/"

src/spikeinterface/core/tests/test_motion_core.py

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ def make_fake_motion():
2929
return motion
3030

3131

32-
def test_Motion(tmp_path):
33-
32+
def test_motion_object(tmp_path):
33+
"""Basic tests for Motion object representation, saving and loading."""
3434
temporal_bins_s = np.arange(0.0, 10.0, 1.0)
3535
spatial_bins_um = np.array([100.0, 200.0])
3636

@@ -43,37 +43,13 @@ def test_Motion(tmp_path):
4343
# serialize with pickle before interpolation fit
4444
motion2 = pickle.loads(pickle.dumps(motion))
4545
assert motion2.interpolators is None
46-
# serialize with pickle after interpolation fit
47-
motion2.make_interpolators()
48-
assert motion2.interpolators is not None
49-
motion2 = pickle.loads(pickle.dumps(motion2))
50-
assert motion2.interpolators is not None
51-
52-
# to/from dict
53-
motion2 = Motion.from_dict(motion.to_dict())
54-
assert motion == motion2
55-
assert motion2.interpolators is None
56-
57-
# do interpolate
58-
displacement = motion.get_displacement_at_time_and_depth([2, 4.4, 11], [120.0, 80.0, 150.0])
59-
# print(displacement)
60-
assert displacement.shape[0] == 3
61-
# check clip
62-
assert displacement[2] == 20.0
63-
64-
# interpolate grid
65-
displacement = motion.get_displacement_at_time_and_depth([2, 4.4, 11, 15, 19], [150.0, 80.0], grid=True)
66-
assert displacement.shape == (2, 5)
67-
assert displacement[0, 2] == 20.0
6846

6947
# save/load to folder
7048
folder = tmp_path / "motion_saved"
71-
if folder.exists():
72-
shutil.rmtree(folder)
7349
motion.save(folder)
7450
motion2 = Motion.load(folder)
7551
assert motion == motion2
7652

7753

7854
if __name__ == "__main__":
79-
test_Motion()
55+
test_motion_object()

src/spikeinterface/sortingcomponents/motion/tests/test_motion_interpolation.py

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
import warnings
22

33
import numpy as np
4-
import spikeinterface.core as sc
4+
import pickle
55

6+
from spikeinterface import NumpyRecording, load
7+
from spikeinterface.core import generate_ground_truth_recording
68
from spikeinterface.core.motion import Motion
9+
from spikeinterface.core.testing import check_recordings_equal
710
from spikeinterface.sortingcomponents.motion.motion_interpolation import (
811
InterpolateMotionRecording,
912
correct_motion_on_peaks,
1013
interpolate_motion,
1114
interpolate_motion_on_traces,
1215
)
1316
from spikeinterface.sortingcomponents.tests.common import make_dataset
14-
from spikeinterface.core import generate_ground_truth_recording
1517

1618

1719
def make_fake_motion(rec):
@@ -36,12 +38,49 @@ def make_fake_motion(rec):
3638
return motion
3739

3840

41+
def test_motion_object_interpolators(tmp_path):
42+
rec, sorting = make_dataset()
43+
motion = make_fake_motion(rec)
44+
45+
# serialize with pickle after interpolation fit
46+
motion.make_interpolators()
47+
assert motion.interpolators is not None
48+
motion2 = pickle.loads(pickle.dumps(motion))
49+
assert motion2.interpolators is not None
50+
51+
# to/from dict
52+
motion2 = Motion.from_dict(motion.to_dict())
53+
assert motion == motion2
54+
# serialization to/from dict loses interpolators
55+
assert motion2.interpolators is None
56+
motion2.make_interpolators()
57+
58+
# save/load to folder
59+
folder = tmp_path / "motion_saved"
60+
motion.save(folder)
61+
motion3 = Motion.load(folder)
62+
# save/load to folder loses interpolators
63+
assert motion3.interpolators is None
64+
65+
# do interpolate
66+
displacement = motion.get_displacement_at_time_and_depth([2, 4.4, 11], [120.0, 80.0, 150.0])
67+
displacement2 = motion2.get_displacement_at_time_and_depth([2, 4.4, 11], [120.0, 80.0, 150.0])
68+
displacement3 = motion3.get_displacement_at_time_and_depth([2, 4.4, 11], [120.0, 80.0, 150.0])
69+
# print(displacement)
70+
assert displacement.shape[0] == 3
71+
# check interpolators reload
72+
np.testing.assert_array_equal(displacement, displacement2)
73+
np.testing.assert_array_equal(displacement, displacement3)
74+
75+
# interpolate grid
76+
displacement = motion.get_displacement_at_time_and_depth([2, 4.4, 11, 15, 19], [150.0, 80.0], grid=True)
77+
assert displacement.shape == (2, 5)
78+
79+
3980
def test_correct_motion_on_peaks():
4081
rec, sorting = make_dataset()
4182
peaks = sorting.to_spike_vector()
42-
print(peaks.dtype)
4383
motion = make_fake_motion(rec)
44-
# print(motion)
4584

4685
# fake locations
4786
peak_locations = np.zeros((peaks.size), dtype=[("x", "float32"), ("y", "float")])
@@ -98,7 +137,7 @@ def test_interpolation_simple():
98137
num_chans_drifted = num_chans_orig + num_chans_orig - 1
99138
traces = np.zeros((n_samples, num_chans_drifted), dtype="float32")
100139
traces[:, :num_chans_orig] = np.eye(num_chans_orig)
101-
rec = sc.NumpyRecording(traces, sampling_frequency=1)
140+
rec = NumpyRecording(traces, sampling_frequency=1)
102141
rec.set_dummy_probe_from_locations(np.c_[np.zeros(num_chans_drifted), np.arange(num_chans_drifted)])
103142

104143
true_motion = Motion(np.arange(n_samples)[:, None], 0.5 + np.arange(n_samples), np.zeros(1))
@@ -157,14 +196,14 @@ def test_cross_band_interpolation():
157196
traces_lfp = np.zeros((num_samples_lfp, num_chans))
158197
traces_lfp[: int(t_switch * fs_lfp), 5] = 1.0
159198
traces_lfp[int(t_switch * fs_lfp) :, 6] = 1.0
160-
rec_lfp = sc.NumpyRecording(traces_lfp, sampling_frequency=fs_lfp)
199+
rec_lfp = NumpyRecording(traces_lfp, sampling_frequency=fs_lfp)
161200
rec_lfp.set_dummy_probe_from_locations(geom)
162201

163202
# same for AP
164203
traces_ap = np.zeros((num_samples_ap, num_chans))
165204
traces_ap[: int(t_switch * fs_ap) - halfbin_ap_lfp, 5] = 1.0
166205
traces_ap[int(t_switch * fs_ap) - halfbin_ap_lfp :, 6] = 1.0
167-
rec_ap = sc.NumpyRecording(traces_ap, sampling_frequency=fs_ap)
206+
rec_ap = NumpyRecording(traces_ap, sampling_frequency=fs_ap)
168207
rec_ap.set_dummy_probe_from_locations(geom)
169208

170209
# set times for both, and silence the warning
@@ -227,7 +266,9 @@ def test_InterpolateMotionRecording():
227266

228267
# test dump.load when multi segments
229268
rec2.dump("rec_motion_interp.pickle")
230-
rec3 = sc.load("rec_motion_interp.pickle")
269+
rec3 = load("rec_motion_interp.pickle")
270+
271+
check_recordings_equal(rec2, rec3)
231272

232273
# import matplotlib.pyplot as plt
233274
# import spikeinterface.widgets as sw

0 commit comments

Comments
 (0)