MouseLand / Kilosort

Fast spike sorting with drift correction for up to a thousand channels
https://kilosort.readthedocs.io/en/latest/
GNU General Public License v3.0
457 stars 239 forks source link

MEA data for spike sorting #785

Open Lime-y opened 1 week ago

Lime-y commented 1 week ago

Describe the issue:

I have a batch of MEA data with the following parameters: ELECTRODE SPACING: 300 µm, ELECTRODE DIAMETER: 50 µm. According to the answer in the previous issue, I understand that dmin and dminx should be set to the median vertical and horizontal distances, respectively, between contacts as a starting point. I tried various dmin and dminx values, and only when the values were set to 25 and 50 could spike sorting run successfully. Setting them to 100, 150, and 300 all resulted in 'No spikes detected, cannot continue sorting.' settings = { 'data_file_path': WindowsPath('D:/TYL/ShaoMEA/MEA analysis/MEA_nofilter.bin'), 'results_dir': WindowsPath('D:/TYL/ShaoMEA/MEA analysis/kilosort4_noexcluded_100'), 'probe': '... (use print probe)', 'probe_name': 'MEA_probmap.json', 'data_dtype': 'float32', 'n_chan_bin': 64, 'fs': 12500.0, 'batch_size': 60000, 'nblocks': 0, 'Th_universal': 9.0, 'Th_learned': 8.0, 'tmin': 0.0, 'tmax': inf, 'nt': 61, 'shift': None, 'scale': 10000.0, 'artifact_threshold': inf, 'nskip': 25, 'whitening_range': 32, 'highpass_cutoff': 300.0, 'binning_depth': 5.0, 'sig_interp': 20.0, 'drift_smoothing': [0.5, 0.5, 0.5], 'nt0min': None, 'dmin': 75.0, 'dminx': 75.0, 'min_template_size': 10.0, 'template_sizes': 5, 'nearest_chans': 10, 'nearest_templates': 64, 'max_channel_distance': None, 'templates_from_data': True, 'n_templates': 6, 'n_pcs': 6, 'Th_single_ch': 6.0, 'acg_threshold': 0.2, 'ccg_threshold': 0.25, 'cluster_downsampling': 20, 'x_centers': None, 'duplicate_spike_ms': 0.25 } probe = { 'chanMap': np.array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63]), 'kcoords': np.array([0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], dtype=np.float32), 'n_chan': 64, 'xc': np.array([ 25., 325., 625., 925., 1225., 1525., 1825., 2125., 25., 325., 625., 925., 1225., 1525., 1825., 2125., 25., 325., 625., 925., 1225., 1525., 1825., 2125., 25., 325., 625., 925., 1225., 1525., 1825., 2125., 25., 325., 625., 925., 1225., 1525., 1825., 2125., 25., 325., 625., 925., 1225., 1525., 1825., 2125., 25., 325., 625., 925., 1225., 1525., 1825., 2125., 25., 325., 625., 925., 1225., 1525., 1825., 2125.], dtype=np.float32), 'yc': np.array([ 25., 25., 25., 25., 25., 25., 25., 25., 325., 325., 325., 325., 325., 325., 325., 325., 625., 625., 625., 625., 625., 625., 625., 625., 925., 925., 925., 925., 925., 925., 925., 925., 1225., 1225., 1225., 1225., 1225., 1225., 1225., 1225., 1525., 1525., 1525., 1525., 1525., 1525., 1525., 1525., 1825., 1825., 1825., 1825., 1825., 1825., 1825., 1825., 2125., 2125., 2125., 2125., 2125., 2125., 2125., 2125.], dtype=np.float32) }

Reproduce the bug:

No response

Error message:

No response

Version information:

kilosort4

jacobpennington commented 1 week ago

Can you please include a screenshot of what the KS4 GUI looks like after loading your data, and upload kilosort4.log from the results directory for the successful sorting and from the failed sorting with dmin = dminx = 300?

Lime-y commented 1 week ago

Thank you for your answer. Here is a screenshot after loading the data.

屏幕截图 2024-09-15 093714 After I changed the min template size to 300, dmin=dminx=300 can also be sorted, but the result seems to be abnormal? 屏幕截图 2024-09-15 094047 The successful case is when the min template size is changed to 300, while the failed case is when the min template size is changed to 10. kilosort4.log This successful case is when the dmin=dminx is changed to 50: kilosort4_50.txt

jacobpennington commented 1 week ago

I definitely wouldn't recommend changing min_template_size to 300, you should use the default value. Did the results look normal for the dmin=50 run?

Lime-y commented 1 week ago

I am very sorry for taking so long to reply to you. The following results are obtained when min_template_size is set to the default value and dmin and dminx=50. Could you please confirm whether the colors in this graph represent a cluster? spike_positions

jacobpennington commented 1 week ago

Yes, colors in that graph represent a cluster. That looks more reasonable, at least they're grouped around the contact positions. You would need to check results in Phy to know if the units are split/merged properly, the waveforms look normal, etc.

As for why you needed to set dmin/dminx to a smaller value than the actual spacing, I'm not sure. The only difference that would make is placing more templates around each contact, but the contacts are far enough apart that a single template position should be sufficient since they won't interact with neighboring channels. I do notice the sampling rate is quite low, so it's possible there's something about the recording setup that would affect how well Kilosort is going to work. If you're recording from an uncommon brain area/organism, that could also have an impact.