diff --git a/src/spikeinterface/core/channelsaggregationrecording.py b/src/spikeinterface/core/channelsaggregationrecording.py index ebaa1c3d1c..2589e70ea6 100644 --- a/src/spikeinterface/core/channelsaggregationrecording.py +++ b/src/spikeinterface/core/channelsaggregationrecording.py @@ -36,9 +36,12 @@ def __init__(self, recording_list_or_dict=None, renamed_channel_ids=None, record ) self._recordings = recording_list - - for group_id, recording in zip(recording_ids, recording_list): - recording.set_property("aggregation_key", [group_id] * recording.get_num_channels()) + aggregation_key = np.concatenate( + [ + np.asarray([recording_id] * recording.get_num_channels()) + for recording_id, recording in zip(recording_ids, recording_list) + ] + ) self._perform_consistency_checks() sampling_frequency = recording_list[0].get_sampling_frequency() @@ -90,6 +93,7 @@ def __init__(self, recording_list_or_dict=None, renamed_channel_ids=None, record del property_dict[prop_name] break + property_dict["aggregation_key"] = aggregation_key for prop_name, prop_values in property_dict.items(): self.set_property(key=prop_name, values=prop_values) diff --git a/src/spikeinterface/core/tests/test_channelsaggregationrecording.py b/src/spikeinterface/core/tests/test_channelsaggregationrecording.py index 8936e6a650..792605fde6 100644 --- a/src/spikeinterface/core/tests/test_channelsaggregationrecording.py +++ b/src/spikeinterface/core/tests/test_channelsaggregationrecording.py @@ -231,6 +231,17 @@ def test_aggretion_labeling_for_dicts(): assert np.all(user_group_property == [6, 6, 7, 7]) +def test_aggregate_channels_does_not_change_inputs(): + recording1 = generate_recording(num_channels=4, durations=[1.0], set_probe=False) + recording2 = generate_recording(num_channels=2, durations=[1.0], set_probe=False) + + aggregate_channels([recording1, recording2]) + aggregate_channels({"X": recording1, "Y": recording2}) + + assert "aggregation_key" not in recording1.get_property_keys() + assert "aggregation_key" not in recording2.get_property_keys() + + def test_channel_aggregation_does_not_preserve_ids_if_not_unique(): recording1 = generate_recording(num_channels=3, durations=[10], set_probe=False) # To avoid location check