|
| 1 | +from pathlib import Path |
| 2 | + |
| 3 | +import scipy.signal |
| 4 | +import numpy as np |
| 5 | + |
| 6 | +from ibllib.io import spikeglx |
| 7 | +from ibllib.dsp import voltage |
| 8 | +from ibllib.ephys import neuropixel |
| 9 | +from oneibl.one import ONE |
| 10 | +from easyqc.gui import viewseis |
| 11 | + |
| 12 | +from viewspikes.plots import plot_insertion, show_psd, overlay_spikes |
| 13 | +from viewspikes.data import stream, get_spikes, get_ks2 |
| 14 | + |
| 15 | +folder_samples = Path('/datadisk/Data/spike_sorting/short_samples') |
| 16 | +files_samples = list(folder_samples.rglob('*.bin')) |
| 17 | + |
| 18 | +one = ONE() |
| 19 | +SIDE_BY_SIDE = False |
| 20 | +# |
| 21 | +# pins = one.alyx.rest('insertions', 'list', django=('json__extended_qc__alignment_count__gt,0')) |
| 22 | +# pid, t0 = ('3e7618b8-34ca-4e48-ba3a-0e0f88a43131', 1002) # SWC_054_2020-10-10_probe01__ - sync w/ spikes !!! |
| 23 | +# pid, t0 = ('04c9890f-2276-4c20-854f-305ff5c9b6cf', 1002.) # SWC_054_2020-10-10_probe00__04c9890f-2276-4c20-854f-305ff5c9b6cf - sync w/ spikes !!! |
| 24 | +# pid, t0 = ('0925fb1b-cf83-4f55-bfb7-aa52f993a404', 500.) # DY_013_2020-03-06_probe00__0925fb1b-cf83-4f55-bfb7-aa52f993a404 |
| 25 | +# pid, t0 = ('0ece5c6a-7d1e-4365-893d-ac1cc04f1d7b', 750.) # CSHL045_2020-02-27_probe01__0ece5c6a-7d1e-4365-893d-ac1cc04f1d7b |
| 26 | +# pid, t0 = ('0ece5c6a-7d1e-4365-893d-ac1cc04f1d7b', 3000.) # CSHL045_2020-02-27_probe01__0ece5c6a-7d1e-4365-893d-ac1cc04f1d7b |
| 27 | +pid, t0 = ('10ef1dcd-093c-4839-8f38-90a25edefb49', 2400.) |
| 28 | +# pid, t0 = ('1a6a17cc-ba8c-4d79-bf20-cc897c9500dc', 5000) |
| 29 | +# pid, t0 = ('2dd99c91-292f-44e3-bbf2-8cfa56015106', 2500) # NYU-23_2020-10-14_probe01__2dd99c91-292f-44e3-bbf2-8cfa56015106 |
| 30 | +# pid, t0 = ('2dd99c91-292f-44e3-bbf2-8cfa56015106', 6000) # NYU-23_2020-10-14_probe01__2dd99c91-292f-44e3-bbf2-8cfa56015106 |
| 31 | +# pid, t0 = ('30dfb8c6-9202-43fd-a92d-19fe68602b6f', 2400.) # ibl_witten_27_2021-01-16_probe00__30dfb8c6-9202-43fd-a92d-19fe68602b6f |
| 32 | +# pid, t0 = ('31dd223c-0c7c-48b5-a513-41feb4000133', 3000.) # really good one : striping on not all channels |
| 33 | +# pid, t0 = ('39b433d0-ec60-460f-8002-a393d81620a4', 2700.) # ZFM-01577_2020-10-27_probe01 needs FDNAT |
| 34 | +# pid, t0 = ('47da98a8-f282-4830-92c2-af0e1d4f00e2', 2700.) |
| 35 | + |
| 36 | +# 67 frequency spike |
| 37 | +# 458 /datadisk/Data/spike_sorting/short_samples/b45c8f3f-6361-41df-9bc1-9df98b3d30e6_01210.bin ERROR dans le chargement de la whitening matrix |
| 38 | +# 433 /datadisk/Data/spike_sorting/short_samples/8d59da25-3a9c-44be-8b1a-e27cdd39ca34_04210.bin Cortex complètement silencieux. |
| 39 | +# 531 /datadisk/Data/spike_sorting/short_samples/47be9ae4-290f-46ab-b047-952bc3a1a509_00010.bin Sympa pour le spike sorting, un bon example de trace pourrie à enlever avec FDNAT / Cadzow. Il y a du striping à la fin mais pas de souci pour KS2 ou pour le FK. |
| 40 | +# 618 5b9ce60c-dcc9-4789-b2ff-29d873829fa5_03610.bin: gros cabossage plat laissé par le FK !! Tester un filtre K tout bête # spikes tous petits en comparaison. Le spike sorting a l'air décalé |
| 41 | +# 681 /datadisk/Data/spike_sorting/short_samples/eab93ab0-26e3-4bd9-9c53-9f81c35172f4_02410.bin !! Spikes décalés. Superbe example de layering dans le cerveau avec 3 niveaux très clairement définis |
| 42 | +# 739 /datadisk/Data/spike_sorting/short_samples/f03b61b4-6b13-479d-940f-d1608eb275cc_04210.bin: Autre example de layering ou les charactéristiques spectrales / spatiales sont très différentes. Spikes alignés |
| 43 | +# 830 /datadisk/Data/spike_sorting/short_samples/b02c0ce6-2436-4fc0-9ea0-e7083a387d7e_03010.bin, très mauvaise qualité - spikes sont décalés ?!? |
| 44 | + |
| 45 | + |
| 46 | + |
| 47 | +file_ind = np.random.randint(len(files_samples)) |
| 48 | +file_ind = 739 # very good quality spike sorting |
| 49 | +print(file_ind, files_samples[file_ind]) |
| 50 | + |
| 51 | +pid, t0 = ('47da98a8-f282-4830-92c2-af0e1d4f00e2', 1425.) |
| 52 | + |
| 53 | +pid = files_samples[file_ind] |
| 54 | +# pid, t0 = ("01c6065e-eb3c-49ba-9c25-c1f17b18d529", 500) |
| 55 | +if isinstance(pid, Path): |
| 56 | + file_sample = pid |
| 57 | + pid, t0 = file_sample.stem.split('_') |
| 58 | + t0 = float(t0) |
| 59 | + sr = spikeglx.Reader(file_sample) |
| 60 | + dsets = one.alyx.rest('datasets', 'list', probe_insertion=pid) |
| 61 | +else: |
| 62 | + sr, dsets = stream(pid, t0, one=one, samples_folder=folder_samples) |
| 63 | + |
| 64 | +# |
| 65 | +plot_insertion(pid, one) |
| 66 | + |
| 67 | + |
| 68 | +h = neuropixel.trace_header() |
| 69 | +raw = sr[:, :-1].T |
| 70 | + |
| 71 | +sos = scipy.signal.butter(3, 300 / sr.fs / 2, btype='highpass', output='sos') |
| 72 | +butt = scipy.signal.sosfiltfilt(sos, raw) |
| 73 | +# show_psd(butt, sr.fs) |
| 74 | + |
| 75 | +fk_kwargs ={'dx': 1, 'vbounds': [0, 1e6], 'ntr_pad': 160, 'ntr_tap': 0, 'lagc': .01, 'btype': 'lowpass'} |
| 76 | +destripe = voltage.destripe(raw, fs=sr.fs, fk_kwargs=fk_kwargs, tr_sel=np.arange(raw.shape[0])) |
| 77 | +ks2 = get_ks2(raw, dsets, one) |
| 78 | + |
| 79 | +# get the spikes corresponding to current chunk, here needs to go through samples for sync reasons |
| 80 | +spikes, clusters, channels = get_spikes(dsets, one) |
| 81 | + |
| 82 | +if SIDE_BY_SIDE: |
| 83 | + hhh = {k: np.tile(h[k], 3) for k in h} |
| 84 | + eqc_concat = viewseis(np.r_[butt, destripe, ks2], si=1 / sr.fs, h=hhh, t0=t0, title='concat') |
| 85 | + overlay_spikes(eqc_concat, spikes, clusters, channels) |
| 86 | +else: |
| 87 | + eqc_butt = viewseis(butt.T, si=1 / sr.fs, h=h, t0=t0, title='butt', taxis=0) |
| 88 | + eqc_dest = viewseis(destripe.T, si=1 / sr.fs, h=h, t0=t0, title='destr', taxis=0) |
| 89 | + eqc_ks2 = viewseis(ks2.T, si=1 / sr.fs, h=h, t0=t0, title='ks2', taxis=0) |
| 90 | + overlay_spikes(eqc_butt, spikes, clusters, channels) |
| 91 | + overlay_spikes(eqc_dest, spikes, clusters, channels) |
| 92 | + overlay_spikes(eqc_ks2, spikes, clusters, channels) |
0 commit comments