Reproducing Elliott, Andrews et al. (2026): claims on the raw voltage¶
Paper: Elliott, Andrews et al., "Microscale maps of bursting dynamics across human hippocampal slices
from patients with epilepsy", J. Neurophysiol. (2026), doi:10.1152/jn.00217.2025; claims file
claims/elliott-2026.yaml, written from the accepted manuscript (PMC12931417) and its Extended Data.
Dataset: DANDI:001132 version 0.241130.1903 (the most recent published version; the paper cites no
version, and the two published versions list the same 69 assets; see the header of
reproduce_elliott_2026.ipynb). Raw voltage is streamed; spike sortings come from the paper's
repository at commit 0f83f70 (outside input). The link between sortings and raw files is
established in reproduce_elliott_2026.ipynb (claim sorting-dandiset-link) and repeated here in
short: recordings 1 to 6 are found in the dandiset, recordings 7 (S5) and 8 (S6) are not.
| Claim | Status here |
|---|---|
| table2-phase-locking-counts | tested on recordings 1 to 6; 7 and 8 have no raw recording |
| table2-phase-locking-seizure-vs-not | tested |
| fig2b-phase-cluster-kuiper | tested |
| ext3-onset-spectral-signature | tested |
| ext4-electrode-lag-clusters | tested on S1 to S4; S5 and S6 have no raw recording |
| fig1j-theta-propagation-stages | tested |
| ext4b-theta-delay | tested (one of two readings) |
| fig2a-subbursts-track-theta | tested |
| methods-rolling-wave-counts | blocked (methods_underspecified); the criterion's detector is run and shown |
import re, time, zlib, resource
import multiprocessing as mp
import numpy as np, pandas as pd
import matplotlib.pyplot as plt
from concurrent.futures import ProcessPoolExecutor
from scipy import stats, signal
from scipy.ndimage import gaussian_filter
from sklearn.cluster import KMeans
from astropy.stats import kuiper_two
import hippo as H
T0 = time.time()
POOL = ProcessPoolExecutor(4, mp_context=mp.get_context('fork')) # for hippo's module-level readers
def pmap(fn, items):
# a fresh forked pool, so that functions and data defined in the notebook are seen by the workers
with ProcessPoolExecutor(4, mp_context=mp.get_context('fork')) as p:
return list(p.map(fn, items))
print('dandiset', H.DANDISET_ID, 'version', H.DANDISET_VERSION, '; code commit', H.CODE_COMMIT)
dandiset 001132 version 0.241130.1903 ; code commit 0f83f704ee4c9b4d8d7f75eb53d94f525c85abb2
Data check¶
Loads the sortings and the electrode tables of the candidate files, and finds each sorting's file and offset with the same scan as the spike notebook (only among files whose electrode layout holds every unit position).
assets = H.list_assets()
A = {a['path'].split('/')[0]: a for a in assets}
SORT = {r: H.load_sorting(r) for r in H.RECORDINGS}
def elec_job(sub):
f = H.open_nwb(A[sub]['asset_id'])
d = f['acquisition/ElectricalSeries/data']
return sub, H.electrodes(f), d.shape, float(d.attrs['conversion'])
ELEC, SHAPE, CONV = {}, {}, {}
for sub, e, shp, cv in pmap(elec_job, sorted(A)):
ELEC[sub], SHAPE[sub], CONV[sub] = e, shp, cv
cand = {}
for r, s in SORT.items():
P = set(map(tuple, np.round(s['pos'], 1)))
cand[r] = [sub for sub, e in ELEC.items() if P <= set(zip(np.round(e.x, 1), np.round(e.y, 1)))]
print(r, H.RECORDINGS[r]['slice'], H.RECORDINGS[r]['cond'], s['n'], 'units,', f"{s['length_ms']/60000:.2f} min sorted; layout matches", cand[r])
1 S1 KA 212 units, 6.00 min sorted; layout matches ['sub-10F-1', 'sub-10F-2', 'sub-10F-3', 'sub-10F-4', 'sub-10F-5', 'sub-10F-6', 'sub-10F-7', 'sub-10F-8'] 2 S1 baseline 249 units, 4.55 min sorted; layout matches ['sub-10F-0'] 3 S2 KA 180 units, 8.50 min sorted; layout matches ['sub-11G-0', 'sub-11G-1', 'sub-11G-2', 'sub-11G-3', 'sub-11G-4'] 4 S2 baseline 51 units, 5.01 min sorted; layout matches ['sub-11G-0', 'sub-11G-1', 'sub-11G-2', 'sub-11G-3', 'sub-11G-4'] 5 S3 no drug 87 units, 6.97 min sorted; layout matches ['sub-1A-0'] 6 S4 KA 109 units, 2.17 min sorted; layout matches ['sub-9E-0', 'sub-9E-1', 'sub-9E-2', 'sub-9E-3', 'sub-9E-4', 'sub-9E-5', 'sub-9E-6', 'sub-9E-7', 'sub-9E-8'] 7 S5 no drug 136 units, 6.42 min sorted; layout matches ['sub-3C-0', 'sub-3C-1', 'sub-3C-2', 'sub-3C-3', 'sub-3C-4', 'sub-3C-5', 'sub-3C-6', 'sub-3C-7'] 8 S6 no drug 100 units, 1.77 min sorted; layout matches ['sub-8D-0', 'sub-8D-1', 'sub-8D-2', 'sub-8D-3', 'sub-8D-4']
t = time.time()
def scan(job):
r, sub = job
return (r, sub) + H.offset_scan(A[sub]['asset_id'], SORT[r])
SCAN = pd.DataFrame(list(pmap(scan, [(r, sub) for r in SORT for sub in cand[r]])), columns=['rec', 'file', 'offset_s', 'peak', 'chance'])
SCAN['ratio'] = SCAN.peak / SCAN.chance
LINK = {}
for r in SORT:
d = SCAN[SCAN.rec == r]; hit = d[d.ratio > 10]
if len(hit) == 1:
LINK[r] = (hit.file.iloc[0], round(float(hit.offset_s.iloc[0]), 3))
print(r, H.RECORDINGS[r]['slice'], H.RECORDINGS[r]['cond'], '->', LINK.get(r, 'no file matched'), f'best ratio {d.ratio.max():.1f}')
for r, (sub, off) in LINK.items():
e = ELEC[sub]
print(f"{sub}: {SHAPE[sub][1]} channels, {SHAPE[sub][0]/H.FS:.1f} s at {H.FS:.0f} Hz, {CONV[sub]*1e6:.3f} uV per count; "
f"electrodes x {e.x.min():.0f}-{e.x.max():.0f}, y {e.y.min():.0f}-{e.y.max():.0f} um; sorting spans file time {off:.1f} to {off + SORT[r]['length_ms']/1000:.1f} s")
print(f'{time.time()-t:.0f} s')
1 S1 KA -> ('sub-10F-6', 0.0) best ratio 83.0
2 S1 baseline -> ('sub-10F-0', 20.0) best ratio 77.5
3 S2 KA -> ('sub-11G-2', -0.0) best ratio 160.9
4 S2 baseline -> ('sub-11G-4', 0.0) best ratio 99.4
5 S3 no drug -> ('sub-1A-0', -0.0) best ratio 169.0
6 S4 KA -> ('sub-9E-2', 30.0) best ratio 73.8
7 S5 no drug -> no file matched best ratio 1.3
8 S6 no drug -> no file matched best ratio 1.4
sub-10F-6: 1009 channels, 360.1 s at 20000 Hz, 1.574 uV per count; electrodes x 158-2608, y 18-1768 um; sorting spans file time 0.0 to 360.1 s
sub-10F-0: 887 channels, 313.1 s at 20000 Hz, 1.574 uV per count; electrodes x 158-2608, y 18-1732 um; sorting spans file time 20.0 to 293.1 s
sub-11G-2: 894 channels, 510.2 s at 20000 Hz, 1.574 uV per count; electrodes x 858-3150, y 0-1260 um; sorting spans file time -0.0 to 510.2 s
sub-11G-4: 894 channels, 300.9 s at 20000 Hz, 1.574 uV per count; electrodes x 858-3150, y 0-1260 um; sorting spans file time 0.0 to 300.9 s
sub-1A-0: 995 channels, 418.4 s at 20000 Hz, 6.294 uV per count; electrodes x 1138-3728, y 508-1872 um; sorting spans file time -0.0 to 418.4 s
sub-9E-2: 936 channels, 160.1 s at 20000 Hz, 1.574 uV per count; electrodes x 1032-2608, y 192-1768 um; sorting spans file time 30.0 to 160.0 s
514 s
LFP at the units' electrodes¶
For recordings 1 to 6, the 1 kHz LFP (hippo.lfp_1khz: 20-sample means of the raw voltage) of the
electrode nearest each unit, over the whole span of the sorting, on the sorting's clock (file time
minus the offset found above). Every unit position is an electrode position (data check), so the
nearest electrode is the unit's own best channel.
t = time.time()
ULFP, UCH, UCOL = {}, {}, {}
for r, (sub, off) in LINK.items():
e = ELEC[sub]
ch = np.array([int(np.argmin((e.x - x) ** 2 + (e.y - y) ** 2)) for x, y in SORT[r]['pos']])
uch = np.unique(ch)
X = H.lfp_1khz(A[sub]['asset_id'], uch, off, off + SORT[r]['length_ms'] / 1000, len(e), POOL)
ULFP[r] = X; UCH[r] = ch; UCOL[r] = {c: i for i, c in enumerate(uch)}
dist = np.hypot(e.x.values[ch] - SORT[r]['pos'][:, 0], e.y.values[ch] - SORT[r]['pos'][:, 1])
print(r, sub, X.shape, f'max unit-electrode distance {dist.max():.1f} um; LFP range {X.min():.0f} to {X.max():.0f} uV; {time.time()-t:.0f} s')
print(f'peak memory {resource.getrusage(resource.RUSAGE_SELF).ru_maxrss/1e6:.1f} GB')
1 sub-10F-6 (360098, 149) max unit-electrode distance 0.0 um; LFP range 635 to 919 uV; 96 s
2 sub-10F-0 (273149, 136) max unit-electrode distance 0.0 um; LFP range 304 to 897 uV; 169 s
3 sub-11G-2 (510217, 133) max unit-electrode distance 0.0 um; LFP range 564 to 909 uV; 297 s
4 sub-11G-4 (300875, 42) max unit-electrode distance 0.0 um; LFP range 189 to 896 uV; 371 s
5 sub-1A-0 (418416, 78) max unit-electrode distance 0.0 um; LFP range 2650 to 4959 uV; 477 s
6 sub-9E-2 (130000, 90) max unit-electrode distance 0.0 um; LFP range 384 to 876 uV; 512 s peak memory 2.7 GB
Values taken from the paper's code¶
The seizure and non-seizure windows, the spans of the other recordings, the sub-burst times and the
phase-cluster thresholds are set by hand in the paper's code (claims file). They are defined here
and printed beside their source at the pinned commit: the windows and spans are the start and stop
times in the names of the LFP files the code saved (data/ephys_raw/; the S1 windows also appear,
commented out, in TJ_phase_locking_basics.ipynb, and the S2 windows there as active code); the
spans of recordings 2 and 5 include files whose times are not in the saving notebooks
(get_raw_data/hc112823_base.ipynb lists four of the five S1 baseline spans, hc111.ipynb one of
the three S3 spans). The code filters theta within each saved window (the butter_filter line
printed below), as is done here.
SEIZ = {1: [(9,28),(38,52),(69,83),(100,113),(138,151),(176,187),(211,220),(246,254)],
3: [(0,11),(25,39),(139,148),(168,174),(258,263),(320,328),(481,487)]}
NONS = {1: [(28,38),(54,66),(85,97),(115,127),(155,167),(193,205),(228,240),(260,272)],
3: [(50,60),(100,113),(200,212),(270,275),(392,400),(400,406),(450,455)]}
SPANS_FILE = {2: [(25,35),(60,70),(105,115),(150,160),(250,260)], 4: [(60,70),(100,110),(150,160),(200,210),(250,260)],
5: [(34,44),(200,210),(325,335)], 6: [(33,43),(110,120),(145,155)], 7: [(120,130),(190,200),(350,365)], 8: [(6,16),(19,29),(50,60)]}
SUBB = {1: [14.4, 14.57, 14.75, 14.91], 3: [35.208, 35.234, 35.265, 35.302]}
def code_group1(pos):
x, y = pos[:, 0], pos[:, 1]
return (x < 940) | ((x == 945) & (y < 1120)) | ((x > 900) & (y < 900))
tree = H.code_tree()
RAW = 'data/ephys_raw/'
sources = {(1, 'seizure'): '2023-12-03-e-Hc112823_avv9hckcr1/seizure/', (1, 'nonseizure'): '2023-12-03-e-Hc112823_avv9hckcr1/nonseizure/',
(3, 'seizure'): '2023-12-11-e-Hc120523_aav9hckcr1_chip21769/seizure/', (3, 'nonseizure'): '2023-12-11-e-Hc120523_aav9hckcr1_chip21769/nonseizure/',
(2, 'spans'): '2023-12-03-e-Hc112823_avv9hckcr1/baseline/base_', (4, 'spans'): '2023-12-11-e-Hc120523_aav9hckcr1_chip21769/baseline/base_',
(5, 'spans'): '2022-11-02-e-Hc11.1-chip16753/immediate_', (6, 'spans'): '2023-11-13-e-Hc110723_hckcr1_21841/acid1_',
(7, 'spans'): '2023-04-02-e-hc328_unperturbed/raw_', (8, 'spans'): '2023-05-10-e-hc52_18790_unperturbed/raw_'}
used = {**{(r, 'seizure'): w for r, w in SEIZ.items()}, **{(r, 'nonseizure'): w for r, w in NONS.items()}, **{(r, 'spans'): w for r, w in SPANS_FILE.items()}}
for k, pre in sources.items():
files = sorted(p[len(RAW):] for p in tree if p.startswith(RAW + pre) and '/' not in p[len(RAW + pre):] and p.endswith('_fs1ms.pkl'))
found = sorted(tuple(int(v) for v in re.search(r'start(\d+)s_stop(\d+)s', f).groups()) for f in files)
print(k, '| files:', [f.split('/')[-1] for f in files], '| used here equal:', found == sorted(used[k]))
TJ = 'figures/figure_3/TJ_phase_locking_basics.ipynb'
lines = H.code_lines(TJ, r'^#?\s*\[\d+, \d+\]')
act = [tuple(int(v) for v in re.findall(r'\d+', l)) for _, _, l in lines if not l.startswith('#')]
com = [tuple(int(v) for v in re.findall(r'\d+', l)) for _, _, l in lines if l.startswith('#')]
print(f'{TJ} cell {lines[0][0]}: active windows {act}; equal to the S2 seizure and non-seizure windows: {act == SEIZ[3] + NONS[3]}')
print(f' commented windows {com}; the first 16 equal to the S1 seizure and non-seizure windows: {com[:16] == SEIZ[1] + NONS[1]}')
for h in H.code_lines(TJ, r'theta_filt = butter_filter|NUM_CLOSEST =|RMS_MULT ='):
print(f' cell {h[0]} line {h[1]}: {h[2]}')
for r, path in {1: 'figures/figure_2/burst_peak_comparison.ipynb', 3: 'figures/supplement/seizure_2/seizure2_burst_peaks.ipynb'}.items():
hits = H.code_lines(path, r'subtime')
for h in hits:
print(f'{path} cell {h[0]} line {h[1]}: {h[2]}')
vals = sorted({float(v) for _, _, l in hits for v in re.findall(r'(\d+\.\d+)\s*\*\s*1000', l)})
print(' sub-burst edges used here', SUBB[r], '| equal:', vals == SUBB[r])
h = H.code_lines('figures/figure_3/Phase_lock_heatmap.ipynb', r'sig_x<940')[0]
print(f'figures/figure_3/Phase_lock_heatmap.ipynb cell {h[0]} line {h[1]}: {h[2]}')
(1, 'seizure') | files: ['acid1_start100s_stop113s_fs1ms.pkl', 'acid1_start138s_stop151s_fs1ms.pkl', 'acid1_start176s_stop187s_fs1ms.pkl', 'acid1_start211s_stop220s_fs1ms.pkl', 'acid1_start246s_stop254s_fs1ms.pkl', 'acid1_start38s_stop52s_fs1ms.pkl', 'acid1_start69s_stop83s_fs1ms.pkl', 'acid1_start9s_stop28s_fs1ms.pkl'] | used here equal: True (1, 'nonseizure') | files: ['acid1_start115s_stop127s_fs1ms.pkl', 'acid1_start155s_stop167s_fs1ms.pkl', 'acid1_start193s_stop205s_fs1ms.pkl', 'acid1_start228s_stop240s_fs1ms.pkl', 'acid1_start260s_stop272s_fs1ms.pkl', 'acid1_start28s_stop38s_fs1ms.pkl', 'acid1_start54s_stop66s_fs1ms.pkl', 'acid1_start85s_stop97s_fs1ms.pkl'] | used here equal: True (3, 'seizure') | files: ['acid1_start0s_stop11s_fs1ms.pkl', 'acid1_start139s_stop148s_fs1ms.pkl', 'acid1_start168s_stop174s_fs1ms.pkl', 'acid1_start258s_stop263s_fs1ms.pkl', 'acid1_start25s_stop39s_fs1ms.pkl', 'acid1_start320s_stop328s_fs1ms.pkl', 'acid1_start481s_stop487s_fs1ms.pkl'] | used here equal: True (3, 'nonseizure') | files: ['acid1_start100s_stop113s_fs1ms.pkl', 'acid1_start200s_stop212s_fs1ms.pkl', 'acid1_start270s_stop275s_fs1ms.pkl', 'acid1_start392s_stop400s_fs1ms.pkl', 'acid1_start400s_stop406s_fs1ms.pkl', 'acid1_start450s_stop455s_fs1ms.pkl', 'acid1_start50s_stop60s_fs1ms.pkl'] | used here equal: True (2, 'spans') | files: ['base_start105s_stop115s_fs1ms.pkl', 'base_start150s_stop160s_fs1ms.pkl', 'base_start250s_stop260s_fs1ms.pkl', 'base_start25s_stop35s_fs1ms.pkl', 'base_start60s_stop70s_fs1ms.pkl'] | used here equal: True (4, 'spans') | files: ['base_start100s_stop110s_fs1ms.pkl', 'base_start150s_stop160s_fs1ms.pkl', 'base_start200s_stop210s_fs1ms.pkl', 'base_start250s_stop260s_fs1ms.pkl', 'base_start60s_stop70s_fs1ms.pkl'] | used here equal: True (5, 'spans') | files: ['immediate_start200s_stop210s_fs1ms.pkl', 'immediate_start325s_stop335s_fs1ms.pkl', 'immediate_start34s_stop44s_fs1ms.pkl'] | used here equal: True (6, 'spans') | files: ['acid1_start110s_stop120s_fs1ms.pkl', 'acid1_start145s_stop155s_fs1ms.pkl', 'acid1_start33s_stop43s_fs1ms.pkl'] | used here equal: True (7, 'spans') | files: ['raw_start120s_stop130s_fs1ms.pkl', 'raw_start190s_stop200s_fs1ms.pkl', 'raw_start350s_stop365s_fs1ms.pkl'] | used here equal: True (8, 'spans') | files: ['raw_start19s_stop29s_fs1ms.pkl', 'raw_start50s_stop60s_fs1ms.pkl', 'raw_start6s_stop16s_fs1ms.pkl'] | used here equal: True
figures/figure_3/TJ_phase_locking_basics.ipynb cell 1: active windows [(0, 11), (25, 39), (139, 148), (168, 174), (258, 263), (320, 328), (481, 487), (50, 60), (100, 113), (200, 212), (270, 275), (392, 400), (400, 406), (450, 455)]; equal to the S2 seizure and non-seizure windows: True commented windows [(9, 28), (38, 52), (69, 83), (100, 113), (138, 151), (176, 187), (211, 220), (246, 254), (28, 38), (54, 66), (85, 97), (115, 127), (155, 167), (193, 205), (228, 240), (260, 272), (19, 29), (50, 60), (6, 16)]; the first 16 equal to the S1 seizure and non-seizure windows: True cell 3 line 4: NUM_CLOSEST = 1 cell 3 line 5: RMS_MULT = 1 cell 3 line 107: theta_filt = butter_filter(data_raw["data"], 4, 8, fs=data_raw["frame_rate"]) cell 6 line 17: theta_filt = butter_filter(data_raw["data"], 4, 8, fs=data_raw["frame_rate"])
figures/figure_2/burst_peak_comparison.ipynb cell 5 line 1: sd1 = sd.subtime( 14.4*1000 , 14.57*1000 ) figures/figure_2/burst_peak_comparison.ipynb cell 5 line 2: sd2 = sd.subtime( 14.57*1000 , 14.75*1000 ) figures/figure_2/burst_peak_comparison.ipynb cell 5 line 3: sd3 = sd.subtime( 14.75*1000, 14.91*1000 ) sub-burst edges used here [14.4, 14.57, 14.75, 14.91] | equal: True
figures/supplement/seizure_2/seizure2_burst_peaks.ipynb cell 7 line 1: sd1 = sd.subtime( 35.208*1000 , 35.234*1000 ) figures/supplement/seizure_2/seizure2_burst_peaks.ipynb cell 7 line 2: sd2 = sd.subtime( 35.234*1000 , 35.265*1000 ) figures/supplement/seizure_2/seizure2_burst_peaks.ipynb cell 7 line 3: sd3 = sd.subtime( 35.265*1000 , 35.302*1000 ) sub-burst edges used here [35.208, 35.234, 35.265, 35.302] | equal: True
figures/figure_3/Phase_lock_heatmap.ipynb cell 9 line 1: g1 = np.logical_or( np.logical_or( sig_x<940, np.logical_and(sig_x==945,sig_y<1120) ) , np.logical_and(sig_x>900,sig_y<900) )
table2-phase-locking-counts¶
Significantly theta phase-locked units are 70 of 212 (33%) in the S1 KA recording and 101 of 180 (56%) in the S2 KA recording, against 14 of 249, 2 of 51, 8 of 87, 6 of 109, 8 of 136 and 1 of 100 in the other recordings.
Theta 4 to 8 Hz (order-5 Butterworth, zero phase), Hilbert phase and envelope, per window (as the code
filters each saved window, printed above); Rayleigh
test p < 0.05 per unit (astropy). Spike selection: the Methods (envelope above the RMS of the theta
series), with the RMS taken over the analysed windows (envelope) and over the whole recording
(envelope_whole_rms, the Methods' "RMS of the whole time series", the criterion's wording), and
the code's cycle selection as a variant. Over the whole recording the two envelope readings are
the same. Recordings 1 and 3:
the code's seizure windows. Others: the whole recording, and the code's get_raw_data spans as a
second reading. Those spans are in the raw file's time (the S4 span 145 to 155 s lies beyond the
130 s sorting and inside the 160 s file), so they are moved to the sorting's clock by the offset
found above; parts outside the sorting are dropped.
def spans_sorting(r):
off = LINK[r][1]; L = SORT[r]['length_ms'] / 1000
out = [(max(a - off, 0), min(b - off, L)) for a, b in SPANS_FILE[r]]
return [(a, b) for a, b in out if b - a > 1]
def lock_job(args):
r, wins, mode = args
X = ULFP[r]; res = []
cache = {}
for u in range(SORT[r]['n']):
c = UCOL[r][UCH[r][u]]
if c not in cache:
th = [(a * 1000, H.theta(X[int(a * 1000):int(b * 1000), c])) for a, b in wins]
# the Methods' "RMS of the whole time series": the theta of the whole recording at this electrode
rms = float(np.sqrt(np.mean(H.theta(X[:, c]) ** 2))) if mode == 'envelope_whole_rms' else None
cache[c] = (th, rms)
th, rms = cache[c]
res.append(H.phase_lock_unit(SORT[r]['trains'][u], th, 'envelope' if mode == 'envelope_whole_rms' else mode, rms))
return pd.DataFrame(res, columns=['n_spikes', 'p', 'mean_angle'])
jobs = {}
for r in LINK:
sets = {'whole': [(0, SORT[r]['length_ms'] / 1000)]}
if r in SEIZ:
sets.update(seizure=SEIZ[r], nonseizure=NONS[r])
else:
sets['code_spans'] = spans_sorting(r)
for name, wins in sets.items():
for mode in ('envelope', 'envelope_whole_rms', 'cycle'):
jobs[(r, name, mode)] = (r, wins, mode)
t = time.time()
LOCK = dict(zip(jobs, pmap(lock_job, list(jobs.values()))))
rows = []
for (r, name, mode), d in LOCK.items():
rows.append(dict(rec=r, slice=H.RECORDINGS[r]['slice'], cond=H.RECORDINGS[r]['cond'], span=name, selection=mode, units=len(d),
significant=int((d.p < 0.05).sum()), percent=100 * (d.p < 0.05).mean(), units_no_spikes=int((d.n_spikes < 2).sum()),
median_spikes_kept=float(d.n_spikes.median())))
PL = pd.DataFrame(rows)
print(PL.round(1).to_string(index=False)); print(f'{time.time()-t:.0f} s')
print('spans used (sorting clock):', {r: spans_sorting(r) for r in LINK if r not in SEIZ})
rec slice cond span selection units significant percent units_no_spikes median_spikes_kept
1 S1 KA whole envelope 212 50 23.6 0 717.0
1 S1 KA whole envelope_whole_rms 212 50 23.6 0 717.0
1 S1 KA whole cycle 212 74 34.9 0 689.0
1 S1 KA seizure envelope 212 60 28.3 0 332.5
1 S1 KA seizure envelope_whole_rms 212 59 27.8 0 348.0
1 S1 KA seizure cycle 212 73 34.4 0 319.5
1 S1 KA nonseizure envelope 212 11 5.2 19 107.5
1 S1 KA nonseizure envelope_whole_rms 212 12 5.7 20 101.0
1 S1 KA nonseizure cycle 212 12 5.7 16 100.0
2 S1 baseline whole envelope 249 19 7.6 0 651.0
2 S1 baseline whole envelope_whole_rms 249 19 7.6 0 651.0
2 S1 baseline whole cycle 249 24 9.6 0 644.0
2 S1 baseline code_spans envelope 249 12 4.8 2 123.0
2 S1 baseline code_spans envelope_whole_rms 249 12 4.8 3 125.0
2 S1 baseline code_spans cycle 249 20 8.0 2 124.0
3 S2 KA whole envelope 180 102 56.7 0 607.5
3 S2 KA whole envelope_whole_rms 180 102 56.7 0 607.5
3 S2 KA whole cycle 180 105 58.3 0 577.5
3 S2 KA seizure envelope 180 104 57.8 3 212.0
3 S2 KA seizure envelope_whole_rms 180 104 57.8 3 269.5
3 S2 KA seizure cycle 180 107 59.4 3 199.0
3 S2 KA nonseizure envelope 180 8 4.4 46 12.5
3 S2 KA nonseizure envelope_whole_rms 180 7 3.9 53 10.5
3 S2 KA nonseizure cycle 180 9 5.0 50 12.0
4 S2 baseline whole envelope 51 5 9.8 0 254.0
4 S2 baseline whole envelope_whole_rms 51 5 9.8 0 254.0
4 S2 baseline whole cycle 51 3 5.9 0 245.0
4 S2 baseline code_spans envelope 51 0 0.0 1 40.0
4 S2 baseline code_spans envelope_whole_rms 51 0 0.0 1 39.0
4 S2 baseline code_spans cycle 51 3 5.9 1 38.0
5 S3 no drug whole envelope 87 11 12.6 0 174.0
5 S3 no drug whole envelope_whole_rms 87 11 12.6 0 174.0
5 S3 no drug whole cycle 87 5 5.7 0 178.0
5 S3 no drug code_spans envelope 87 10 11.5 6 15.0
5 S3 no drug code_spans envelope_whole_rms 87 8 9.2 7 15.0
5 S3 no drug code_spans cycle 87 5 5.7 5 15.0
6 S4 KA whole envelope 109 3 2.8 1 123.0
6 S4 KA whole envelope_whole_rms 109 3 2.8 1 123.0
6 S4 KA whole cycle 109 14 12.8 2 111.0
6 S4 KA code_spans envelope 109 5 4.6 7 41.0
6 S4 KA code_spans envelope_whole_rms 109 5 4.6 8 41.0
6 S4 KA code_spans cycle 109 6 5.5 8 40.0
112 s
spans used (sorting clock): {2: [(5.0, 15.0), (40.0, 50.0), (85.0, 95.0), (130.0, 140.0), (230.0, 240.0)], 4: [(60.0, 70.0), (100.0, 110.0), (150.0, 160.0), (200.0, 210.0), (250.0, 260.0)], 5: [(34.0, 44.0), (200.0, 210.0), (325.0, 335.0)], 6: [(3.0, 13.0), (80.0, 90.0), (115.0, 125.0)]}
exp_pl = {1: 70, 2: 14, 3: 101, 4: 2, 5: 8, 6: 6, 7: 8, 8: 1}
tol_pl = {1: 7, 2: 1.4, 3: 10.1, 4: 1, 5: 1, 6: 1, 7: 1, 8: 1}
rows = []
for mode in ('envelope', 'envelope_whole_rms', 'cycle'):
for reading in ('whole', 'code_spans'):
row = dict(selection=mode, reading_others=reading)
n_ok = 0
for r in LINK:
span = 'seizure' if r in SEIZ else reading
v = int(PL[(PL.rec == r) & (PL.span == span) & (PL.selection == mode)].significant.iloc[0])
ok = abs(v - exp_pl[r]) <= tol_pl[r]
row[f'r{r}'] = f"{v}{'*' if ok else ''}"
n_ok += ok
row['within_tol_of_6'] = n_ok
rows.append(row)
print('count per recording (* within tolerance); recordings 7 and 8 have no raw recording in the dandiset')
print(pd.DataFrame(rows).to_string(index=False))
count per recording (* within tolerance); recordings 7 and 8 have no raw recording in the dandiset
selection reading_others r1 r2 r3 r4 r5 r6 within_tol_of_6
envelope whole 60 19 104* 5 11 3 1
envelope code_spans 60 12 104* 0 10 5* 2
envelope_whole_rms whole 59 19 104* 5 11 3 1
envelope_whole_rms code_spans 59 12 104* 0 8* 5* 3
cycle whole 73* 24 107* 3* 5 14 3
cycle code_spans 73* 20 107* 3* 5 6* 4
# null: the same test with each unit's spike times shifted circularly by a random amount within its windows
rng = np.random.default_rng(zlib.crc32(b"elliott-2026/table2-phase-locking-counts"))
def shifted(r, wins, shift_ms):
out = []
for u, tr in enumerate(SORT[r]['trains']):
parts = []
for a, b in wins:
x = tr[(tr >= a * 1000) & (tr < b * 1000)]
parts.append(a * 1000 + np.mod(x - a * 1000 + shift_ms[u], (b - a) * 1000))
out.append(np.sort(np.concatenate(parts)) if parts else tr)
return out
for r in (1, 3):
sh = rng.uniform(1000, 5000, SORT[r]['n'])
tr_s = shifted(r, SEIZ[r], sh)
X = ULFP[r]; cnt = 0
cache = {}
for u in range(SORT[r]['n']):
c = UCOL[r][UCH[r][u]]
if c not in cache:
cache[c] = [(a * 1000, H.theta(X[int(a * 1000):int(b * 1000), c])) for a, b in SEIZ[r]]
cnt += H.phase_lock_unit(tr_s[u], cache[c], 'envelope')[1] < 0.05
print(H.RECORDINGS[r]['slice'], 'seizure windows, spikes shifted 1 to 5 s within each window:', int(cnt), 'of', SORT[r]['n'], 'significant (chance level 5% =', round(0.05 * SORT[r]['n'], 1), ')')
S1 seizure windows, spikes shifted 1 to 5 s within each window: 10 of 212 significant (chance level 5% = 10.6 )
S2 seizure windows, spikes shifted 1 to 5 s within each window: 15 of 180 significant (chance level 5% = 9.0 )
Result: not reproduced. With the Methods' spike selection the counts are 60 (S1 KA, seizure windows, 70 expected), 104 (S2 KA, 101), and for recordings 2, 4, 5 and 6 19, 5, 11 and 3 over the whole recording or 12, 0, 10 and 5 over the code's spans (14, 2, 8 and 6 expected): 1 or 2 of the 6 testable counts are within tolerance. With the RMS taken over the whole recording (the Methods' "RMS of the whole time series") the counts are 59 (S1) and 104 (S2), and 19, 5, 11 and 3 or 12, 0, 8 and 5 for the others: 1 or 3 of 6 within tolerance, and S1 misses under every envelope reading. With the code's cycle selection (variant) S1 and S2 match (73 and 107) and 3 to 4 of 6 are within tolerance; over the code's spans every other recording is below 10% (5.5 to 8.0%). Recordings 7 and 8 have no raw recording in the dandiset. Shifting spikes within the seizure windows gives 10 of 212 and 15 of 180, near the 5% chance level.
table2-phase-locking-seizure-vs-not¶
During seizure-like activity on average 45% of units per recording are phase locked, against 5% in recordings without seizure-like activity; within S1 and S2, only 5% and 4% are phase locked outside the seizure periods.
The mean over recordings 1 and 3 (seizure windows), the mean over the recordings without seizure-like activity that have raw data here (2, 4, 5, 6; 7 and 8 are missing), and the non-seizure windows of recordings 1 and 3.
rows = []
for mode in ('envelope', 'envelope_whole_rms', 'cycle'):
for reading in ('whole', 'code_spans'):
g = lambda r, span: float(PL[(PL.rec == r) & (PL.span == span) & (PL.selection == mode)].percent.iloc[0])
seiz = np.mean([g(1, 'seizure'), g(3, 'seizure')])
other = np.mean([g(r, reading) for r in (2, 4, 5, 6)])
n1, n3 = g(1, 'nonseizure'), g(3, 'nonseizure')
vals = [seiz, other, n1, n3]; exp = [45, 5, 5, 4]
ok = [abs(v - x) <= 0.1 * x for v, x in zip(vals, exp)]
rows.append(dict(selection=mode, reading_others=reading, seizure_mean=seiz, others_mean=other, S1_nonseizure=n1, S2_nonseizure=n3,
n_within_tol=sum(ok), all_others_below_10=all(v < 10 for v in vals[1:]), seizure_ok=ok[0]))
print(pd.DataFrame(rows).round(2).to_string(index=False))
selection reading_others seizure_mean others_mean S1_nonseizure S2_nonseizure n_within_tol all_others_below_10 seizure_ok
envelope whole 43.04 8.21 5.19 4.44 2 True True
envelope code_spans 43.04 5.23 5.19 4.44 3 True True
envelope_whole_rms whole 42.80 8.21 5.66 3.89 2 True True
envelope_whole_rms code_spans 42.80 4.65 5.66 3.89 3 True True
cycle whole 46.94 8.53 5.66 5.00 1 True True
cycle code_spans 46.94 6.29 5.66 5.00 1 True True
Result: partially reproduced. The seizure mean is 43.0% with the Methods' selection (within 40.5 to 49.5) and 46.9% with the code's. Outside the seizure windows 5.2% (S1, within tolerance) and 4.4% (S2, 8 of 180 units, just above the 4.4% bound) are phase locked. The mean over recordings 2, 4, 5 and 6 is 8.2% over whole recordings and 5.2% over the code's spans (within tolerance), so all four values match under no reading, and every value other than the seizure mean is below 10%. With the RMS over the whole recording the values are 42.8%, 8.2% or 4.7%, 5.7% and 3.9%: 2 or 3 of 4 within tolerance, every value other than the seizure mean below 10%.
fig2b-phase-cluster-kuiper¶
In S1 the significantly phase-locked units form two spatial groups along the granule cell layer whose preferred theta phases differ significantly (Kuiper test).
Units significant in the seizure windows (main) and over the whole KA recording (variant), each under the Methods' and the code's spike selection. Splits: (a) the code's position thresholds, with duplicate positions removed as the code does; (b) the angular difference from the polar mode split at its median (polar mode from a 36-bin histogram, a standard choice); (c) k-means with 2 clusters on unit position. Kuiper two-sample test (astropy kuiper_two).
seed = zlib.crc32(b"elliott-2026/fig2b-phase-cluster-kuiper")
rows = []
for span in ('seizure', 'whole'):
for mode in ('envelope', 'envelope_whole_rms', 'cycle'):
d = LOCK[(1, span, mode)]; sig = np.where(d.p < 0.05)[0]
ang = d.mean_angle.values[sig]; pos = SORT[1]['pos'][sig]
h, ed = np.histogram(np.mod(ang, 2 * np.pi), 36, (0, 2 * np.pi)); mode_ang = (ed[h.argmax()] + ed[h.argmax() + 1]) / 2
diff = np.abs(np.angle(np.exp(1j * (ang - mode_ang))))
_, first = np.unique(pos, axis=0, return_index=True); dedup = np.zeros(len(sig), bool); dedup[first] = True
splits = {'a_code_thresholds': (code_group1(pos), dedup),
'b_median_angular_difference': (diff > np.median(diff), np.ones(len(sig), bool)),
'c_kmeans_position': (KMeans(2, n_init=10, random_state=seed).fit_predict(pos) == 1, np.ones(len(sig), bool))}
for name, (g, keep) in splits.items():
g1, g2 = ang[g & keep], ang[~g & keep]
D, p = kuiper_two(np.mod(g1, 2 * np.pi), np.mod(g2, 2 * np.pi)) if len(g1) > 1 and len(g2) > 1 else (np.nan, np.nan)
m1 = np.degrees(np.angle(np.mean(np.exp(1j * g1)))); m2 = np.degrees(np.angle(np.mean(np.exp(1j * g2))))
rows.append(dict(units=span, selection=mode, n_sig=len(sig), split=name, n1=len(g1), n2=len(g2),
mean_angle1_deg=m1, mean_angle2_deg=m2, kuiper_D=D, p=p))
K2 = pd.DataFrame(rows)
print(K2.round(4).to_string(index=False))
units selection n_sig split n1 n2 mean_angle1_deg mean_angle2_deg kuiper_D p seizure envelope 60 a_code_thresholds 32 26 -179.2759 -69.0452 0.4447 0.0371 seizure envelope 60 b_median_angular_difference 30 30 -0.5719 -157.9111 1.0000 0.0000 seizure envelope 60 c_kmeans_position 29 31 -176.9597 -79.9284 0.3849 0.1148 seizure envelope_whole_rms 59 a_code_thresholds 29 27 -179.3202 -70.3154 0.4700 0.0228 seizure envelope_whole_rms 59 b_median_angular_difference 29 30 -1.0636 -151.6384 1.0000 -0.0000 seizure envelope_whole_rms 59 c_kmeans_position 27 32 -174.3008 -76.6818 0.4653 0.0200 seizure cycle 73 a_code_thresholds 35 28 4.9113 -37.6351 0.5071 0.0042 seizure cycle 73 b_median_angular_difference 36 37 -134.0460 -5.1677 1.0000 -0.0000 seizure cycle 73 c_kmeans_position 32 41 -45.7045 6.0345 0.5061 0.0014 whole envelope 50 a_code_thresholds 22 26 -175.5615 -97.6197 0.4860 0.0352 whole envelope 50 b_median_angular_difference 25 25 -11.9073 -154.3543 1.0000 -0.0000 whole envelope 50 c_kmeans_position 29 21 -97.1603 -169.8032 0.4647 0.0505 whole envelope_whole_rms 50 a_code_thresholds 22 26 -175.5615 -97.6197 0.4860 0.0352 whole envelope_whole_rms 50 b_median_angular_difference 25 25 -11.9073 -154.3543 1.0000 -0.0000 whole envelope_whole_rms 50 c_kmeans_position 29 21 -97.1603 -169.8032 0.4647 0.0505 whole cycle 74 a_code_thresholds 35 32 -27.1995 -41.9982 0.5375 0.0008 whole cycle 74 b_median_angular_difference 37 37 -114.3550 -15.5814 1.0000 -0.0000 whole cycle 74 c_kmeans_position 37 37 -25.5992 -46.8335 0.4324 0.0130
Result: reproduced. With the 60 units significant in the seizure windows (Methods' selection), the Methods' split by angular difference from the polar mode (reading b) gives Kuiper p below 1e-4; by construction this split separates the angles it then tests. The spatial splits give p = 0.037 (code's thresholds, 32 and 26 units after removing duplicate positions) and p = 0.11 (k-means on position). With the code's spike selection the spatial splits give p = 0.0042 and 0.0014, and with units significant over the whole recording p = 0.035 to 0.051 (Methods) and 0.0008 to 0.013 (code). With the 59 units significant in the seizure windows under the RMS of the whole recording, the spatial splits give p = 0.023 and 0.020, and reading b again p below 1e-4. Under the Methods' spike selection only reading b reaches p <= 0.01.
All-electrode windows¶
Stage windows (claims file: baseline before the first burst, initiation the first burst, seizure the subsequent bursts; exact windows not given). Bursts start within the first second of both KA recordings (spike notebook), so no window lies before the first burst; the baseline is taken as a stretch free of detected bursts under every burst reading, just before the initiation burst. S1 initiation is the first burst that the code splits into sub-bursts, 14.4 to 14.91 s, and the seizure plot of Extended Data Fig. 4e starts at 15.10 s; S2 initiation is the code's sub-bursts at 35.208 to 35.302 s (figures/supplement/seizure_2/seizure2_burst_peaks.ipynb, printed above), and Extended Data Fig. 5b marks seizure after it. Used here: S1 baseline 12.0 to 13.0 s, initiation 14.4 to 14.91 s, seizure 15.0 to 28.0 s (to the end of the code's first seizure window); S2 baseline 34.45 to 35.2 s (0.75 s: detected bursts at 34.35 to 34.42 s and 35.24 s bound it), initiation 35.208 to 35.302 s, seizure 35.3 to 38.5 s. The code's S2 initiation window (94 ms) is shorter than one theta cycle (125 to 250 ms), so a lag of up to 40 ms has little signal to rest on there; windows of one theta cycle at 4 Hz and longer starting at 35.208 s (250 ms, 500 ms, 1 s) and 35.0 to 35.5 s are run as variants. For S3 and S4 (Extended Data Fig. 6: segments "that contained higher than average burst-like activity"; the length is not given) the 8 s window with the most spikes of the sorting (8 s is a choice). S5 and S6 have no raw recording here.
def busiest(r, w=8.0):
allsp = np.concatenate(SORT[r]['trains']) / 1000
c = np.histogram(allsp, bins=np.arange(0, SORT[r]['length_ms'] / 1000, 1.0))[0]
k = np.convolve(c, np.ones(int(w)), 'valid').argmax()
return float(k), float(k + w), c[k:k + int(w)].sum() / w / SORT[r]['n'], c.sum() / len(c) / SORT[r]['n']
WIN = {1: dict(read=(0, 30), baseline=(12.0, 13.0), initiation=(14.4, 14.91), seizure=(15.0, 28.0)),
3: dict(read=(33, 40), baseline=(34.45, 35.2), initiation=(35.208, 35.302), seizure=(35.3, 38.5),
init_250ms=(35.208, 35.458), init_500ms=(35.208, 35.708), init_1s=(35.208, 36.208), init_35_to_35p5=(35.0, 35.5))}
# bursts of S1 and S2 under the four readings of fig1g (as in the spike notebook)
READINGS = [(sg, rd) for rd in ('a', 'b') for sg in (10, 20)]
def bursts(r, sg, rd):
s = SORT[r]; rate = H.population_rate(s['trains'], s['length_ms'], sg)
if rd == 'a':
b = {1: 2, 3: 4}[r]
thr = 2 * H.population_rate(SORT[b]['trains'], SORT[b]['length_ms'], sg).mean()
else:
thr = rate.mean() + 3 * rate.std()
return H.detect_bursts(rate, thr)
BT = {(r, sg, rd): bursts(r, sg, rd) for r in (1, 3) for sg, rd in READINGS}
for r in (1, 3):
lo, hi = WIN[r]['baseline'][0] - 2, WIN[r]['initiation'][1]
for sg, rd in READINGS:
b = BT[(r, sg, rd)][0]
inb = b[(b >= WIN[r]['baseline'][0]) & (b < WIN[r]['baseline'][1])]
print(H.RECORDINGS[r]['slice'], f'({rd}) sigma {sg}: bursts {lo:.2f} to {hi:.2f} s: {np.round(b[(b >= lo) & (b < hi)], 3).tolist()}; in the baseline window: {len(inb)}')
for r in (5, 6):
a, b, act, mean_ = busiest(r); off = LINK[r][1]
WIN[r] = dict(read=(a + off - 1, b + off + 1), active=(a + off, b + off))
print(H.RECORDINGS[r]['slice'], f'busiest 8 s: sorting time {a:.0f}-{b:.0f} s (file {a+off:.0f}-{b+off:.0f} s), {act:.2f} spikes/s per unit against {mean_:.2f} over the recording')
t = time.time()
WL = {}
for r, w in WIN.items():
sub = LINK[r][0]; e = ELEC[sub]
WL[r] = H.lfp_1khz(A[sub]['asset_id'], np.arange(len(e)), w['read'][0], w['read'][1], len(e), POOL)
print(r, sub, WL[r].shape, f'range {WL[r].min():.0f} to {WL[r].max():.0f} uV; {time.time()-t:.0f} s')
S1 (a) sigma 10: bursts 10.00 to 14.91 s: [13.15, 13.762, 14.817, 14.879]; in the baseline window: 0 S1 (a) sigma 20: bursts 10.00 to 14.91 s: [13.757, 14.857]; in the baseline window: 0 S1 (b) sigma 10: bursts 10.00 to 14.91 s: []; in the baseline window: 0 S1 (b) sigma 20: bursts 10.00 to 14.91 s: []; in the baseline window: 0 S2 (a) sigma 10: bursts 32.45 to 35.30 s: [32.559, 32.633, 33.456, 33.546, 34.348, 34.424, 35.243]; in the baseline window: 0 S2 (a) sigma 20: bursts 32.45 to 35.30 s: [32.584, 33.532, 34.362, 35.243]; in the baseline window: 0 S2 (b) sigma 10: bursts 32.45 to 35.30 s: [32.559, 32.633, 33.456, 33.546, 34.348, 34.424, 35.243]; in the baseline window: 0 S2 (b) sigma 20: bursts 32.45 to 35.30 s: [32.584, 33.532, 34.362, 35.243]; in the baseline window: 0 S3 busiest 8 s: sorting time 399-407 s (file 399-407 s), 1.71 spikes/s per unit against 1.36 over the recording S4 busiest 8 s: sorting time 120-128 s (file 150-158 s), 10.23 spikes/s per unit against 5.39 over the recording
1 sub-10F-6 (30000, 1009) range 578 to 931 uV; 13 s
3 sub-11G-2 (7000, 894) range 517 to 999 uV; 21 s
5 sub-1A-0 (10000, 995) range 1822 to 4836 uV; 30 s
6 sub-9E-2 (10000, 936) range 629 to 1001 uV; 38 s
ext4-electrode-lag-clusters¶
In the two epileptiform slices, k-means clustering of electrodes by their pairwise theta lags gives spatial clusters that replicate the theta propagation of each stage, while the slices without epileptiform activity (S3 to S6) show no spatial pattern.
Lag matrix as the Methods (hippo.lag_matrix), k-means with 2 clusters on its rows (random state
from the claim's seed), spatial coherence against 1000 label shuffles (hippo.spatial_coherence).
Theta filter order 5 (code) and 4 (Methods' theta plots). The S2 initiation window of the code is
94 ms, shorter than one theta cycle; the longer windows above are run as variants, with the fraction
of lags at the +-40 ms edge (frac_at_edge).
seed = zlib.crc32(b"elliott-2026/ext4-electrode-lag-clusters")
LAGS, LABS = {}, {}
rows = []
for r, w in WIN.items():
e = ELEC[LINK[r][0]]; xy = np.c_[e.x, e.y]; t0 = w['read'][0]
for order in (5, 4):
th = H.theta(WL[r], order=order)
for st, (a, b) in w.items():
if st == 'read':
continue
seg = th[int(round((a - t0) * 1000)):int(round((b - t0) * 1000))]
L, Cc = H.lag_matrix(seg)
lab = KMeans(2, n_init=10, random_state=seed).fit_predict(L)
obs, null = H.spatial_coherence(xy, lab, rng=np.random.default_rng(seed))
LAGS[(r, order, st)] = L; LABS[(r, order, st)] = lab
rows.append(dict(slice=H.RECORDINGS[r]['slice'], order=order, stage=st, window_ms=len(seg), sizes=np.bincount(lab).tolist(),
coherence=obs, null_mean=null.mean(), null_max=null.max(), beyond_all=obs > null.max(),
median_abs_lag=float(np.median(np.abs(L))), frac_at_edge=float(np.mean(np.abs(L) == 40))))
LC = pd.DataFrame(rows)
print(LC.round(3).to_string(index=False))
slice order stage window_ms sizes coherence null_mean null_max beyond_all median_abs_lag frac_at_edge S1 5 baseline 1000 [546, 463] 0.369 0.373 0.444 False 24.0 0.261 S1 5 initiation 510 [664, 345] 0.689 0.510 0.566 True 14.0 0.163 S1 5 seizure 13000 [370, 639] 0.902 0.470 0.521 True 22.0 0.183 S1 4 baseline 1000 [542, 467] 0.367 0.372 0.446 False 24.0 0.259 S1 4 initiation 510 [664, 345] 0.681 0.510 0.570 True 14.0 0.159 S1 4 seizure 13000 [365, 644] 0.900 0.478 0.531 True 22.0 0.182 S2 5 baseline 750 [542, 352] 0.672 0.432 0.502 True 14.0 0.184 S2 5 initiation 94 [124, 770] 0.838 0.848 0.861 False 0.0 0.002 S2 5 seizure 3200 [381, 513] 0.860 0.396 0.479 True 12.0 0.123 S2 5 init_250ms 250 [254, 640] 0.925 0.609 0.650 True 3.0 0.216 S2 5 init_500ms 500 [496, 398] 0.875 0.382 0.478 True 11.0 0.106 S2 5 init_1s 1000 [401, 493] 0.884 0.379 0.466 True 12.0 0.114 S2 5 init_35_to_35p5 500 [192, 702] 0.906 0.733 0.763 True 6.0 0.120 S2 4 baseline 750 [343, 551] 0.682 0.445 0.515 True 14.0 0.171 S2 4 initiation 94 [786, 108] 0.853 0.871 0.879 False 0.0 0.002 S2 4 seizure 3200 [512, 382] 0.861 0.395 0.484 True 12.0 0.122 S2 4 init_250ms 250 [257, 637] 0.922 0.603 0.644 True 3.0 0.219 S2 4 init_500ms 500 [397, 497] 0.875 0.382 0.479 True 11.0 0.108 S2 4 init_1s 1000 [401, 493] 0.881 0.379 0.464 True 12.0 0.115 S2 4 init_35_to_35p5 500 [192, 702] 0.914 0.733 0.763 True 6.0 0.120 S3 5 active 8000 [393, 602] 0.444 0.431 0.488 False 25.0 0.281 S3 4 active 8000 [376, 619] 0.466 0.454 0.511 False 25.0 0.278 S4 5 active 8000 [561, 375] 0.439 0.424 0.482 False 25.0 0.276 S4 4 active 8000 [550, 386] 0.392 0.411 0.478 False 25.0 0.274
# seed sensitivity of the k-means labels and the shuffle null (claim seed plus 1000 to 4000)
rows = []
for r, st in [(1, 'initiation'), (1, 'seizure'), (3, 'initiation'), (3, 'init_250ms'), (3, 'init_500ms'), (3, 'init_1s'), (3, 'init_35_to_35p5'), (3, 'seizure'), (5, 'active'), (6, 'active')]:
e = ELEC[LINK[r][0]]; xy = np.c_[e.x, e.y]; L = LAGS[(r, 5, st)]
for k in range(5):
sd = seed + 1000 * k
lab = KMeans(2, n_init=10, random_state=sd).fit_predict(L)
obs, null = H.spatial_coherence(xy, lab, rng=np.random.default_rng(sd))
rows.append(dict(slice=H.RECORDINGS[r]['slice'], stage=st, seed_offset=1000 * k, coherence=obs, null_max=null.max(), beyond_all=obs > null.max()))
print(pd.DataFrame(rows).round(3).to_string(index=False))
slice stage seed_offset coherence null_max beyond_all S1 initiation 0 0.689 0.566 True S1 initiation 1000 0.689 0.555 True S1 initiation 2000 0.689 0.578 True S1 initiation 3000 0.691 0.583 True S1 initiation 4000 0.689 0.557 True S1 seizure 0 0.902 0.521 True S1 seizure 1000 0.902 0.521 True S1 seizure 2000 0.902 0.524 True S1 seizure 3000 0.902 0.524 True S1 seizure 4000 0.902 0.535 True S2 initiation 0 0.838 0.861 False S2 initiation 1000 0.838 0.860 False S2 initiation 2000 0.838 0.859 False S2 initiation 3000 0.838 0.861 False S2 initiation 4000 0.838 0.860 False S2 init_250ms 0 0.925 0.650 True S2 init_250ms 1000 0.925 0.648 True S2 init_250ms 2000 0.925 0.650 True S2 init_250ms 3000 0.925 0.650 True S2 init_250ms 4000 0.925 0.648 True S2 init_500ms 0 0.875 0.478 True S2 init_500ms 1000 0.875 0.477 True S2 init_500ms 2000 0.875 0.470 True S2 init_500ms 3000 0.876 0.451 True S2 init_500ms 4000 0.875 0.472 True S2 init_1s 0 0.884 0.466 True S2 init_1s 1000 0.884 0.477 True S2 init_1s 2000 0.884 0.484 True S2 init_1s 3000 0.884 0.460 True S2 init_1s 4000 0.884 0.453 True S2 init_35_to_35p5 0 0.906 0.763 True S2 init_35_to_35p5 1000 0.906 0.760 True S2 init_35_to_35p5 2000 0.906 0.757 True S2 init_35_to_35p5 3000 0.906 0.756 True S2 init_35_to_35p5 4000 0.906 0.752 True S2 seizure 0 0.860 0.479 True S2 seizure 1000 0.860 0.474 True S2 seizure 2000 0.860 0.492 True S2 seizure 3000 0.860 0.471 True S2 seizure 4000 0.860 0.474 True S3 active 0 0.444 0.488 False S3 active 1000 0.422 0.443 False S3 active 2000 0.380 0.453 False S3 active 3000 0.392 0.452 False S3 active 4000 0.390 0.461 False S4 active 0 0.439 0.482 False S4 active 1000 0.373 0.450 False S4 active 2000 0.331 0.460 False S4 active 3000 0.369 0.454 False S4 active 4000 0.448 0.479 False
fig, axs = plt.subplots(2, 4, figsize=(14, 6))
for a, (r, st) in zip(axs.flat, [(1, 'baseline'), (1, 'initiation'), (1, 'seizure'), (3, 'baseline'), (3, 'initiation'), (3, 'seizure'), (5, 'active'), (6, 'active')]):
e = ELEC[LINK[r][0]]
a.scatter(e.x, e.y, c=LABS[(r, 5, st)], s=3, cmap='PiYG'); a.invert_yaxis(); a.set_aspect('equal')
a.set_title(f"{H.RECORDINGS[r]['slice']} {st}", fontsize=9)
plt.tight_layout(); plt.show()
Result: partially reproduced. Electrode clusters are spatially coherent beyond all 1000 shuffles in the S1 initiation (0.69 against a shuffle maximum of 0.57) and seizure stages (0.90 against 0.52) and the S2 seizure stage (0.86 against 0.48), under both filter orders and all five seeds. The S2 initiation window of the code (94 ms, shorter than one theta cycle; median lag 0 ms, 0.2% of lags at the window edge) gives 0.84 against 0.86 and fails; every window of one theta cycle or longer passes under both filter orders and all five seeds (250 ms from 35.208 s: 0.92 to 0.93 against shuffle maxima of 0.64 to 0.65; 500 ms: 0.88 against 0.45 to 0.48; 1 s: 0.88 against 0.45 to 0.48; 35.0 to 35.5 s: 0.91 against 0.75 to 0.76), with 11 to 22% of lags at the edge. S3 and S4 are less coherent (0.44 and 0.44, below their shuffle maxima of 0.49 and 0.48) than every coherent stage of S1 and S2. S5 and S6 could not be tested, so the second part of the criterion is shown for 2 of the 4 slices it names. The S1 baseline is not coherent (0.37 against 0.44), and the S2 baseline is (0.67 against 0.50), where the paper reports no pattern at baseline.
fig1j-theta-propagation-stages¶
In S1 theta-band activity shows no pattern at baseline, a standing wave oscillating across the length of the granule cell layer at initiation, and at the seizure stage a rolling wave orthogonal to the initiation direction, moving from the hilar to the outer aspect; S2 shows the same stages.
Per stage, a plane fitted to each electrode's arrival time (minus its mean lag) over position
(hippo.plane_direction). Layer long axis and the normal toward the convex (outer) side from the
degree-2 fit of unit positions (hippo.layer_axes; that the hilus lies on the concave side is an
assumption). Initiation direction is compared with the long axis as an axis (a standing wave has no
sign); seizure direction with the outward normal as a direction. seiz_vs_inward gives the angle if the hilus were on the convex side
instead. For S2 the initiation is also run with the 250 ms window, as the code's 94 ms window is
shorter than one theta cycle.
rows = []
for r in (1, 3):
ax_, nrm = H.layer_axes(SORT[r]['pos'])
ax_deg = np.degrees(np.arctan2(ax_[1], ax_[0])); n_deg = np.degrees(np.arctan2(nrm[1], nrm[0]))
e = ELEC[LINK[r][0]]; xy = np.c_[e.x, e.y]
for order in (5, 4):
for ini_stage in (['initiation'] if r == 1 else ['initiation', 'init_250ms']):
d = {st: H.plane_direction(xy, LAGS[(r, order, st)]) for st in ('baseline', ini_stage, 'seizure')}
ini, sz = d[ini_stage][0], d['seizure'][0]
row = dict(slice=H.RECORDINGS[r]['slice'], order=order, init_window=ini_stage, layer_axis_deg=ax_deg, outward_normal_deg=n_deg,
init_dir=ini, init_R2=d[ini_stage][1], seiz_dir=sz, seiz_R2=d['seizure'][1], base_R2=d['baseline'][1],
init_vs_axis=H.angle_between(ini, ax_deg, axial=True), init_vs_seiz=H.angle_between(ini, sz, axial=True),
seiz_vs_outward=H.angle_between(sz, n_deg), seiz_vs_inward=H.angle_between(sz, n_deg + 180))
row['holds'] = (row['init_vs_axis'] <= 45) and (60 <= row['init_vs_seiz'] <= 120) and (row['seiz_vs_outward'] <= 45) and (row['base_R2'] < min(row['init_R2'], row['seiz_R2']))
rows.append(row)
print(pd.DataFrame(rows).round(3).to_string(index=False))
slice order init_window layer_axis_deg outward_normal_deg init_dir init_R2 seiz_dir seiz_R2 base_R2 init_vs_axis init_vs_seiz seiz_vs_outward seiz_vs_inward holds S1 5 initiation 2.504 92.504 -98.157 0.020 -94.010 0.046 0.000 79.339 4.147 173.486 6.514 False S1 4 initiation 2.504 92.504 -101.824 0.022 -94.861 0.045 0.001 75.672 6.963 172.635 7.365 False S2 5 initiation 26.538 -63.462 103.570 0.018 87.948 0.311 0.068 77.032 15.622 151.410 28.590 False S2 5 init_250ms 26.538 -63.462 -126.267 0.426 87.948 0.311 0.068 27.195 34.216 151.410 28.590 False S2 4 initiation 26.538 -63.462 104.048 0.019 87.966 0.310 0.056 77.510 16.082 151.428 28.572 False S2 4 init_250ms 26.538 -63.462 -126.330 0.426 87.966 0.310 0.056 27.132 34.296 151.428 28.572 False
Result: not reproduced. Plane fits explain little of the arrival times (R2 0.02 at initiation and 0.05 in the seizure stage of S1; 0.02 and 0.31 in S2). The initiation direction is 75 to 79 degrees from the layer's long axis in both slices, the initiation and seizure directions differ by only 4 to 16 degrees, and the seizure direction points 151 to 173 degrees from the outward normal (7 to 29 degrees from the inward normal, if the hilus lay on the convex side). In S1 the baseline R2 (0.000 to 0.001) is the lowest of the three stages; in S2 it (0.06 to 0.07) is above that of the code's initiation window. With the 250 ms S2 initiation window the initiation direction lies 27 degrees from the long axis (R2 0.43), but it differs from the seizure direction by 34 degrees, outside 60 to 120. The conditions fail in S1 under every variant.
ext4b-theta-delay¶
During seizure-like activity theta waves in S1 reach three electrodes along the propagation direction in turn, with a 40 ms delay from the first to the second and from the second to the third.
Reading 1 of the criterion: the median lag over electrode pairs whose displacement lies within 15 degrees of the seizure-stage direction (from fig1j) at the spacing of the figure's electrodes. The spacing is read from Extended Data Fig. 4a against its 500 um scale bar as roughly 200 to 300 um between successive electrodes (an approximate reading of the figure). The second reading (the three electrodes of the figure's map) cannot be run: the map is drawn over histology without electrode coordinates.
e = ELEC[LINK[1][0]]; xy = np.c_[e.x, e.y]
for order in (5, 4):
L = LAGS[(1, order, 'seizure')]
sdir = H.plane_direction(xy, L)[0]
u = np.array([np.cos(np.radians(sdir)), np.sin(np.radians(sdir))])
dvec = xy[None, :, :] - xy[:, None, :]
dist = np.hypot(dvec[..., 0], dvec[..., 1])
cosang = (dvec @ u) / np.maximum(dist, 1e-9)
for lo, hi in [(200, 300), (150, 250), (250, 350)]:
m = (dist >= lo) & (dist < hi) & (cosang > np.cos(np.radians(15)))
lag = L[m]
print(f'order {order}, direction {sdir:.0f} deg, spacing {lo}-{hi} um: {m.sum()} pairs, median lag {np.median(lag):.1f} ms, '
f'IQR {np.percentile(lag, 25):.0f} to {np.percentile(lag, 75):.0f}, fraction positive {np.mean(lag > 0):.2f}, at +-40 ms {np.mean(np.abs(lag) == 40):.2f}')
order 5, direction -94 deg, spacing 200-300 um: 7039 pairs, median lag -23.0 ms, IQR -38 to -9, fraction positive 0.13, at +-40 ms 0.27 order 5, direction -94 deg, spacing 150-250 um: 5820 pairs, median lag -19.0 ms, IQR -34 to -7, fraction positive 0.11, at +-40 ms 0.19 order 5, direction -94 deg, spacing 250-350 um: 6173 pairs, median lag -23.0 ms, IQR -40 to -6, fraction positive 0.21, at +-40 ms 0.34 order 4, direction -95 deg, spacing 200-300 um: 7076 pairs, median lag -23.0 ms, IQR -38 to -9, fraction positive 0.13, at +-40 ms 0.27 order 4, direction -95 deg, spacing 150-250 um: 5792 pairs, median lag -19.0 ms, IQR -34 to -7, fraction positive 0.11, at +-40 ms 0.19 order 4, direction -95 deg, spacing 250-350 um: 6231 pairs, median lag -23.0 ms, IQR -40 to -7, fraction positive 0.20, at +-40 ms 0.34
Result: not reproduced. Along the fitted seizure direction at 200 to 300 um, the median lag is -23 ms (interquartile range -38 to -9 ms; 13% positive), and -19 to -23 ms at the other spacings, with 19 to 34% of lags at the +-40 ms edge. The negative sign means electrodes further along the fitted direction lead, consistent with the weak plane fit of fig1j. The reading with the figure's three electrodes could not be run.
methods-rolling-wave-counts (blocked, methods_underspecified)¶
The rolling wave appeared in every investigated burst of S1 and in about 75% of those of S2, 2 to 4 times per burst, giving about 200 stereotypic propagations in S1's seizure stage and 35 in S2's.
The paper counted rolling waves by watching videos. The criterion allows one detector as an
assumption: a theta cycle whose lag-plane direction matches the seizure direction (from
fig1j-theta-propagation-stages) within 45 degrees and explains most of the lag variance. It is run
here on the S1 seizure window (15 to 28 s): theta cycles from trough to trough of the theta averaged
over all electrodes, one lag matrix and plane fit per cycle (hippo.lag_matrix,
hippo.plane_direction), "most of the variance" read as R2 above 0.5. The claim stays blocked: the
reference direction itself rests on a plane fit with R2 0.05 (fig1j), so the detector has no
defensible basis (see the attempt record).
t = time.time()
e = ELEC[LINK[1][0]]; xy = np.c_[e.x, e.y]; t0 = WIN[1]['read'][0]
th = H.theta(WL[1], order=5)
sdir = H.plane_direction(xy, LAGS[(1, 5, 'seizure')])[0]
tr = signal.find_peaks(-th.mean(1))[0]
tr = tr[(tr >= (15.0 - t0) * 1000) & (tr < (28.0 - t0) * 1000)]
rows = []
for a, b in zip(tr[:-1], tr[1:]):
d, r2, _ = H.plane_direction(xy, H.lag_matrix(th[a:b])[0])
rows.append(dict(start_s=t0 + a / 1000, ms=b - a, direction=d, R2=r2, off_seizure_dir=H.angle_between(d, sdir)))
RW = pd.DataFrame(rows)
RW['is_rolling'] = (RW.R2 > 0.5) & (RW.off_seizure_dir <= 45)
print(f'seizure direction {sdir:.0f} deg; {len(RW)} theta cycles of {RW.ms.min()} to {RW.ms.max()} ms; R2 median {RW.R2.median():.4f}, '
f'max {RW.R2.max():.3f}; cycles with R2 > 0.5: {int((RW.R2 > 0.5).sum())}; within 45 deg of the seizure direction: {int((RW.off_seizure_dir <= 45).sum())}; '
f'both (rolling waves): {int(RW.is_rolling.sum())}')
for sg, rd in READINGS:
b = BT[(1, sg, rd)][0]; b = b[(b >= 15.0) & (b < 28.0)]
with_wave = sum(RW[(RW.start_s >= x - 0.25) & (RW.start_s < x + 0.25)].is_rolling.any() for x in b)
print(f'({rd}) sigma {sg}: {len(b)} bursts in 15 to 28 s, {with_wave} with a rolling wave within 250 ms')
print(f'{time.time() - t:.0f} s')
seizure direction -94 deg; 63 theta cycles of 106 to 285 ms; R2 median 0.0023, max 0.381; cycles with R2 > 0.5: 0; within 45 deg of the seizure direction: 37; both (rolling waves): 0 (a) sigma 10: 22 bursts in 15 to 28 s, 0 with a rolling wave within 250 ms (a) sigma 20: 12 bursts in 15 to 28 s, 0 with a rolling wave within 250 ms (b) sigma 10: 10 bursts in 15 to 28 s, 0 with a rolling wave within 250 ms (b) sigma 20: 7 bursts in 15 to 28 s, 0 with a rolling wave within 250 ms 99 s
Result: blocked (methods_underspecified). The criterion's detector finds no rolling wave in S1's first seizure window: of 63 theta cycles (106 to 285 ms), none has a plane fit with R2 above 0.5 (median 0.0023, largest 0.38), though 37 point within 45 degrees of the fitted seizure direction; 0 of the 7 to 22 bursts in 15 to 28 s have a rolling wave. Adopting the detector would give 0 for every expected value; it is not adopted, as its reference direction rests on a plane fit with R2 0.05.
fig2a-subbursts-track-theta¶
At the initiation stage of S1 the first burst splits into three sub-bursts whose peaks and troughs coincide with the theta oscillation, and the change in single-unit firing from sub-burst to sub-burst alternates between the same two spatial modes as theta; S2 shows a similar pattern.
Sub-bursts as set in the code (S1 14.4, 14.57, 14.75, 14.91 s; S2 35.208, 35.234, 35.265, 35.302 s; sources printed above). Per-unit rate in each sub-burst, the difference between consecutive sub-bursts (earlier minus later, as the code), heatmaps on a 30 by 30 grid with Gaussian smoothing (Methods; display only). Theta modes: the two k-means electrode clusters of the initiation stage (order 5). Each unit takes the cluster of its electrode. Measure (claims file): the mean firing change over cluster A minus over cluster B for each difference map, and the theta of cluster A minus cluster B averaged within each sub-burst. For S2 the clusters of the code's 94 ms initiation window fail the coherence test (ext4), so the clusters of the 250 ms window are run as a variant.
rows = []
fig, axs = plt.subplots(3, 2, figsize=(10, 10))
for i, (r, stage) in enumerate([(1, 'initiation'), (3, 'initiation'), (3, 'init_250ms')]):
sub, off = LINK[r]; e = ELEC[sub]; t0 = WIN[r]['read'][0]
lab = LABS[(r, 5, stage)]
ch = UCH[r]; ulab = lab[ch]
edges = SUBB[r]
rates = np.array([[np.sum((tr >= a * 1000) & (tr < b * 1000)) / (b - a) for a, b in zip(edges[:-1], edges[1:])] for tr in SORT[r]['trains']])
d1, d2 = rates[:, 0] - rates[:, 1], rates[:, 1] - rates[:, 2]
th = H.theta(WL[r], order=5)
thA = th[:, lab == 0].mean(1); thB = th[:, lab == 1].mean(1)
tdiff = [float(np.mean((thA - thB)[int((a - t0) * 1000):int((b - t0) * 1000)])) for a, b in zip(edges[:-1], edges[1:])]
D1 = d1[ulab == 0].mean() - d1[ulab == 1].mean(); D2 = d2[ulab == 0].mean() - d2[ulab == 1].mean()
flips = np.sign(D1) != np.sign(D2)
th_alt = (np.sign(tdiff[0]) != np.sign(tdiff[1])) and (np.sign(tdiff[1]) != np.sign(tdiff[2]))
rows.append(dict(slice=H.RECORDINGS[r]['slice'], clusters_from=stage, units_A=int((ulab == 0).sum()), units_B=int((ulab == 1).sum()),
active_units=[int((rates[:, k] > 0).sum()) for k in range(3)], D1_A_minus_B=D1, D2_A_minus_B=D2, firing_flips=flips,
theta_A_minus_B_per_subburst=np.round(tdiff, 2).tolist(), theta_alternates=th_alt, holds=bool(flips and th_alt)))
for j, dd in enumerate((d1, d2)):
grid = np.zeros((30, 30)); cnt = np.zeros((30, 30))
gx = np.clip(((SORT[r]['pos'][:, 0] - e.x.min()) / (e.x.max() - e.x.min() + 1e-9) * 30).astype(int), 0, 29)
gy = np.clip(((SORT[r]['pos'][:, 1] - e.y.min()) / (e.y.max() - e.y.min() + 1e-9) * 30).astype(int), 0, 29)
np.add.at(grid, (gy, gx), dd); np.add.at(cnt, (gy, gx), 1)
hm = gaussian_filter(np.where(cnt > 0, grid / np.maximum(cnt, 1), 0), 1)
im = axs[i, j].imshow(hm, cmap='PiYG'); axs[i, j].set_title(f"{H.RECORDINGS[r]['slice']} ({stage} clusters) change {j+1} to {j+2} (range {hm.min():.0f} to {hm.max():.0f} Hz)", fontsize=8)
plt.tight_layout(); plt.show()
print(pd.DataFrame(rows).round(2).to_string(index=False))
slice clusters_from units_A units_B active_units D1_A_minus_B D2_A_minus_B firing_flips theta_A_minus_B_per_subburst theta_alternates holds S1 initiation 137 75 [122, 137, 140] 0.22 0.91 False [0.24, -0.26, -0.65] False False S2 initiation 29 151 [95, 98, 113] 3.90 -7.06 True [4.68, 2.45, -0.76] False False S2 init_250ms 90 90 [95, 98, 113] -8.92 5.51 True [-7.2, -4.42, 1.14] False False
Result: not reproduced. In S1 the cluster difference in firing change is 0.22 then 0.91 Hz (no flip) and the theta difference between clusters is 0.24, -0.26 and -0.65 uV over the three sub-bursts (it changes sign once). In S2 the firing difference flips (3.90 then -7.06 Hz) but the theta difference does not alternate (4.68, 2.45, -0.76 uV); with the clusters of the 250 ms window the firing difference flips (-8.92 then 5.51 Hz) and the theta difference again does not alternate (-7.20, -4.42, 1.14 uV). Neither slice meets the criterion. The S2 sub-bursts are 26 to 37 ms long, a fraction of one theta cycle.
ext3-onset-spectral-signature¶
At the onset of seizure-like activity in S1 the LFP shows a large upwelling of delta power and an increase in theta amplitude, and this holds at different electrodes.
0.1 to 100 Hz (order-2 high-pass at 0.1 Hz and order-5 low-pass at 100 Hz, zero phase) of the 1 kHz LFP; complex Morlet wavelet cmor1-1 (PyWavelets), power as the squared magnitude, Gaussian smoothing sigma 2. Onsets: the criterion's, the first burst of the first epoch, under each of the four burst readings of fig1g; as variants, the first burst of the first epoch that has the criterion's 5 s of recording before it, under each reading, and the initiation burst that the paper's figures and code use (14.4 s). Baseline: the 5 s before onset, or what the recording holds of it. Electrodes: nearest the three units with the highest rate, and three along the layer (nearest the fitted curve at 25, 50 and 75% of its x range).
import pywt
s = SORT[1]; e = ELEC[LINK[1][0]]
onsets = {}
for sg, rd in READINGS:
ep = BT[(1, sg, rd)][1]
onsets[f'criterion ({rd}, sigma {sg})'] = float(ep[0][0])
for sg, rd in READINGS:
ep = BT[(1, sg, rd)][1]
onsets[f'first epoch with 5 s before ({rd}, sigma {sg})'] = float(next(x[0] for x in ep if x[0] >= 5))
onsets['paper initiation (code 14.4 s)'] = 14.4
fr = np.array([len(t) for t in s['trains']])
top = np.argsort(fr)[::-1][:3]
el_rate = [int(np.argmin((e.x - x) ** 2 + (e.y - y) ** 2)) for x, y in s['pos'][top]]
c = np.polyfit(s['pos'][:, 0], s['pos'][:, 1], 2)
xs = s['pos'][:, 0].min() + np.array([0.25, 0.5, 0.75]) * np.ptp(s['pos'][:, 0])
el_layer = [int(np.argmin((e.x - x) ** 2 + (e.y - np.polyval(c, x)) ** 2)) for x in xs]
sos_h = signal.butter(2, 0.1, 'high', fs=1000, output='sos'); sos_l = signal.butter(5, 100, 'low', fs=1000, output='sos')
freqs = np.arange(0.5, 50.5, 0.5)
scales = pywt.frequency2scale('cmor1-1', freqs / 1000)
# cmor1-1 has a Gaussian envelope exp(-t^2 / B) with B = 1 at scale s = 1 / f: at 0.5 Hz it falls to 1/e at 2 s
print('e-folding half-width of the wavelet: 0.5 Hz', 1 / 0.5, 's; 4 Hz', 1 / 4, 's')
PRE = {}
for ch in el_rate + el_layer:
x = WL[1][:, ch].astype(float)
x = signal.sosfiltfilt(sos_l, signal.sosfiltfilt(sos_h, x - x.mean()))
coef, _ = pywt.cwt(x, scales, 'cmor1-1', sampling_period=1 / 1000)
pw = gaussian_filter(np.abs(coef) ** 2, 2)
PRE[ch] = (pw[(freqs >= 0.5) & (freqs <= 4)].mean(0), np.abs(signal.hilbert(H.theta(x))), np.abs(signal.hilbert(x)))
rows = []
for oname, on in onsets.items():
for ename, els in [('top-rate units', el_rate), ('along layer', el_layer)]:
for ch in els:
delta, th_env, bb_env = PRE[ch]
b0, b1, p1 = int(max(on - 5, 0) * 1000), int(on * 1000), int((on + 2) * 1000)
r_delta = delta[b1:p1].mean() / delta[b0:b1].mean()
r_th = th_env[b1:p1].mean() / th_env[b0:b1].mean()
r_bb = bb_env[b1:p1].mean() / bb_env[b0:b1].mean()
rows.append(dict(onset=oname, onset_s=on, baseline_s=(b1 - b0) / 1000, electrodes=ename, channel=ch, x=e.x[ch], y=e.y[ch],
delta_ratio=r_delta, theta_amp_ratio=r_th, broadband_amp_ratio=r_bb,
holds_theta=(r_delta > 1) and (r_th > 2), holds_broadband=(r_delta > 1) and (r_bb > 2)))
E3 = pd.DataFrame(rows)
pd.set_option('display.width', 250)
print(E3.round(3).to_string(index=False))
print(E3.groupby(['onset', 'electrodes'], sort=False).agg(onset_s=('onset_s', 'first'), baseline_s=('baseline_s', 'first'),
holds_theta=('holds_theta', 'sum'), holds_broadband=('holds_broadband', 'sum')).to_string())
e-folding half-width of the wavelet: 0.5 Hz 2.0 s; 4 Hz 0.25 s
onset onset_s baseline_s electrodes channel x y delta_ratio theta_amp_ratio broadband_amp_ratio holds_theta holds_broadband
criterion (a, sigma 10) 0.730 0.730 top-rate units 480 472.5 1137.5 1.541 1.139 1.160 False False
criterion (a, sigma 10) 0.730 0.730 top-rate units 722 577.5 1137.5 0.698 1.909 0.896 False False
criterion (a, sigma 10) 0.730 0.730 top-rate units 867 1155.0 1347.5 1.285 1.721 1.289 False False
criterion (a, sigma 10) 0.730 0.730 along layer 434 752.5 1137.5 0.891 1.005 1.311 False False
criterion (a, sigma 10) 0.730 0.730 along layer 75 1330.0 1277.5 0.975 1.866 1.165 False False
criterion (a, sigma 10) 0.730 0.730 along layer 59 1715.0 1172.5 1.215 1.783 1.086 False False
criterion (a, sigma 20) 0.895 0.895 top-rate units 480 472.5 1137.5 1.421 1.118 1.061 False False
criterion (a, sigma 20) 0.895 0.895 top-rate units 722 577.5 1137.5 0.687 1.544 0.825 False False
criterion (a, sigma 20) 0.895 0.895 top-rate units 867 1155.0 1347.5 0.913 1.364 0.979 False False
criterion (a, sigma 20) 0.895 0.895 along layer 434 752.5 1137.5 0.602 0.893 0.795 False False
criterion (a, sigma 20) 0.895 0.895 along layer 75 1330.0 1277.5 0.773 1.128 0.765 False False
criterion (a, sigma 20) 0.895 0.895 along layer 59 1715.0 1172.5 1.054 1.301 0.832 False False
criterion (b, sigma 10) 0.893 0.893 top-rate units 480 472.5 1137.5 1.423 1.118 1.063 False False
criterion (b, sigma 10) 0.893 0.893 top-rate units 722 577.5 1137.5 0.688 1.548 0.826 False False
criterion (b, sigma 10) 0.893 0.893 top-rate units 867 1155.0 1347.5 0.917 1.369 0.982 False False
criterion (b, sigma 10) 0.893 0.893 along layer 434 752.5 1137.5 0.605 0.892 0.800 False False
criterion (b, sigma 10) 0.893 0.893 along layer 75 1330.0 1277.5 0.775 1.133 0.770 False False
criterion (b, sigma 10) 0.893 0.893 along layer 59 1715.0 1172.5 1.056 1.305 0.832 False False
criterion (b, sigma 20) 0.895 0.895 top-rate units 480 472.5 1137.5 1.421 1.118 1.061 False False
criterion (b, sigma 20) 0.895 0.895 top-rate units 722 577.5 1137.5 0.687 1.544 0.825 False False
criterion (b, sigma 20) 0.895 0.895 top-rate units 867 1155.0 1347.5 0.913 1.364 0.979 False False
criterion (b, sigma 20) 0.895 0.895 along layer 434 752.5 1137.5 0.602 0.893 0.795 False False
criterion (b, sigma 20) 0.895 0.895 along layer 75 1330.0 1277.5 0.773 1.128 0.765 False False
criterion (b, sigma 20) 0.895 0.895 along layer 59 1715.0 1172.5 1.054 1.301 0.832 False False
first epoch with 5 s before (a, sigma 10) 13.150 5.000 top-rate units 480 472.5 1137.5 4.389 1.587 1.674 False False
first epoch with 5 s before (a, sigma 10) 13.150 5.000 top-rate units 722 577.5 1137.5 2.164 1.321 1.111 False False
first epoch with 5 s before (a, sigma 10) 13.150 5.000 top-rate units 867 1155.0 1347.5 2.034 1.473 1.029 False False
first epoch with 5 s before (a, sigma 10) 13.150 5.000 along layer 434 752.5 1137.5 2.615 1.045 1.446 False False
first epoch with 5 s before (a, sigma 10) 13.150 5.000 along layer 75 1330.0 1277.5 1.588 1.169 0.947 False False
first epoch with 5 s before (a, sigma 10) 13.150 5.000 along layer 59 1715.0 1172.5 3.556 1.227 1.143 False False
first epoch with 5 s before (a, sigma 20) 13.757 5.000 top-rate units 480 472.5 1137.5 5.155 1.282 2.361 False True
first epoch with 5 s before (a, sigma 20) 13.757 5.000 top-rate units 722 577.5 1137.5 3.398 1.418 1.776 False False
first epoch with 5 s before (a, sigma 20) 13.757 5.000 top-rate units 867 1155.0 1347.5 3.290 1.564 1.789 False False
first epoch with 5 s before (a, sigma 20) 13.757 5.000 along layer 434 752.5 1137.5 3.853 1.082 1.921 False False
first epoch with 5 s before (a, sigma 20) 13.757 5.000 along layer 75 1330.0 1277.5 1.974 1.260 1.366 False False
first epoch with 5 s before (a, sigma 20) 13.757 5.000 along layer 59 1715.0 1172.5 5.506 1.595 2.009 False True
first epoch with 5 s before (b, sigma 10) 14.982 5.000 top-rate units 480 472.5 1137.5 2.159 0.965 2.321 False True
first epoch with 5 s before (b, sigma 10) 14.982 5.000 top-rate units 722 577.5 1137.5 3.715 1.921 2.461 False True
first epoch with 5 s before (b, sigma 10) 14.982 5.000 top-rate units 867 1155.0 1347.5 3.912 1.296 2.547 False True
first epoch with 5 s before (b, sigma 10) 14.982 5.000 along layer 434 752.5 1137.5 4.237 1.247 2.501 False True
first epoch with 5 s before (b, sigma 10) 14.982 5.000 along layer 75 1330.0 1277.5 2.092 1.478 2.102 False True
first epoch with 5 s before (b, sigma 10) 14.982 5.000 along layer 59 1715.0 1172.5 4.053 1.615 3.031 False True
first epoch with 5 s before (b, sigma 20) 15.048 5.000 top-rate units 480 472.5 1137.5 1.993 0.948 2.203 False True
first epoch with 5 s before (b, sigma 20) 15.048 5.000 top-rate units 722 577.5 1137.5 3.596 1.868 2.367 False True
first epoch with 5 s before (b, sigma 20) 15.048 5.000 top-rate units 867 1155.0 1347.5 3.701 1.273 2.549 False True
first epoch with 5 s before (b, sigma 20) 15.048 5.000 along layer 434 752.5 1137.5 4.032 1.251 2.462 False True
first epoch with 5 s before (b, sigma 20) 15.048 5.000 along layer 75 1330.0 1277.5 1.999 1.453 2.095 False True
first epoch with 5 s before (b, sigma 20) 15.048 5.000 along layer 59 1715.0 1172.5 3.742 1.566 3.060 False True
paper initiation (code 14.4 s) 14.400 5.000 top-rate units 480 472.5 1137.5 4.065 1.080 2.863 False True
paper initiation (code 14.4 s) 14.400 5.000 top-rate units 722 577.5 1137.5 4.468 1.664 2.740 False True
paper initiation (code 14.4 s) 14.400 5.000 top-rate units 867 1155.0 1347.5 4.281 1.621 2.607 False True
paper initiation (code 14.4 s) 14.400 5.000 along layer 434 752.5 1137.5 5.144 0.996 2.597 False True
paper initiation (code 14.4 s) 14.400 5.000 along layer 75 1330.0 1277.5 2.408 1.499 2.093 False True
paper initiation (code 14.4 s) 14.400 5.000 along layer 59 1715.0 1172.5 5.588 1.530 2.973 False True
onset_s baseline_s holds_theta holds_broadband
onset electrodes
criterion (a, sigma 10) top-rate units 0.730 0.730 0 0
along layer 0.730 0.730 0 0
criterion (a, sigma 20) top-rate units 0.895 0.895 0 0
along layer 0.895 0.895 0 0
criterion (b, sigma 10) top-rate units 0.893 0.893 0 0
along layer 0.893 0.893 0 0
criterion (b, sigma 20) top-rate units 0.895 0.895 0 0
along layer 0.895 0.895 0 0
first epoch with 5 s before (a, sigma 10) top-rate units 13.150 5.000 0 0
along layer 13.150 5.000 0 0
first epoch with 5 s before (a, sigma 20) top-rate units 13.757 5.000 0 1
along layer 13.757 5.000 0 1
first epoch with 5 s before (b, sigma 10) top-rate units 14.982 5.000 0 3
along layer 14.982 5.000 0 3
first epoch with 5 s before (b, sigma 20) top-rate units 15.048 5.000 0 3
along layer 15.048 5.000 0 3
paper initiation (code 14.4 s) top-rate units 14.400 5.000 0 3
along layer 14.400 5.000 0 3
# the spectrogram around the paper's initiation at one electrode (display)
x = WL[1][:, el_layer[1]].astype(float); x = signal.sosfiltfilt(sos_l, signal.sosfiltfilt(sos_h, x - x.mean()))
coef, _ = pywt.cwt(x[8000:22000], scales, 'cmor1-1', sampling_period=1 / 1000)
pw = gaussian_filter(np.abs(coef) ** 2, 2)
plt.figure(figsize=(10, 3)); plt.imshow(np.log10(pw), aspect='auto', origin='lower', extent=[8, 22, freqs[0], freqs[-1]]); plt.axvline(14.4, color='w')
plt.ylabel('Hz'); plt.xlabel('s'); plt.colorbar(label='log10 power'); plt.show()
print(f'log10 power range {np.log10(pw).min():.1f} to {np.log10(pw).max():.1f}')
log10 power range -2.3 to 4.2
Result: reproduced, resting on an assumption. The criterion's onset, the first burst of the first epoch, falls at 0.73 to 0.90 s under the four burst readings: the recording holds only 0.73 to 0.90 s of baseline, and the 2 s after onset lie within the 2 s e-folding half-width of the 0.5 Hz wavelet from the recording's start, so these runs cannot test the claim; the criterion fails there at all six electrodes (delta ratios 0.60 to 1.54, 0.1 to 100 Hz amplitude ratios 0.77 to 1.31, theta amplitude ratios 0.89 to 1.91). With onset at the paper's initiation burst (14.4 s, 5 s baseline), delta power in the 2 s after onset is 2.4 to 5.6 times the baseline at all six electrodes and the 0.1 to 100 Hz amplitude 2.09 to 2.97 times, so the criterion holds at three of three electrodes in both electrode readings with the broadband amplitude. Taking the first epoch that has 5 s of recording before it, the onset is 14.98 or 15.05 s under reading (b) and the criterion holds at three of three electrodes in both electrode readings; under reading (a) it is 13.15 or 13.76 s, isolated bursts before the initiation, and it holds at none or one. The theta amplitude never reaches twice the baseline (at most 1.92 times), so the statement's increase in theta amplitude holds only weakly.
Summary¶
A failure to reproduce here may be a failure of this attempt, not of the paper: see the reasoning and the differences from the paper's method.
| Claim | Outcome |
|---|---|
| table2-phase-locking-counts | not reproduced (Methods' selection; the code's selection matches S1 and S2) |
| table2-phase-locking-seizure-vs-not | partially reproduced |
| fig2b-phase-cluster-kuiper | reproduced (on the Methods' split, which is circular) |
| ext4-electrode-lag-clusters | partially reproduced |
| fig1j-theta-propagation-stages | not reproduced |
| ext4b-theta-delay | not reproduced |
| fig2a-subbursts-track-theta | not reproduced |
| ext3-onset-spectral-signature | reproduced, resting on the choice of onset |
| methods-rolling-wave-counts | blocked (methods_underspecified; the criterion's detector finds no rolling wave) |
How the analysis differs from the paper's: LFP is the 20-sample mean of the raw voltage (1 kHz), not the paper's filtered and downsampled pickles; stage windows are taken from the times in the paper's figures and code, with baselines free of detected bursts and, for S2, initiation windows of at least one theta cycle as variants; spikes for phase locking are kept while the theta envelope exceeds the RMS of theta over the analysed windows or, as a second reading, over the whole recording; the propagation direction is a plane fit to lags, a measure the claims file names, where the paper judged videos by eye; recordings 7 and 8 (S5, S6) have no raw data here, so the phase locking and electrode clustering of those slices are not tested.
What was found about the dataset: the raw files hold recordings 1 to 6 of the paper (S1 baseline from 20 s of sub-10F-0, S4 from 30 s of sub-9E-2); the S5 and S6 recordings are not in the dandiset; no file records when kainic acid was applied.
POOL.shutdown()
print(f'notebook ran in {(time.time()-T0)/60:.1f} min; peak memory {resource.getrusage(resource.RUSAGE_SELF).ru_maxrss/1e6:.1f} GB')
notebook ran in 25.6 min; peak memory 3.8 GB