Commit 32578f6
Fix sparse template handling in kilosort reader for SI-exported Phy data
SpikeInterface's export_to_phy exports sparse templates by default (since
v0.101.0), with templates.npy shape (n_templates, n_samples, max_sparse_channels)
instead of the full (n_templates, n_samples, n_channels) format from native
Kilosort.
The companion file templates_ind.npy maps (template_idx, sparse_channel_idx)
to actual channel indices, with -1 indicating padding.
This fix updates get_best_channel() and extract_spike_depths() to:
- Check if templates_ind exists (indicates SI-exported sparse format)
- Use templates_ind to map sparse indices to actual channel indices
- Fall back to original behavior for native Kilosort (dense) format
Without this fix, spike_sites and best_channel values are incorrect when
reading SI-exported Phy curations, as argmax returns indices into the
sparse representation rather than actual channel indices.
Related: dj-sciops/nei_nienborg#111 (Issue #2)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>1 parent c4fafcd commit 32578f6
1 file changed
+43
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
151 | 151 | | |
152 | 152 | | |
153 | 153 | | |
154 | | - | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
155 | 176 | | |
156 | 177 | | |
157 | 178 | | |
| |||
179 | 200 | | |
180 | 201 | | |
181 | 202 | | |
| 203 | + | |
182 | 204 | | |
183 | | - | |
184 | | - | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
185 | 225 | | |
186 | 226 | | |
187 | 227 | | |
| |||
0 commit comments