@@ -99,7 +99,8 @@ to any preprocessing function.
9999 referenced_recording = spre.common_reference(filtered_recording)
100100 good_channels_recording = spre.detect_and_remove_bad_channels(filtered_recording)
101101
102- We can then aggregate the recordings back together using the ``aggregate_channels `` function
102+ We can then aggregate the recordings back together using the ``aggregate_channels `` function.
103+ Note that we do not need to do this to sort the data (see :ref: `sorting-by-channel-group `).
103104
104105.. code-block :: python
105106
@@ -134,23 +135,47 @@ back together under the hood).
134135 In general, it is not recommended to apply :py:func: `~aggregate_channels ` more than once.
135136 This will slow down :py:func: `~get_traces ` calls and may result in unpredictable behaviour.
136137
138+ .. _sorting-by-channel-group :
137139
138140Sorting a Recording by Channel Group
139141------------------------------------
140142
141143We can also sort a recording for each channel group separately. It is not necessary to preprocess
142144a recording by channel group in order to sort by channel group.
143145
144- There are two ways to sort a recording by channel group. First, we can split the preprocessed
145- recording (or, if it was already split during preprocessing as above, skip the :py:func: ` ~aggregate_channels ` step
146- directly use the :py:func: ` ~split_recording_dict `) .
146+ There are two ways to sort a recording by channel group. First, we can simply pass the output from
147+ our preprocessing-by-group method above. Second, for more control, we can loop over the recordings
148+ ourselves .
147149
148- **Option 1: Manual splitting **
150+ **Option 1 : Automatic splitting **
149151
150- In this example, similar to above we loop over all preprocessed recordings that
152+ Simply pass the split recording to the `run_sorter ` function, as if it was a non-split recording.
153+ This will return a dict of sortings, with the keys corresponding to the groups.
154+
155+ .. code-block :: python
156+
157+ split_recording = raw_recording.split_by(" group" )
158+ # is a dict of recordings
159+
160+ # do preprocessing if needed
161+ pp_recording = spre.bandpass_filter(split_recording)
162+
163+ dict_of_sortings = run_sorter(
164+ sorter_name = ' kilosort2' ,
165+ recording = pp_recording,
166+ working_folder = ' working_path'
167+ )
168+
169+
170+ **Option 2: Manual splitting **
171+
172+ In this example, we loop over all preprocessed recordings that
151173are grouped by channel, and apply the sorting separately. We store the
152174sorting objects in a dictionary for later use.
153175
176+ You might do this if you want extra control e.g. to apply bespoke steps
177+ to different groups.
178+
154179.. code-block :: python
155180
156181 split_preprocessed_recording = preprocessed_recording.split_by(" group" )
@@ -163,16 +188,3 @@ sorting objects in a dictionary for later use.
163188 folder = f " folder_KS2_group { group} "
164189 )
165190 sortings[group] = sorting
166-
167- **Option 2 : Automatic splitting **
168-
169- Alternatively, SpikeInterface provides a convenience function to sort the recording by property:
170-
171- .. code-block :: python
172-
173- aggregate_sorting = run_sorter_by_property(
174- sorter_name = ' kilosort2' ,
175- recording = preprocessed_recording,
176- grouping_property = ' group' ,
177- working_folder = ' working_path'
178- )
0 commit comments