1- .. _ recording-by-channel-group :
1+ .. _ process_by_group :
22
33Process a recording by channel group
44====================================
@@ -101,8 +101,8 @@ to any preprocessing function.
101101 referenced_recording = spre.common_reference(filtered_recording)
102102 good_channels_recording = spre.detect_and_remove_bad_channels(filtered_recording)
103103
104- We can then aggregate the recordings back together using the ``aggregate_channels `` function.
105- Note that we do not need to do this to sort the data (see :ref: `sorting-by-channel-group `).
104+ If needed, we could aggregate the recordings back together using the ``aggregate_channels `` function.
105+ Note: you do not need to do this to sort the data (see :ref: `sorting-by-channel-group `).
106106
107107.. code-block :: python
108108
@@ -145,14 +145,16 @@ Sorting a Recording by Channel Group
145145We can also sort a recording for each channel group separately. It is not necessary to preprocess
146146a recording by channel group in order to sort by channel group.
147147
148- There are two ways to sort a recording by channel group. First, we can simply pass the output from
149- our preprocessing-by-group method above. Second, for more control, we can loop over the recordings
148+ There are two ways to sort a recording by channel group. First, we can pass a dictionary to the
149+ ``run_sorter `` function. Since the preprocessing-by-group method above returns a dict, we can
150+ simply pass this output. Alternatively, for more control, we can loop over the recordings
150151ourselves.
151152
152- **Option 1 : Automatic splitting **
153+ **Option 1 : Automatic splitting (Recommended) **
153154
154- Simply pass the split recording to the `run_sorter ` function, as if it was a non-split recording.
155- This will return a dict of sortings, with the keys corresponding to the groups.
155+ Simply pass the split recording to the ``run_sorter `` function, as if it was a non-split recording.
156+ This will return a dict of sortings, with the same keys as the dict of recordings that were
157+ passed to ``run_sorter ``.
156158
157159.. code-block :: python
158160
@@ -162,10 +164,10 @@ This will return a dict of sortings, with the keys corresponding to the groups.
162164 # do preprocessing if needed
163165 pp_recording = spre.bandpass_filter(split_recording)
164166
165- dict_of_sortings = run_sorter(
166- sorter_name = ' kilosort2 ' ,
167+ dict_of_sortings = run_sorter(
168+ sorter_name = ' kilosort4 ' ,
167169 recording = pp_recording,
168- working_folder = ' working_path '
170+ folder = ' my_kilosort4_sorting '
169171 )
170172
171173
@@ -190,3 +192,37 @@ to different groups.
190192 folder = f " folder_KS2_group { group} "
191193 )
192194 sortings[group] = sorting
195+
196+
197+ Creating a SortingAnalyzer by Channel Group
198+ -------------------------------------------
199+
200+ The code above generates a dictionary of recording objects and a dictionary of sorting objects.
201+ When making a :ref: `SortingAnalyzer <modules/core:SortingAnalyzer >`, we can pass these dictionaries and
202+ a single analyzer will be created, with the recordings and sortings appropriately aggregated.
203+
204+ The dictionary of recordings and dictionary of sortings must have the same keys. E.g. if you
205+ use ``split_by("group") ``, the keys of your dict of recordings will be the values of the ``group ``
206+ property of the recording. Then the dict of sortings should also have these keys.
207+ Note that if you use the internal functions, like we do in the code-block below, you don't need to
208+ keep track of keys yourself. SpikeInterface will do this for you automatically.
209+
210+ The code for create ``SortingAnalyzer `` from dicts of recordings and sortings is very similar to that for
211+ creating a sorting analyzer from a single recording and sorting:
212+
213+ .. code-block :: python
214+
215+ dict_of_recordings = preprocessed_recording.split_by(" group" )
216+ dict_of_sortings = run_sorter(sorter_name = " mountainsort5" , recording = dict_of_recordings)
217+
218+ analyzer = create_sorting_analyzer(sorting = dict_of_sortings, recording = dict_of_recordings)
219+
220+
221+ The code above creates a *single * sorting analyzer called :code: `analyzer `. You can select the units
222+ from one of the "group"s as follows:
223+
224+ .. code-block :: python
225+
226+ aggretation_keys = analyzer.get_sorting_property(" aggregation_key" )
227+ unit_ids_group_0 = analyzer.unit_ids[aggretation_keys == 0 ]
228+ group_0_analzyer = analyzer.select_units(unit_ids = unit_ids_group_0)
0 commit comments