1010 interpolate_motion_on_traces ,
1111)
1212from spikeinterface .sortingcomponents .tests .common import make_dataset
13-
13+ from spikeinterface . core import generate_ground_truth_recording
1414
1515def make_fake_motion (rec ):
1616 # make a fake motion object
17- duration = rec . get_total_duration ()
17+
1818 locs = rec .get_channel_locations ()
19- temporal_bins = np .arange (0.5 , duration - 0.49 , 0.5 )
2019 spatial_bins = np .arange (locs [:, 1 ].min (), locs [:, 1 ].max (), 100 )
21- displacement = np .zeros ((temporal_bins .size , spatial_bins .size ))
22- displacement [:, :] = np .linspace (- 30 , 30 , temporal_bins .size )[:, None ]
2320
24- motion = Motion ([displacement ], [temporal_bins ], spatial_bins , direction = "y" )
21+ displacement = []
22+ temporal_bins = []
23+ for segment_index in range (rec .get_num_segments ()):
24+ duration = rec .get_duration (segment_index = segment_index )
25+ seg_time_bins = np .arange (0.5 , duration - 0.49 , 0.5 )
26+ seg_disp = np .zeros ((seg_time_bins .size , spatial_bins .size ))
27+ seg_disp [:, :] = np .linspace (- 30 , 30 , seg_time_bins .size )[:, None ]
28+
29+ temporal_bins .append (seg_time_bins )
30+ displacement .append (seg_disp )
31+
32+ motion = Motion (displacement , temporal_bins , spatial_bins , direction = "y" )
2533
2634 return motion
2735
@@ -176,7 +184,27 @@ def test_cross_band_interpolation():
176184
177185
178186def test_InterpolateMotionRecording ():
179- rec , sorting = make_dataset ()
187+ # rec, sorting = make_dataset()
188+
189+ # 2 segments
190+ rec , sorting = generate_ground_truth_recording (
191+ durations = [30.0 ],
192+ sampling_frequency = 30000.0 ,
193+ num_channels = 32 ,
194+ num_units = 10 ,
195+ generate_probe_kwargs = dict (
196+ num_columns = 2 ,
197+ xpitch = 20 ,
198+ ypitch = 20 ,
199+ contact_shapes = "circle" ,
200+ contact_shape_params = {"radius" : 6 },
201+ ),
202+ generate_sorting_kwargs = dict (firing_rates = 6.0 , refractory_period_ms = 4.0 ),
203+ noise_kwargs = dict (noise_levels = 5.0 , strategy = "on_the_fly" ),
204+ seed = 2205 ,
205+ )
206+
207+
180208 motion = make_fake_motion (rec )
181209
182210 rec2 = InterpolateMotionRecording (rec , motion , border_mode = "force_extrapolate" )
@@ -187,15 +215,19 @@ def test_InterpolateMotionRecording():
187215
188216 rec2 = InterpolateMotionRecording (rec , motion , border_mode = "remove_channels" )
189217 assert rec2 .channel_ids .size == 24
190- for ch_id in (0 , 1 , 14 , 15 , 16 , 17 , 30 , 31 ):
218+ for ch_id in ("0" , "1" , "14" , "15" , "16" , "17" , "30" , "31" ):
191219 assert ch_id not in rec2 .channel_ids
192220
193221 traces = rec2 .get_traces (segment_index = 0 , start_frame = 0 , end_frame = 30000 )
194222 assert traces .shape == (30000 , 24 )
195223
196- traces = rec2 .get_traces (segment_index = 0 , start_frame = 0 , end_frame = 30000 , channel_ids = [3 , 4 ])
224+ traces = rec2 .get_traces (segment_index = 0 , start_frame = 0 , end_frame = 30000 , channel_ids = ["3" , "4" ])
197225 assert traces .shape == (30000 , 2 )
198226
227+ # test dump.load when multi segments
228+ rec2 .dump ("rec_motion_interp.pickle" )
229+ rec3 = sc .load ("rec_motion_interp.pickle" )
230+
199231 # import matplotlib.pyplot as plt
200232 # import spikeinterface.widgets as sw
201233 # fig, ax = plt.subplots()
@@ -207,7 +239,7 @@ def test_InterpolateMotionRecording():
207239
208240if __name__ == "__main__" :
209241 # test_correct_motion_on_peaks()
210- test_interpolate_motion_on_traces ()
242+ # test_interpolate_motion_on_traces()
211243 # test_interpolation_simple()
212- # test_InterpolateMotionRecording()
213- test_cross_band_interpolation ()
244+ test_InterpolateMotionRecording ()
245+ # test_cross_band_interpolation()
0 commit comments