Adding a residual preprocessor
@@ -61,7 +61,7 @@ def correct_motion_on_peaks(peaks, peak_locations, times,
return corrected_peak_locations
-def correct_motion_on_traces(traces, times, channel_locations, motion, temporal_bins, spatial_bins,
+def correct_motion_on_traces(traces, times, channel_locations, motion, temporal_bins, spatial_bins=None,
direction=1, spatial_interpolation_method='idw', spatial_interpolation_kwargs={}):
"""
Apply inverse motion with spatial interpolation on traces.
@@ -252,7 +252,7 @@ class CorrectMotionRecording(BasePreprocessor):
"""
name = 'correct_motion'
- def __init__(self, recording, motion, temporal_bins, spatial_bins, direction=1):
+ def __init__(self, recording, motion, temporal_bins, spatial_bins=None, direction=1):
assert recording.get_num_segments() == 1, 'correct is handle only for one segment for the moment'
BasePreprocessor.__init__(self, recording)
@@ -299,3 +299,31 @@ class CorrectMotionRecordingSegment(BasePreprocessorSegment):
trace2 = trace2[:, channel_indices]
return trace2
+
+
+
+class ResidualRecording(BasePreprocessor):
+ name = 'residual_recording'
+ def __init__(self, recording_1, recording_2):
+ assert recording_1.get_num_segments() == recording_2.get_num_segments()
+ BasePreprocessor.__init__(self, recording_1)
+
+ for parent_recording_segment_1, parent_recording_segment_2 in zip(recording_1._recording_segments, recording_2._recording_segments):
+ rec_segment = DifferenceRecordingSegment(parent_recording_segment_1, parent_recording_segment_2)
+ self.add_recording_segment(rec_segment)
+
+ self._kwargs = dict(recording_1=recording_1.to_dict(), recording_2=recording_2.to_dict())
+
+
+class DifferenceRecordingSegment(BasePreprocessorSegment):
+ def __init__(self, parent_recording_segment_1, parent_recording_segment_2):
+ BasePreprocessorSegment.__init__(self, parent_recording_segment_1)
+ self.parent_recording_segment_1 = parent_recording_segment_1
+ self.parent_recording_segment_2 = parent_recording_segment_2
+
+ def get_traces(self, start_frame, end_frame, channel_indices):
+
+ traces_1 = self.parent_recording_segment_1.get_traces(start_frame, end_frame, channel_indices=slice(None))
+ traces_2 = self.parent_recording_segment_2.get_traces(start_frame, end_frame, channel_indices=slice(None))
+
+ return traces_2 - traces_1
