Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spiky artifacts in estimated drift #363

Closed
lshaheen opened this issue Mar 24, 2021 · 2 comments · Fixed by #595
Closed

Spiky artifacts in estimated drift #363

lshaheen opened this issue Mar 24, 2021 · 2 comments · Fixed by #595

Comments

@lshaheen
Copy link

Hi,

I'm trying out the new drift correction in KS3. For some reason I'm getting a lot of spiky artifacts in the drift correction. In the first plot here I'm plotting rez.dshift, and changed the x axis to be time. I set rez.nblocks=1 for rigid registration to make it simpler, but I saw the same artifacts with the default, usually they would happen on all the segments together. There are several recordings concatenated together from a single site, and there are short periods between them where we didn't capture data. The dashed lines show the start of each recording. The electrode was a 64D from UCLA, which has a 3-column checkerboard pattern. But for some reason the center column wasn't giving good data so I excluded all those electrodes from this sort, making the electrode 2 columns spaced 40 um apart, with 50 um between rows. Maybe the problem is that this is just a little too sparse to capture the drift well? Have you seen these kind of artifacts in your data?

In the second plot I added the rez.dshift from two more sorts. The orange is a sort with just the first 6 recordings, the blue has just the 6th. The artifacts are in different places than when you include all the data, which seems odd.

Any insights are much appreciated!

Thanks,
Luke

Drift_HOD009a_1_2_3_4_5_6_7_8_9_11_12_13_KiloSort3_minfr_goodchannels_to0_rmBadChans_rigid
Drift_overlay_HOD009a_1_2_3_4_5_6_7_8_9_11_12_13_KiloSort3_minfr_goodchannels_to0_rmBadChans_rigid

@marius10p
Copy link
Contributor

This happens when there is not enough data to estimate the drift well. To compensate, you can increase the batch size ops.NT by a factor of 8 or so. I can also look into adding an optional smoothing factor to encourage smooth drifts.

@lshaheen
Copy link
Author

lshaheen commented Apr 2, 2021

Thanks. I increased the batch size by a factor of 4 and added a 3-point median filter which got rid of a few remaining blips. If anyone else reads this and wants to try, it, I added this code to line 97 of datashift2.m:

med_filt = getOr(rez.ops, 'drift_estimate_median_filter_pts', 0);
if med_filt>0
    imin_pre_filt=imin;
    imin = medfilt1(imin,med_filt,'truncate');
end

And set ops.drift_estimate_median_filter_pt=3;

@lshaheen lshaheen closed this as completed Apr 2, 2021
czuba added a commit to czuba/Kilosort that referenced this issue Apr 16, 2021
- see mention & example in github issue MouseLand#363

- [ops.integerShifts] flag to disable subsample datashifts,
  - if ==1, only apply shifts in integer multiples of electrode (y) spacing

- [ops.fig] ==2, new mode for additional debug plots

increased binning witdth to 10 um
- default was 5, 10 good for 100 um uprobe spacing  (5 too small for uprobes)

align_block2>>

- increase look up & down distance (from 15 to 25 upsampled 'channels')
- Shifted starting batch to 2/3 into file (was 1/2)

- initialize alignment target with batch temporally averaged +/- 5% of total batches

- more [informative] plots

Temporally smooth each of the datashift rigid registration iterations by
increasing number of samples, so that distant batches don't get stuck in local minima

disable attempt to smooth/simplify datashifting by temporally reordering batches
 - perhaps this is better/reasonable if have alot of rhythmic artifacts, but
   the temporal drift reordering (halmark of kilosort 2.0 drift correction) just
   never really worked properly.

- initialize alignment target with batch temporally averaged +/- 5% of total batches

...mostly probably it for datashifting changes, but might have missed something
- if having issues, check the diff
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants