Skip to content

Commit

Permalink
Parent recording -> recording
Browse files Browse the repository at this point in the history
  • Loading branch information
AnujVadher committed May 29, 2024
1 parent 790715c commit 31e2c6b
Showing 1 changed file with 28 additions and 28 deletions.
56 changes: 28 additions & 28 deletions src/spikeinterface/preprocessing/zero_channel_pad.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class TracePaddedRecording(BasePreprocessor):
Parameters
----------
parent_recording_segment : BaseRecording
recording_segment : BaseRecording
The parent recording segment from which the traces are to be retrieved.
padding_start : int, default: 0
The amount of padding to add to the left of the traces. It has to be non-negative.
Expand All @@ -30,18 +30,18 @@ class TracePaddedRecording(BasePreprocessor):
"""

def __init__(
self, parent_recording: BaseRecording, padding_start: int = 0, padding_end: int = 0, fill_value: float = 0.0
self, recording: BaseRecording, padding_start: int = 0, padding_end: int = 0, fill_value: float = 0.0
):
assert padding_end >= 0 and padding_start >= 0, "Paddings must be >= 0"
super().__init__(recording=parent_recording)
super().__init__(recording=recording)

self.padding_start = padding_start
self.padding_end = padding_end
self.fill_value = fill_value
for segment in parent_recording._recording_segments:
for segment in recording._recording_segments:
recording_segment = TracePaddedRecordingSegment(
segment,
parent_recording.get_num_channels(),
recording.get_num_channels(),
self.dtype,
self.padding_start,
self.padding_end,
Expand All @@ -50,7 +50,7 @@ def __init__(
self.add_recording_segment(recording_segment)

self._kwargs = dict(
parent_recording=parent_recording,
parent_recording=recording,
padding_start=padding_start,
padding_end=padding_end,
fill_value=fill_value,
Expand All @@ -60,21 +60,21 @@ def __init__(
class TracePaddedRecordingSegment(BasePreprocessorSegment):
def __init__(
self,
parent_recording_segment: BaseRecordingSegment,
recording_segment: BaseRecordingSegment,
num_channels,
dtype,
paddign_left,
padding_left,
padding_end,
fill_value,
):
self.padding_start = paddign_left
self.padding_start = padding_left
self.padding_end = padding_end
self.fill_value = fill_value
self.num_channels = num_channels
self.num_samples_in_original_segment = parent_recording_segment.get_num_samples()
self.num_samples_in_original_segment = recording_segment.get_num_samples()
self.dtype = dtype

super().__init__(parent_recording_segment=parent_recording_segment)
super().__init__(parent_recording_segment=recording_segment)

def get_traces(self, start_frame, end_frame, channel_indices):
if start_frame is None:
Expand Down Expand Up @@ -146,12 +146,12 @@ class ZeroChannelPaddedRecording(BaseRecording):
name = "zero_channel_pad"
installed = True

def __init__(self, parent_recording: BaseRecording, num_channels: int, channel_mapping: Union[list, None] = None):
def __init__(self, recording: BaseRecording, num_channels: int, channel_mapping: Union[list, None] = None):
"""Pads a recording with channels that contain only zero.
Parameters
----------
parent_recording : BaseRecording
recording : BaseRecording
recording to zero-pad
num_channels : int
Total number of channels in the zero-channel-padded recording
Expand All @@ -161,50 +161,50 @@ def __init__(self, parent_recording: BaseRecording, num_channels: int, channel_m
beginning of the zero-channel-padded recording.
"""
BaseRecording.__init__(
self, parent_recording.get_sampling_frequency(), np.arange(num_channels), parent_recording.get_dtype()
self, recording.get_sampling_frequency(), np.arange(num_channels), recording.get_dtype()
)

if channel_mapping is not None:
assert (
len(channel_mapping) == parent_recording.get_num_channels()
len(channel_mapping) == recording.get_num_channels()
), "The new mapping must be specified for all channels."
assert max(channel_mapping) < num_channels, (
"The new mapping cannot exceed total number of channels " "in the zero-chanenl-padded recording."
)
else:
if (
"locations" in parent_recording.get_property_keys()
or "contact_vector" in parent_recording.get_property_keys()
"locations" in recording.get_property_keys()
or "contact_vector" in recording.get_property_keys()
):
self.channel_mapping = np.argsort(parent_recording.get_channel_locations()[:, 1])
self.channel_mapping = np.argsort(recording.get_channel_locations()[:, 1])
else:
self.channel_mapping = np.arange(parent_recording.get_num_channels())
self.channel_mapping = np.arange(recording.get_num_channels())

self.parent_recording = parent_recording
self.parent_recording = recording
self.num_channels = num_channels
for segment in parent_recording._recording_segments:
for segment in recording._recording_segments:
recording_segment = ZeroChannelPaddedRecordingSegment(segment, self.num_channels, self.channel_mapping)
self.add_recording_segment(recording_segment)

# only copy relevant metadata and properties
parent_recording.copy_metadata(self, only_main=True)
self._parent = parent_recording
prop_keys = parent_recording.get_property_keys()
recording.copy_metadata(self, only_main=True)
self._parent = recording
prop_keys = recording.get_property_keys()

for k in prop_keys:
values = self.get_property(k)
if values is not None:
self.set_property(k, values, ids=self.channel_ids[self.channel_mapping])

self._kwargs = dict(
parent_recording=parent_recording, num_channels=num_channels, channel_mapping=channel_mapping
parent_recording=recording, num_channels=num_channels, channel_mapping=channel_mapping
)


class ZeroChannelPaddedRecordingSegment(BasePreprocessorSegment):
def __init__(self, parent_recording_segment: BaseRecordingSegment, num_channels: int, channel_mapping: list):
BasePreprocessorSegment.__init__(self, parent_recording_segment)
self.parent_recording_segment = parent_recording_segment
def __init__(self, recording_segment: BaseRecordingSegment, num_channels: int, channel_mapping: list):
BasePreprocessorSegment.__init__(self, recording_segment)
self.parent_recording_segment = recording_segment
self.num_channels = num_channels
self.channel_mapping = channel_mapping

Expand Down

0 comments on commit 31e2c6b

Please sign in to comment.