In [1]:
# # Keles et al. (2024) from dandiset 000623: HFB power of microwire LFP and macro iEEG
#
# Paper: Keles et al. (2024), Scientific Data 11, 214, doi:10.1038/s41597-024-03029-1.
# Dataset: DANDI:000623, version 0.240130.2108, the version the paper cites (reference 54); the
# three published versions hold the same 29 assets (`reproduce_keles_2024.ipynb` shows this).
# Claims file: `claims/keles-2024.yaml`, from the version of record and the
# paper's code (github.com/rutishauserlab/bmovie-release-NWB-BIDS at commit 8c35290).
#
# This notebook computes high-frequency broadband (HFB) power as the paper's `prep_filterLFP.py`
# does, for every session and electrode type, and tests the memory and event selectivity of
# channels; it also tests the example units and channels of Figs. 6 and 7 and the comparison of
# modalities, which needs the single-cell result again.
#
# | Claim | Here |
# |---|---|
# | memory-lfp, memory-ieeg | tested |
# | event-lfp, event-ieeg | tested, with the code's scene-cut annotations |
# | fig6-examples, fig7-examples | tested |
# | memory-modalities-differ | tested |
# | nwb-contents | tested, with the clock check of the LFP |
#
# The other claims are in `reproduce_keles_2024.ipynb`.
In [2]:
import os
os.environ.setdefault("OMP_NUM_THREADS", "1")
import time
from concurrent.futures import ProcessPoolExecutor

import numpy as np
import pandas as pd

import bmovie as bm

pd.set_option("display.width", 160)
pd.set_option("display.max_columns", 30)

assets = bm.asset_urls()
with ProcessPoolExecutor(6) as ex:
    S = list(ex.map(bm.load_session, [u for _, u, _ in assets]))
cuts = bm.scenecuts()
ids = [s["identifier"] for s in S]

t_start = time.time()
with ProcessPoolExecutor(4) as ex:
    H = list(ex.map(bm.hfb_job, [(u, bm.hfb_onsets(s, cuts)) for (_, u, _), s in zip(assets, S)]))
print("HFB computed for %d sessions in %.1f min" % (len(H), (time.time() - t_start) / 60))
HFB computed for 29 sessions in 24.8 min
In [3]:
rows = []
for s, h in zip(S, H):
    for et in ["LFP_micro", "LFP_macro"]:
        o = h[et]
        if o is None:
            rows.append(dict(session=s["identifier"], type=et, channels=0))
            continue
        ar = pd.Series([n[1:-1] for n in o["names"]]).value_counts().to_dict()
        rows.append(dict(session=s["identifier"], type=et, channels=len(o["names"]),
                         channels_in_file=s["lfp"][et]["shape"][1], **ar,
                         memory_nan=int(np.isnan(o["memory"]).sum()), events_nan=int(np.isnan(o["events"]).sum()),
                         memory_range=(round(float(np.nanmin(o["memory"])), 2), round(float(np.nanmax(o["memory"])), 2)),
                         events_range=(round(float(np.nanmin(o["events"])), 2), round(float(np.nanmax(o["events"])), 2))))
chan = pd.DataFrame(rows).fillna(0)
print(chan.to_string())
print("\nchannels per type and area (all sessions):")
print(chan.groupby("type")[["ACC", "AMY", "HIP", "OFC", "SMA"]].sum().astype(int).to_string())
print("\nHFB is z-scored power (no unit); window means range from %.2f to %.2f"
      % (min(np.nanmin(h[e]["events"]) for h in H for e in h), max(np.nanmax(h[e]["events"]) for h in H for e in h)))
     session       type  channels  channels_in_file  ACC  SMA  AMY  HIP   OFC  memory_nan  events_nan   memory_range    events_range
0   P41CS_R1  LFP_micro        80                80   16   16   16   16  16.0           0           0  (-0.27, 0.87)   (-0.24, 1.36)
1   P41CS_R1  LFP_macro        80                96   16   16   16   16  16.0           0           0  (-0.34, 1.81)   (-0.34, 2.66)
2   P41CS_R2  LFP_micro        80                80   16   16   16   16  16.0           0           0  (-0.22, 0.95)   (-0.29, 2.25)
3   P41CS_R2  LFP_macro        80                96   16   16   16   16  16.0           0           0  (-0.35, 1.24)   (-0.35, 4.22)
4   P42CS_R1  LFP_micro        64                64   16   16   16   16   0.0           0           0  (-0.28, 1.25)   (-0.38, 1.65)
5   P42CS_R1  LFP_macro        80                96   16   16   16   16  16.0           0           0  (-0.51, 0.54)   (-0.61, 2.32)
6   P42CS_R2  LFP_micro        64                64   16   16   16   16   0.0           0           0   (-0.3, 1.01)    (-0.38, 0.9)
7   P42CS_R2  LFP_macro        80                96   16   16   16   16  16.0           0           0  (-0.36, 0.92)    (-0.4, 1.11)
8   P43CS_R1  LFP_micro        80                80   16   16   16   16  16.0           0           0  (-0.29, 0.68)   (-0.37, 3.29)
9   P43CS_R1  LFP_macro        80                96   16   16   16   16  16.0           0           0  (-0.39, 0.84)   (-0.35, 2.01)
10  P43CS_R2  LFP_micro        80                80   16   16   16   16  16.0           0           0  (-0.29, 0.69)   (-0.43, 3.83)
11  P43CS_R2  LFP_macro        80                96   16   16   16   16  16.0           0           0  (-0.35, 0.98)    (-0.42, 1.8)
12  P44CS_R1  LFP_micro        64                64   16   16   16   16   0.0           0           0   (-0.3, 1.68)   (-0.32, 1.73)
13  P44CS_R1  LFP_macro        80                96   16   16   16   16  16.0           0           0  (-0.33, 0.88)   (-0.33, 4.56)
14  P47CS_R1  LFP_micro        80                80   16   16   16   16  16.0           0           0   (-0.25, 0.8)   (-0.39, 3.78)
15  P47CS_R1  LFP_macro        80                96   16   16   16   16  16.0           0           0  (-0.25, 0.93)  (-0.25, 10.54)
16  P47CS_R2  LFP_micro        80                80   16   16   16   16  16.0           0           0  (-0.33, 1.45)    (-0.34, 2.1)
17  P47CS_R2  LFP_macro        80                96   16   16   16   16  16.0           0           0  (-0.27, 1.19)   (-0.38, 1.35)
18  P48CS_R1  LFP_micro        80                80   16   16   16   16  16.0           0           0   (-0.4, 3.09)   (-0.36, 2.96)
19  P48CS_R1  LFP_macro        80                96   16   16   16   16  16.0           0           0  (-0.31, 1.11)   (-0.42, 7.11)
20  P48CS_R2  LFP_micro        80                80   16   16   16   16  16.0           0           0  (-0.38, 1.25)   (-0.33, 1.98)
21  P48CS_R2  LFP_macro        80                96   16   16   16   16  16.0           0           0  (-0.42, 1.81)   (-0.45, 1.55)
22  P49CS_R1  LFP_micro        80                80   16   16   16   16  16.0           0           0  (-0.21, 1.11)   (-0.24, 2.96)
23  P49CS_R1  LFP_macro        80                96   16   16   16   16  16.0           0           0  (-0.46, 1.63)   (-0.45, 2.82)
24  P49CS_R2  LFP_micro        80                80   16   16   16   16  16.0           0           0  (-0.33, 1.54)   (-0.44, 2.61)
25  P49CS_R2  LFP_macro        80                96   16   16   16   16  16.0           0           0   (-0.3, 3.49)   (-0.34, 2.64)
26  P51CS_R1  LFP_micro        80                80   16   16   16   16  16.0           0           0  (-0.27, 2.78)   (-0.42, 1.71)
27  P51CS_R1  LFP_macro        80               128   16   16   16   16  16.0           0           0  (-0.27, 1.24)   (-0.35, 5.35)
28  P51CS_R2  LFP_micro        80                80   16   16   16   16  16.0           0           0  (-0.32, 1.62)   (-0.42, 1.31)
29  P51CS_R2  LFP_macro        80               128   16   16   16   16  16.0           0           0  (-0.27, 1.49)   (-0.34, 0.75)
30  P53CS_R1  LFP_micro        80                80   16   16   16   16  16.0           0           0  (-0.25, 0.61)  (-0.32, 11.25)
31  P53CS_R1  LFP_macro        80                96   16   16   16   16  16.0           0           0  (-0.25, 2.67)  (-0.52, 11.46)
32  P53CS_R2  LFP_micro        80                80   16   16   16   16  16.0           0           0  (-0.35, 1.32)   (-0.46, 1.92)
33  P53CS_R2  LFP_macro        80                96   16   16   16   16  16.0           0           0  (-0.53, 0.89)   (-0.49, 4.02)
34  P54CS_R1  LFP_micro        80                80   16   16   16   16  16.0           0           0  (-0.28, 1.22)   (-0.27, 3.59)
35  P54CS_R1  LFP_macro        80                96   16   16   16   16  16.0           0           0  (-0.22, 0.75)   (-0.45, 2.56)
36  P54CS_R2  LFP_micro        80                80   16   16   16   16  16.0           0           0  (-0.33, 1.63)    (-0.3, 3.33)
37  P54CS_R2  LFP_macro        80                96   16   16   16   16  16.0           0           0   (-0.3, 6.05)   (-0.52, 7.58)
38  P55CS_R1  LFP_micro        80                80   16   16   16   16  16.0           0           0  (-0.32, 1.23)   (-0.37, 1.38)
39  P55CS_R1  LFP_macro        80                96   16   16   16   16  16.0           0           0  (-0.42, 3.66)   (-0.35, 3.83)
40  P55CS_R2  LFP_micro        80                80   16   16   16   16  16.0           0           0  (-0.29, 0.96)   (-0.38, 2.39)
41  P55CS_R2  LFP_macro        80                96   16   16   16   16  16.0           0           0  (-0.25, 1.72)   (-0.43, 4.61)
42  P56CS_R1  LFP_micro        80                80   16   16   16   16  16.0           0           0  (-0.24, 1.09)   (-0.35, 4.21)
43  P56CS_R1  LFP_macro        80               106   16   16   16   16  16.0           0           0  (-0.59, 3.61)   (-0.35, 4.32)
44  P56CS_R2  LFP_micro        80                80   16   16   16   16  16.0           0           0  (-0.17, 1.36)   (-0.32, 1.91)
45  P56CS_R2  LFP_macro        80               106   16   16   16   16  16.0           0           0  (-0.37, 2.39)   (-0.34, 1.81)
46  P57CS_R1  LFP_micro        80                80   16   16   16   16  16.0           0           0   (-0.3, 0.62)   (-0.36, 2.81)
47  P57CS_R1  LFP_macro        80               102   16   16   16   16  16.0           0           0  (-0.48, 1.86)    (-0.66, 2.5)
48  P57CS_R2  LFP_micro        80                80   16   16   16   16  16.0           0           0  (-0.25, 0.49)   (-0.32, 0.83)
49  P57CS_R2  LFP_macro        80               102   16   16   16   16  16.0           0           0  (-0.56, 4.35)   (-0.56, 1.15)
50  P58CS_R1  LFP_micro        80                80   16   16   16   16  16.0           0           0  (-0.34, 1.56)   (-0.42, 2.52)
51  P58CS_R1  LFP_macro        80                86   16   16   16   16  16.0           0           0  (-0.31, 1.95)    (-0.4, 4.02)
52  P60CS_R1  LFP_micro        80                80   16   16   16   16  16.0           0           0   (-0.31, 0.8)    (-0.3, 5.59)
53  P60CS_R1  LFP_macro        80                92   16   16   16   16  16.0           0           0  (-0.31, 1.36)   (-0.36, 4.22)
54  P62CS_R1  LFP_micro        40                56    8    8    8    8   8.0           0           0  (-0.26, 1.29)   (-0.35, 3.06)
55  P62CS_R1  LFP_macro        40                40    8    8    8    8   8.0           0           0  (-0.32, 4.08)   (-0.38, 3.12)
56  P62CS_R2  LFP_micro        40                56    8    8    8    8   8.0           0           0   (-0.3, 1.79)    (-0.33, 1.0)
57  P62CS_R2  LFP_macro        40                40    8    8    8    8   8.0           0           0  (-0.29, 2.18)   (-0.39, 3.79)

channels per type and area (all sessions):
           ACC  AMY  HIP  OFC  SMA
type                              
LFP_macro  448  448  448  448  448
LFP_micro  448  448  448  400  448

HFB is z-scored power (no unit); window means range from -0.66 to 11.46

Intermediate steps of the HFB pipeline. For each session, electrode type and task block, hfb_session keeps the median over channels of the power spectrum before the notch filter and after notch, high-pass and re-referencing, and the mean, s.d. and maximum of each channel's HFB trace. The next cell prints the line-noise power at 60, 120 and 180 Hz relative to the neighbouring 5 Hz on either side, before and after the filters, and the distribution of the per-channel HFB statistics (z-scored per frequency, then averaged over the 11 frequencies, so the mean is 0 and the s.d. below 1).

In [4]:
f = H[0]["LFP_micro"]["psd_freqs"]
def line_ratio(psd, f0):
    i0 = np.argmin(np.abs(f - f0))
    nb = (np.abs(f - (f0 - 5)) < 1.0) | (np.abs(f - (f0 + 5)) < 1.0)
    return psd[i0] / psd[nb].mean()
rows = []
for s, h in zip(S, H):
    for et in ["LFP_micro", "LFP_macro"]:
        o = h[et]
        if o is None:
            continue
        for task in ["enc", "recog"]:
            r = dict(session=s["identifier"], type=et, task=task)
            for f0 in [60, 120, 180]:
                r[f"{f0}Hz_before"] = line_ratio(o[f"psd_{task}_before"], f0)
                r[f"{f0}Hz_after"] = line_ratio(o[f"psd_{task}_after"], f0)
            st = o[f"hfbstats_{task}"]
            r.update(hfb_mean_absmax=np.abs(st[:, 0]).max(), hfb_sd_median=np.median(st[:, 1]),
                     hfb_sd_min=st[:, 1].min(), hfb_sd_max=st[:, 1].max(), hfb_max_median=np.median(st[:, 2]))
            rows.append(r)
inter = pd.DataFrame(rows)
print("line-noise power over the neighbouring +-5 Hz (median over channels), by session, type and block:")
print(inter.round(3).to_string(index=False))
print("\nmedian over blocks:")
print(inter.groupby("type")[[c for c in inter.columns if c.endswith("before") or c.endswith("after")]].median().round(3).to_string())
print("\nlargest |channel mean HFB|: %.2g; channel s.d. from %.3f to %.3f (median %.3f)"
      % (inter.hfb_mean_absmax.max(), inter.hfb_sd_min.min(), inter.hfb_sd_max.max(), inter.hfb_sd_median.median()))
line-noise power over the neighbouring +-5 Hz (median over channels), by session, type and block:
 session      type  task  60Hz_before  60Hz_after  120Hz_before  120Hz_after  180Hz_before  180Hz_after  hfb_mean_absmax  hfb_sd_median  hfb_sd_min  hfb_sd_max  hfb_max_median
P41CS_R1 LFP_micro   enc        8.911       0.080         6.377        0.033         3.739        0.013              0.0          0.776       0.723       0.982         121.124
P41CS_R1 LFP_micro recog        8.029       0.072         6.155        0.033         3.418        0.014              0.0          0.706       0.681       0.979          17.258
P41CS_R1 LFP_macro   enc       19.953       0.078       131.390        0.059       188.201        0.015              0.0          0.778       0.708       0.892          62.264
P41CS_R1 LFP_macro recog       15.529       0.085       123.494        0.077       170.888        0.017              0.0          0.812       0.704       0.968          54.524
P41CS_R2 LFP_micro   enc       11.167       0.079         6.561        0.035         3.566        0.013              0.0          0.717       0.692       0.982          43.695
P41CS_R2 LFP_micro recog        9.193       0.089         6.537        0.032         3.229        0.013              0.0          0.703       0.677       0.978           9.185
P41CS_R2 LFP_macro   enc       16.916       0.083        96.263        0.051       151.642        0.016              0.0          0.784       0.708       0.929          54.650
P41CS_R2 LFP_macro recog       18.098       0.081       154.168        0.036       206.322        0.014              0.0          0.736       0.682       0.908          26.420
P42CS_R1 LFP_micro   enc        3.482       0.081         2.485        0.032         1.578        0.013              0.0          0.699       0.671       0.960          33.634
P42CS_R1 LFP_micro recog        2.931       0.082         2.078        0.031         1.424        0.012              0.0          0.770       0.677       0.979          45.335
P42CS_R1 LFP_macro   enc        8.940       0.071        27.159        0.031        18.906        0.013              0.0          0.713       0.680       0.856          14.864
P42CS_R1 LFP_macro recog        6.966       0.080        23.333        0.031        16.251        0.013              0.0          0.728       0.689       0.962          23.616
P42CS_R2 LFP_micro   enc        1.701       0.090         2.032        0.033         1.823        0.012              0.0          0.957       0.773       0.982         184.650
P42CS_R2 LFP_micro recog        2.983       0.082         2.286        0.039         1.842        0.012              0.0          0.905       0.710       0.983         125.257
P42CS_R2 LFP_macro   enc       14.956       0.072        48.415        0.032        22.040        0.013              0.0          0.712       0.677       0.865          10.871
P42CS_R2 LFP_macro recog       10.032       0.077        36.056        0.031        18.575        0.012              0.0          0.758       0.700       0.945          49.070
P43CS_R1 LFP_micro   enc       19.677       0.083         0.926        0.033        12.533        0.011              0.0          0.693       0.671       0.967          11.274
P43CS_R1 LFP_micro recog       19.069       0.078         0.975        0.032        12.490        0.012              0.0          0.686       0.667       0.940           8.173
P43CS_R1 LFP_macro   enc        2.295       0.071         1.223        0.034         3.758        0.013              0.0          0.701       0.677       0.888           9.551
P43CS_R1 LFP_macro recog        2.258       0.076         1.116        0.031         3.976        0.012              0.0          0.728       0.679       0.927          39.898
P43CS_R2 LFP_micro   enc       21.752       0.078         0.986        0.030        13.850        0.013              0.0          0.696       0.675       0.958          11.952
P43CS_R2 LFP_micro recog       19.366       0.075         1.016        0.031        13.956        0.013              0.0          0.685       0.674       0.847           7.403
P43CS_R2 LFP_macro   enc        2.443       0.079         1.401        0.032         3.663        0.012              0.0          0.706       0.682       0.879          16.744
P43CS_R2 LFP_macro recog        2.009       0.081         1.078        0.029         3.267        0.012              0.0          0.713       0.679       0.901          13.669
P44CS_R1 LFP_micro   enc        4.101       0.084         3.099        0.029         2.509        0.011              0.0          0.978       0.733       0.983         174.176
P44CS_R1 LFP_micro recog        2.891       0.076         2.489        0.037         2.493        0.016              0.0          0.957       0.720       0.980          81.292
P44CS_R1 LFP_macro   enc        7.160       0.079        29.401        0.030        32.934        0.013              0.0          0.734       0.690       0.872          28.928
P44CS_R1 LFP_macro recog        5.414       0.082        16.166        0.032        18.716        0.014              0.0          0.763       0.696       0.981          28.389
P47CS_R1 LFP_micro   enc       13.719       0.079         1.517        0.032         3.465        0.013              0.0          0.853       0.705       0.982         120.349
P47CS_R1 LFP_micro recog       15.743       0.089         1.398        0.035         6.230        0.013              0.0          0.709       0.681       0.981          16.398
P47CS_R1 LFP_macro   enc       21.603       0.084         1.593        0.033         4.865        0.013              0.0          0.941       0.755       0.981          43.291
P47CS_R1 LFP_macro recog       20.151       0.078         1.745        0.032         4.860        0.012              0.0          0.888       0.738       0.972          62.903
P47CS_R2 LFP_micro   enc        3.172       0.082         4.337        0.031        11.098        0.014              0.0          0.765       0.684       0.981          56.628
P47CS_R2 LFP_micro recog        2.358       0.092         3.445        0.032        11.100        0.013              0.0          0.725       0.682       0.978          20.062
P47CS_R2 LFP_macro   enc       16.492       0.080         1.714        0.032         3.161        0.012              0.0          0.798       0.713       0.967          79.505
P47CS_R2 LFP_macro recog       12.662       0.068         1.357        0.036         3.614        0.011              0.0          0.856       0.728       0.976          42.741
P48CS_R1 LFP_micro   enc      123.273       0.083         0.883        0.033        18.526        0.013              0.0          0.859       0.702       0.982          93.972
P48CS_R1 LFP_micro recog      139.041       0.079         0.844        0.028        19.663        0.013              0.0          0.835       0.711       0.981          50.585
P48CS_R1 LFP_macro   enc       60.210       0.083         1.168        0.032       163.838        0.012              0.0          0.719       0.689       0.951          26.412
P48CS_R1 LFP_macro recog       70.123       0.080         0.990        0.032       183.954        0.013              0.0          0.750       0.704       0.982          47.700
P48CS_R2 LFP_micro   enc       59.092       0.089         0.925        0.032         9.829        0.013              0.0          0.887       0.727       0.981         130.168
P48CS_R2 LFP_micro recog       59.745       0.091         0.923        0.031        10.898        0.013              0.0          0.854       0.690       0.978          51.181
P48CS_R2 LFP_macro   enc       43.306       0.079         0.929        0.029         1.662        0.012              0.0          0.730       0.701       0.948          23.051
P48CS_R2 LFP_macro recog       36.042       0.079         0.928        0.031         1.659        0.013              0.0          0.770       0.702       0.965          28.170
P49CS_R1 LFP_micro   enc       39.882       0.084         8.689        0.033        56.827        0.012              0.0          0.939       0.702       0.982         147.088
P49CS_R1 LFP_micro recog       37.121       0.085        10.409        0.032        62.240        0.013              0.0          0.912       0.690       0.982          98.276
P49CS_R1 LFP_macro   enc       45.813       0.087        84.417        0.033        42.497        0.013              0.0          0.717       0.683       0.962          24.462
P49CS_R1 LFP_macro recog       33.513       0.084        60.879        0.032        29.190        0.012              0.0          0.794       0.694       0.966          53.042
P49CS_R2 LFP_micro   enc        9.287       0.077        11.746        0.031        32.121        0.012              0.0          0.801       0.691       0.982          85.043
P49CS_R2 LFP_micro recog        8.032       0.085        11.831        0.034        29.954        0.012              0.0          0.713       0.681       0.960          30.829
P49CS_R2 LFP_macro   enc        2.987       0.080        12.153        0.045        15.645        0.012              0.0          0.921       0.754       0.981         122.284
P49CS_R2 LFP_macro recog        2.396       0.076         9.535        0.055        12.013        0.011              0.0          0.916       0.724       0.978          67.330
P51CS_R1 LFP_micro   enc      123.450       0.084         1.241        0.033         4.043        0.013              0.0          0.687       0.678       0.920           8.106
P51CS_R1 LFP_micro recog      125.559       0.088         1.165        0.029         4.011        0.013              0.0          0.691       0.679       0.963          12.859
P51CS_R1 LFP_macro   enc      195.643       0.080         1.197        0.032         1.595        0.013              0.0          0.713       0.682       0.860          21.183
P51CS_R1 LFP_macro recog      214.985       0.095         1.100        0.033         1.591        0.013              0.0          0.730       0.678       0.983          42.720
P51CS_R2 LFP_micro   enc       41.758       0.085         1.121        0.031         1.836        0.013              0.0          0.704       0.681       0.982          44.759
P51CS_R2 LFP_micro recog       15.464       0.083         1.059        0.032         1.708        0.013              0.0          0.742       0.684       0.981          51.081
P51CS_R2 LFP_macro   enc       81.964       0.083         1.024        0.033         3.468        0.013              0.0          0.869       0.680       0.974          82.649
P51CS_R2 LFP_macro recog       34.265       0.076         1.028        0.032         3.068        0.012              0.0          0.897       0.681       0.952          56.351
P53CS_R1 LFP_micro   enc       34.507       0.077         1.483        0.033       240.138        0.014              0.0          0.811       0.685       0.980          90.243
P53CS_R1 LFP_micro recog       29.449       0.079         1.785        0.031       196.620        0.015              0.0          0.742       0.676       0.977          26.833
P53CS_R1 LFP_macro   enc       62.247       0.076         1.157        0.054      1099.283        0.023              0.0          0.806       0.722       0.897          49.199
P53CS_R1 LFP_macro recog       75.128       0.084         1.220        0.050      1035.152        0.017              0.0          0.743       0.693       0.977          32.074
P53CS_R2 LFP_micro   enc        3.466       0.080         1.020        0.034         5.910        0.013              0.0          0.694       0.679       0.977          17.615
P53CS_R2 LFP_micro recog        3.545       0.090         1.024        0.031         5.539        0.012              0.0          0.700       0.678       0.981          12.078
P53CS_R2 LFP_macro   enc       44.234       0.080         1.147        0.046       584.749        0.010              0.0          0.771       0.710       0.921          23.729
P53CS_R2 LFP_macro recog       52.258       0.091         1.084        0.031       581.766        0.009              0.0          0.753       0.703       0.854          16.580
P54CS_R1 LFP_micro   enc       22.883       0.076         1.974        0.033      1105.396        0.016              0.0          0.855       0.728       0.981          58.405
P54CS_R1 LFP_micro recog       17.077       0.087         1.550        0.033       664.063        0.014              0.0          0.885       0.732       0.982          50.109
P54CS_R1 LFP_macro   enc     4969.374       0.104         6.068        0.073     69200.120        0.206              0.0          0.774       0.726       0.895          70.646
P54CS_R1 LFP_macro recog     6159.942       0.132         5.159        0.059     95090.350        0.021              0.0          0.788       0.737       0.919          61.220
P54CS_R2 LFP_micro   enc       33.651       0.081         1.397        0.033       415.145        0.013              0.0          0.800       0.684       0.982          64.185
P54CS_R2 LFP_micro recog       29.293       0.072         1.373        0.031       400.051        0.014              0.0          0.829       0.685       0.980          52.383
P54CS_R2 LFP_macro   enc      908.842       0.085         8.518        0.035     28238.740        0.021              0.0          0.736       0.689       0.947          34.186
P54CS_R2 LFP_macro recog      922.768       0.078         6.113        0.036     24861.801        0.026              0.0          0.793       0.689       0.966          66.479
P55CS_R1 LFP_micro   enc        7.730       0.085         1.446        0.034      1214.330        0.014              0.0          0.921       0.715       0.986         159.549
P55CS_R1 LFP_micro recog        7.221       0.072         1.492        0.032      1678.950        0.015              0.0          0.788       0.681       0.974          62.664
P55CS_R1 LFP_macro   enc      251.725       0.089         4.681        0.041      1631.038        0.021              0.0          0.721       0.673       0.970          35.261
P55CS_R1 LFP_macro recog      258.692       0.088         6.055        0.038      2080.276        0.022              0.0          0.741       0.674       0.948          31.790
P55CS_R2 LFP_micro   enc        5.888       0.089         1.883        0.052       344.379        0.017              0.0          0.816       0.691       0.976          78.548
P55CS_R2 LFP_micro recog        4.722       0.079         1.669        0.055       486.988        0.025              0.0          0.719       0.672       0.977          21.676
P55CS_R2 LFP_macro   enc      161.666       0.091         5.949        0.037       841.021        0.016              0.0          0.739       0.682       0.957          40.596
P55CS_R2 LFP_macro recog      180.085       0.100         3.458        0.039      1680.093        0.021              0.0          0.758       0.690       0.982          39.990
P56CS_R1 LFP_micro   enc        2.339       0.083         1.105        0.033        33.384        0.013              0.0          0.744       0.682       0.980          62.175
P56CS_R1 LFP_micro recog        2.417       0.091         1.028        0.032        26.662        0.012              0.0          0.790       0.679       0.912          51.857
P56CS_R1 LFP_macro   enc      706.350       0.078         8.315        0.035       383.975        0.014              0.0          0.734       0.703       0.953          22.240
P56CS_R1 LFP_macro recog       51.547       0.012         2.961        0.012        35.718        0.000              0.0          0.861       0.720       0.980          10.554
P56CS_R2 LFP_micro   enc        2.033       0.074         1.131        0.033        24.517        0.015              0.0          0.896       0.711       0.980         125.678
P56CS_R2 LFP_micro recog        1.787       0.075         1.031        0.030        26.350        0.012              0.0          0.938       0.796       0.979         123.773
P56CS_R2 LFP_macro   enc     1174.598       0.087        16.830        0.034       619.646        0.015              0.0          0.781       0.705       0.973          56.531
P56CS_R2 LFP_macro recog     1162.964       0.090        11.097        0.033       986.789        0.013              0.0          0.785       0.716       0.971          44.176
P57CS_R1 LFP_micro   enc        1.965       0.090         1.040        0.032        14.242        0.012              0.0          0.686       0.672       0.876           7.766
P57CS_R1 LFP_micro recog        2.086       0.079         0.961        0.033        14.244        0.013              0.0          0.687       0.674       0.834           6.989
P57CS_R1 LFP_macro   enc      131.876       0.083        11.294        0.032       519.681        0.013              0.0          0.708       0.687       0.943          11.969
P57CS_R1 LFP_macro recog      148.858       0.082        34.353        0.030       879.466        0.014              0.0          0.791       0.726       0.958          39.773
P57CS_R2 LFP_micro   enc        4.140       0.088         1.073        0.035        36.832        0.012              0.0          0.686       0.678       0.826           8.256
P57CS_R2 LFP_micro recog        3.834       0.082         1.073        0.034        30.816        0.010              0.0          0.689       0.675       0.884           8.612
P57CS_R2 LFP_macro   enc      122.865       0.088        11.263        0.036       516.126        0.013              0.0          0.733       0.702       0.949          48.365
P57CS_R2 LFP_macro recog      148.831       0.096        21.127        0.035       721.695        0.012              0.0          0.820       0.716       0.968          59.012
P58CS_R1 LFP_micro   enc        4.653       0.084         1.047        0.030         3.332        0.013              0.0          0.716       0.672       0.948          27.886
P58CS_R1 LFP_micro recog        6.600       0.080         1.019        0.030         3.370        0.013              0.0          0.699       0.668       0.930           9.395
P58CS_R1 LFP_macro   enc      422.996       0.081         3.468        0.032      4632.470        0.017              0.0          0.818       0.726       0.982         115.541
P58CS_R1 LFP_macro recog      592.158       0.084         3.070        0.030      4595.163        0.055              0.0          0.745       0.682       0.967          31.697
P60CS_R1 LFP_micro   enc       10.207       0.082         4.753        0.033         1.923        0.013              0.0          0.765       0.689       0.982          47.974
P60CS_R1 LFP_micro recog       10.947       0.081         4.699        0.033         1.598        0.013              0.0          0.707       0.672       0.954          13.337
P60CS_R1 LFP_macro   enc      723.228       0.091        28.450        0.038      1571.612        0.015              0.0          0.802       0.716       0.929          38.777
P60CS_R1 LFP_macro recog      968.181       0.105        52.598        0.041      2430.960        0.016              0.0          0.754       0.702       0.895          26.573
P62CS_R1 LFP_micro   enc        4.661       0.076         1.059        0.034         9.573        0.013              0.0          0.902       0.711       0.981         150.530
P62CS_R1 LFP_micro recog        5.204       0.078         0.944        0.031         7.793        0.013              0.0          0.888       0.709       0.980          90.280
P62CS_R1 LFP_macro   enc       33.765       0.083         1.618        0.036       626.814        0.017              0.0          0.731       0.703       0.869          19.109
P62CS_R1 LFP_macro recog       59.738       0.088         1.824        0.033      1214.496        0.014              0.0          0.733       0.701       0.883          23.577
P62CS_R2 LFP_micro   enc        4.616       0.077         1.004        0.035         6.922        0.012              0.0          0.922       0.709       0.978         162.759
P62CS_R2 LFP_micro recog        5.803       0.081         1.064        0.036        11.861        0.011              0.0          0.761       0.685       0.971          43.358
P62CS_R2 LFP_macro   enc       42.482       0.081         1.559        0.032       754.474        0.014              0.0          0.735       0.707       0.887          19.157
P62CS_R2 LFP_macro recog       57.654       0.081         2.034        0.032       946.520        0.021              0.0          0.725       0.698       0.978          26.614

median over blocks:
           60Hz_before  60Hz_after  120Hz_before  120Hz_after  180Hz_before  180Hz_after
type                                                                                    
LFP_macro       51.903       0.082         4.920        0.033       186.078        0.013
LFP_micro        8.031       0.082         1.385        0.033        11.481        0.013

largest |channel mean HFB|: 0.00036; channel s.d. from 0.667 to 0.986 (median 0.758)

The LFP clock. The files give each LFP series a starting time near 0 s, and the Usage Notes say to "start at 10 seconds before the starting time" when making the LFP timepoints, so the first sample is 10 s before the movie; the code subtracts the same 10 s. The cell below reads the HFB with that offset and without it (the stored starting time taken as the time of the first sample, as the NWB format defines it), in two ways: the channels with an event-selective response to scene cuts (bootstrap p < 0.05, either direction), and the channels whose HFB in 0.2 to 1.7 s after a recognition image differs from the 1 s before it (Wilcoxon signed-rank over trials, p < 0.01). An image onset evokes a response only at the right time, so the second check can tell the two readings apart where the first, on a continuous movie, may not. The cell after it bounds the offset more finely.

In [5]:
from scipy import stats

def chan_table(et, key, sessions=None):
    blocks, rows = [], []
    for s, h in zip(S, H):
        o = h[et]
        if o is None or (sessions is not None and s["identifier"] not in sessions):
            continue
        if key.startswith("memory"):
            _, a, b = bm.memory_design(s)
        else:
            a = (cuts.kind == "change").to_numpy()
            b = (cuts.kind == "cont").to_numpy()
        blocks.append((o[key], a, b))
        rows.append(pd.DataFrame({"session": s["identifier"], "channel": o["names"],
                                  "area_code": [n[1:-1] for n in o["names"]]}))
    t = pd.concat(rows, ignore_index=True)
    t["area"] = t.area_code.map(bm.CHANNEL_AREAS).fillna(t.area_code)
    return blocks, t

for et in ["LFP_micro", "LFP_macro"]:
    for key in ["events", "events_fileclock"]:
        bl, tb = chan_table(et, key)
        p = np.concatenate([bm.observed_selection(V, a, b, False)[1] for V, a, b in bl])
        print(f"{et:10s} {key:17s} channels {len(p)}: event selective (p < 0.05) {int((p < 0.05).sum())} ({100 * (p < 0.05).mean():.1f}%)")
    for clock in ["", "_fileclock"]:
        n_sig = n_tot = 0
        for h in H:
            o = h[et]
            post, pre = o["memory" + clock], o["memory_pre" + clock]
            for c in range(post.shape[0]):
                ok = np.isfinite(post[c]) & np.isfinite(pre[c])
                n_tot += 1
                if ok.sum() >= 10 and stats.wilcoxon(post[c, ok], pre[c, ok]).pvalue < 0.01:
                    n_sig += 1
        name = "10-s offset (Usage Notes, code)" if not clock else "no offset"
        print(f"{et:10s} image onset response, {name}: {n_sig} of {n_tot} channels ({100 * n_sig / n_tot:.1f}%)")
LFP_micro  events            channels 2192: event selective (p < 0.05) 290 (13.2%)
LFP_micro  events_fileclock  channels 2192: event selective (p < 0.05) 266 (12.1%)
LFP_micro  image onset response, 10-s offset (Usage Notes, code): 650 of 2192 channels (29.7%)
LFP_micro  image onset response, no offset: 18 of 2192 channels (0.8%)
LFP_macro  events            channels 2240: event selective (p < 0.05) 268 (12.0%)
LFP_macro  events_fileclock  channels 2240: event selective (p < 0.05) 290 (12.9%)
LFP_macro  image onset response, 10-s offset (Usage Notes, code): 683 of 2240 channels (30.5%)
LFP_macro  image onset response, no offset: 20 of 2240 channels (0.9%)
In [6]:
# the offset more finely: the image-onset count with onsets shifted around the 10-s offset, and
# the time course of the HFB response next to that of the spikes, which are on the trials' clock
def n_responsive(et, post_key, pre_key):
    n_sig = n_tot = 0
    for h in H:
        o = h[et]
        post, pre = o[post_key], o[pre_key]
        for c in range(post.shape[0]):
            ok = np.isfinite(post[c]) & np.isfinite(pre[c])
            n_tot += 1
            if ok.sum() >= 10 and stats.wilcoxon(post[c, ok], pre[c, ok]).pvalue < 0.01:
                n_sig += 1
    return n_sig, n_tot

for et in ["LFP_micro", "LFP_macro"]:
    line = []
    for dd in sorted(bm.CLOCK_SHIFTS + [0.0]):
        key = "" if dd == 0 else f"_d{dd:+.2f}"
        a, b = n_responsive(et, "memory" + key, "memory_pre" + key)
        line.append(f"{10 + dd:.2f} s: {a} ({100 * a / b:.1f}%)")
    print(f"{et}, responsive channels by offset:", "; ".join(line))

edges = np.arange(bm.TC_WINDOW[0], bm.TC_WINDOW[1] + bm.TC_WINDOW[2] / 2, bm.TC_WINDOW[2])
t_bins = edges[:-1]

def latency(curve):
    """Start of the first bin after onset at or above half the peak (0 to 1.5 s), and the
    largest pre-onset value as a fraction of the peak."""
    post = t_bins >= 0
    pk = curve[post].max()
    first = t_bins[post][np.argmax(curve[post] >= pk / 2)]
    return first, curve[~post].max() / pk

def tc_population(curves):
    """Per unit or channel: baseline-subtracted mean over trials, signed so that the response
    0.2 to 1.7 s after onset is positive, and scaled by its own peak; then averaged."""
    out = []
    for m in curves:
        m = m - np.nanmean(m[t_bins < 0])
        sgn = np.sign(np.nanmean(m[(t_bins >= 0.2) & (t_bins < 1.5)]))
        if sgn == 0 or not np.isfinite(sgn):
            continue
        out.append(sgn * m)
    return np.nanmean(out, 0), len(out)

for et in ["LFP_micro", "LFP_macro"]:
    curves = []
    for h in H:
        o = h[et]
        post, pre = o["memory"], o["memory_pre"]
        for c in range(post.shape[0]):
            ok = np.isfinite(post[c]) & np.isfinite(pre[c])
            if ok.sum() >= 10 and stats.wilcoxon(post[c, ok], pre[c, ok]).pvalue < 0.01:
                curves.append(np.nanmean(o["memory_tc"][c], 0))
    pop, n = tc_population(curves)
    lat, pre_frac = latency(pop)
    print(f"{et}: {n} responsive channels; half-peak latency {lat * 1000:.0f} ms after image onset;"
          f" largest value before onset {100 * pre_frac:.0f}% of the peak")
    print("   ", " ".join(f"{v:+.2f}" for v in pop / pop.max()))
curves = []
for s in S:
    ons = bm.recog_trials(s).start_time.to_numpy()
    for st, inU in zip(s["units"].spike_times, bm.units_U(s).in_U):
        if not inU:
            continue
        st = np.asarray(st)
        post = bm.window_counts(st, ons, (0.2, 1.7))
        pre = bm.window_counts(st, ons, (-1.5, -0.0001))
        if np.any(post != pre) and stats.wilcoxon(post, pre).pvalue < 0.01:
            cnt = np.array([np.histogram(st - o, bins=edges)[0] for o in ons], float)
            curves.append(cnt.mean(0))
pop, n = tc_population(curves)
lat, pre_frac = latency(pop)
print(f"units: {n} responsive units; half-peak latency {lat * 1000:.0f} ms after image onset;"
      f" largest value before onset {100 * pre_frac:.0f}% of the peak")
print("   ", " ".join(f"{v:+.2f}" for v in pop / pop.max()))
print("bin starts (s):", " ".join(f"{v:+.2f}" for v in t_bins))
LFP_micro, responsive channels by offset: 9.00 s: 460 (21.0%); 9.50 s: 461 (21.0%); 9.75 s: 492 (22.4%); 9.90 s: 590 (26.9%); 10.00 s: 650 (29.7%); 10.10 s: 693 (31.6%); 10.25 s: 695 (31.7%); 10.50 s: 565 (25.8%); 11.00 s: 257 (11.7%)
LFP_macro, responsive channels by offset: 9.00 s: 356 (15.9%); 9.50 s: 433 (19.3%); 9.75 s: 560 (25.0%); 9.90 s: 617 (27.5%); 10.00 s: 683 (30.5%); 10.10 s: 715 (31.9%); 10.25 s: 724 (32.3%); 10.50 s: 565 (25.2%); 11.00 s: 345 (15.4%)
LFP_micro: 650 responsive channels; half-peak latency 350 ms after image onset; largest value before onset 9% of the peak
    +0.09 +0.04 -0.06 +0.01 -0.04 +0.03 -0.05 -0.09 -0.01 +0.05 +0.02 +0.04 +0.00 +0.15 +0.20 +0.30 +0.30 +0.59 +0.77 +0.75 +0.65 +0.75 +0.84 +0.84 +0.85 +0.90 +1.00 +0.97 +0.88 +0.94 +0.92 +0.90 +0.76 +0.84 +0.84 +0.77 +0.88 +0.78 +0.74 +0.81
LFP_macro: 683 responsive channels; half-peak latency 200 ms after image onset; largest value before onset 7% of the peak
    +0.04 -0.03 +0.00 +0.07 -0.01 +0.00 -0.03 -0.03 -0.04 +0.02 +0.01 +0.04 +0.10 +0.27 +0.59 +0.47 +0.47 +0.62 +0.79 +0.76 +0.78 +0.82 +0.95 +1.00 +0.90 +0.86 +0.92 +0.86 +0.83 +0.87 +0.86 +0.74 +0.69 +0.72 +0.75 +0.73 +0.62 +0.62 +0.62 +0.58
units: 192 responsive units; half-peak latency 300 ms after image onset; largest value before onset 10% of the peak
    -0.02 -0.06 +0.02 -0.06 -0.03 -0.01 -0.02 -0.01 +0.10 +0.03 +0.07 +0.11 +0.17 +0.16 +0.28 +0.41 +0.63 +0.74 +0.83 +0.91 +0.98 +0.94 +0.95 +1.00 +0.99 +0.98 +0.93 +0.99 +0.89 +0.86 +0.83 +0.82 +0.76 +0.74 +0.65 +0.72 +0.62 +0.59 +0.60 +0.58
bin starts (s): -0.50 -0.45 -0.40 -0.35 -0.30 -0.25 -0.20 -0.15 -0.10 -0.05 -0.00 +0.05 +0.10 +0.15 +0.20 +0.25 +0.30 +0.35 +0.40 +0.45 +0.50 +0.55 +0.60 +0.65 +0.70 +0.75 +0.80 +0.85 +0.90 +0.95 +1.00 +1.05 +1.10 +1.15 +1.20 +1.25 +1.30 +1.35 +1.40 +1.45

nwb-contents¶

Each NWB file holds spike times of all sorted neurons, LFP from all microwires and field potentials from all macro contacts downsampled to 1000 Hz, behavior, electrode locations, spike-sorting quality metrics and eye-tracking data; spike times are referenced to movie start and the LFP starts 10 s before it.

In [7]:
need_units = {"spike_times", "electrode_id", "isibelow", "peakSNR", "meanSNR", "isolationdist"}
chk = []
for s in S:
    t0, _ = bm.movie_window(s)
    lf = s["lfp"]
    chk.append(dict(
        session=s["identifier"],
        units=need_units <= set(s["units_columns"]) and len(s["units"]) > 0,
        micro_1kHz=("LFP_micro" in lf and lf["LFP_micro"]["rate"] == 1000.0),
        macro_1kHz=("LFP_macro" in lf and lf["LFP_macro"]["rate"] == 1000.0),
        lfp_start_file=round(min(v["starting_time"] for v in lf.values()), 4),
        lfp_end_after_last_trial=round(min(v["starting_time"] - bm.LFP_PAD_S + v["shape"][0] / v["rate"]
                                           for v in lf.values()) - float(s["trials"].stop_time.max()), 1),
        trials=len(s["trials"]) > 1, locations="location" in s["electrodes"].columns,
        pairwise="pairwise_distances" in s["electrodes"].columns,
        gaze="EyeTracking" in s["behavior_modules"], frames=len(s["frame_times"]) == 11971,
        movie_start=t0, movie_start_ok=abs(t0) <= 0.04))
chk = pd.DataFrame(chk).set_index("session")
print(chk.to_string())
cols = ["units", "micro_1kHz", "macro_1kHz", "trials", "locations", "pairwise", "gaze", "frames", "movie_start_ok"]
print("\nall files pass every listed item:", bool(chk[cols].all().all()))
print("LFP series whose stored starting_time is the movie start (within 0.01 s), so that by the Usage Notes",
      "the first sample is 10 s before the movie:",
      int(sum(abs(v["starting_time"] - bm.movie_window(s)[0]) < 0.01 for s in S for v in s["lfp"].values())),
      "of", sum(len(s["lfp"]) for s in S))
print("LFP series that, read that way, run past the last trial's stop time:",
      int((chk.lfp_end_after_last_trial >= 0).sum()), "of", len(chk), "files (seconds to spare, smallest per file:",
      chk.lfp_end_after_last_trial.min(), "to", chk.lfp_end_after_last_trial.max(), ")")
          units  micro_1kHz  macro_1kHz  lfp_start_file  lfp_end_after_last_trial  trials  locations  pairwise  gaze  frames  movie_start  movie_start_ok
session                                                                                                                                                  
P41CS_R1   True        True        True          0.0000                       1.5    True       True      True  True    True          0.0            True
P41CS_R2   True        True        True          0.0000                       1.4    True       True      True  True    True          0.0            True
P42CS_R1   True        True        True          0.0001                       1.2    True       True      True  True    True          0.0            True
P42CS_R2   True        True        True          0.0001                       1.2    True       True      True  True    True          0.0            True
P43CS_R1   True        True        True          0.0008                       1.1    True       True      True  True    True          0.0            True
P43CS_R2   True        True        True          0.0001                       1.0    True       True      True  True    True          0.0            True
P44CS_R1   True        True        True          0.0006                       1.1    True       True      True  True    True          0.0            True
P47CS_R1   True        True        True          0.0001                       1.1    True       True      True  True    True          0.0            True
P47CS_R2   True        True        True          0.0002                       1.8    True       True      True  True    True          0.0            True
P48CS_R1   True        True        True          0.0004                       1.2    True       True      True  True    True          0.0            True
P48CS_R2   True        True        True          0.0003                       1.1    True       True      True  True    True          0.0            True
P49CS_R1   True        True        True          0.0007                       1.1    True       True      True  True    True          0.0            True
P49CS_R2   True        True        True          0.0005                       2.4    True       True      True  True    True          0.0            True
P51CS_R1   True        True        True          0.0005                       1.1    True       True      True  True    True          0.0            True
P51CS_R2   True        True        True          0.0001                       1.2    True       True      True  True    True          0.0            True
P53CS_R1   True        True        True          0.0005                       1.2    True       True      True  True    True          0.0            True
P53CS_R2   True        True        True          0.0001                       4.8    True       True      True  True    True          0.0            True
P54CS_R1   True        True        True          0.0001                       1.1    True       True      True  True    True          0.0            True
P54CS_R2   True        True        True          0.0004                       1.1    True       True      True  True    True          0.0            True
P55CS_R1   True        True        True          0.0000                       1.1    True       True      True  True    True          0.0            True
P55CS_R2   True        True        True          0.0001                       1.1    True       True      True  True    True          0.0            True
P56CS_R1   True        True        True          0.0001                      11.0    True       True      True  True    True          0.0            True
P56CS_R2   True        True        True          0.0001                       1.1    True       True      True  True    True          0.0            True
P57CS_R1   True        True        True          0.0002                       1.0    True       True      True  True    True          0.0            True
P57CS_R2   True        True        True          0.0004                       1.1    True       True      True  True    True          0.0            True
P58CS_R1   True        True        True          0.0001                       1.1    True       True      True  True    True          0.0            True
P60CS_R1   True        True        True          0.0005                       1.0    True       True      True  True    True          0.0            True
P62CS_R1   True        True        True          0.0000                       1.1    True       True      True  True    True          0.0            True
P62CS_R2   True        True        True          0.0004                       1.1    True       True      True  True    True          0.0            True

all files pass every listed item: True
LFP series whose stored starting_time is the movie start (within 0.01 s), so that by the Usage Notes the first sample is 10 s before the movie: 58 of 58
LFP series that, read that way, run past the last trial's stop time: 29 of 29 files (seconds to spare, smallest per file: 1.0 to 11.0 )

Result: reproduced. Every file has units with spike times, electrode ids and the four quality metrics, LFP_micro and LFP_macro at 1000 Hz, the trials table, electrode locations, pairwise distances, gaze and 11971 frame times, and the movie starts at 0 s in all 29. All 58 LFP series store a starting time at the movie start, which, read as the Usage Notes say ("start at 10 seconds before the starting time"), puts the first sample 10 s before the movie, and every file's LFP then runs past the last trial (by 1.0 to 11.0 s). The image-onset check supports that reading: with the 10-s offset 650 of 2192 micro and 683 of 2240 macro channels respond to recognition images (30%), without it 18 and 20 (under 1%). Finer, the count stays high for offsets of 9.9 to 10.25 s, and with the 10-s offset the HFB response rises at 200 ms (macro) and 350 ms (micro) after the image, against 300 ms for the spikes, which are on the trials' clock; the largest value before onset is 9% of the peak (micro), 7% (macro) and 10% (units). These checks do not pin the offset to a single bin: the counts keep rising up to 10.25 s (micro 650, 693, 695 and macro 683, 715, 724 at 10.0, 10.1 and 10.25 s), and shifting the onsets also moves the analysis window against the response, so the sweep bounds the offset only to roughly 9.9 to 10.25 s; the macro HFB rising 100 ms before the spikes is consistent with a residual offset of about 100 ms but does not show one below it. The claim needs only 10 s against 0 s, which the checks settle. The stored starting time is not the time of the first sample, as the NWB format defines starting_time, so a reader who does not apply the Usage Notes' offset reads the LFP 10 s off.

memory-lfp and memory-ieeg¶

For microwire LFP HFB power, significant proportions of channels were memory selective in the amygdala (37/368, p = 0.002), ACC (33/368, p = 0.028) and preSMA (40/368, p = 0.001), but not in the hippocampus (17/368, p = 0.90) or vmPFC (28/336, p = 0.05).

For macroelectrode iEEG HFB power, significant proportions of channels were memory selective in the ACC (41/368, p < 0.001), vmPFC (34/368, p = 0.012) and preSMA (45/368, p < 0.001), but not in the amygdala (25/368, p = 0.47) or hippocampus (32/368, p = 0.067).

Sessions by rule R (the five sessions of reading (a) of memory-sessions-included; the readings remove the same five sessions, reproduce_keles_2024.ipynb). Mean HFB in 0.2 to 1.7 s after each trial's start_time; correct trials; bootstrap B (novel against familiar, balanced, seed 13); permutation test P with 2,000 shuffles.

In [8]:
mem_sessions = {s["identifier"] for s in S if bm.rule_R(s)[0]}
print("sessions in the memory analyses:", len(mem_sessions), "; removed:", sorted(set(ids) - mem_sessions))
paper_mem = {
    "LFP_micro": pd.DataFrame({"area": bm.AREAS, "paper_selective": [37, 17, 33, 40, 28],
                               "paper_n": [368, 368, 368, 368, 336], "paper_p": [0.002, 0.90, 0.028, 0.001, 0.05]}),
    "LFP_macro": pd.DataFrame({"area": bm.AREAS, "paper_selective": [25, 32, 41, 45, 34],
                               "paper_n": [368] * 5, "paper_p": [0.47, 0.067, 0.001, 0.001, 0.012]}),
}
res_mem = {}
for k, et in enumerate(["LFP_micro", "LFP_macro"]):
    bl, tb = chan_table(et, "memory", mem_sessions)
    res_mem[et] = bm.selection_and_null(bl, tb, balanced=True, positive_only=False, seed=0)
sessions in the memory analyses: 24 ; removed: ['P44CS_R1', 'P51CS_R2', 'P56CS_R2', 'P57CS_R1', 'P57CS_R2']
In [9]:
t, sm = res_mem["LFP_micro"]
print(sm.merge(paper_mem["LFP_micro"]).round(4).to_string())
print("channels outside the five areas:", int((~t.area.isin(bm.AREAS)).sum()))
print("selective channels with novel > familiar:", int((t.selective & (t["diff"] > 0)).sum()), "of", int(t.selective.sum()))
print("by participant:")
print(t.assign(p=t.session.str[:5]).groupby("p").agg(sel=("selective", "sum"), n=("selective", "size")).T.to_string())
          area    n  selective  p_perm  null_mean  null_95th   mc_se  paper_selective  paper_n  paper_p
0     amygdala  368         37  0.0015    21.8600       30.0  0.0009               37      368    0.002
1  hippocampus  368         17  0.8961    22.3870       30.0  0.0068               17      368    0.900
2          ACC  368         32  0.0315    22.6470       31.0  0.0039               33      368    0.028
3       preSMA  368         40  0.0005    21.7985       29.0  0.0005               40      368    0.001
4        vmPFC  336         28  0.0645    20.5505       28.0  0.0055               28      336    0.050
channels outside the five areas: 0
selective channels with novel > familiar: 90 of 154
by participant:
p    P41CS  P42CS  P43CS  P47CS  P48CS  P49CS  P51CS  P53CS  P54CS  P55CS  P56CS  P58CS  P60CS  P62CS
sel      4     32     24     21      4      2     14     17      9      7      8      9      2      1
n      160    128    160    160    160    160     80    160    160    160     80     80     80     80

Result: reproduced. Amygdala 37/368 (permutation p = 0.0015), ACC 32/368 (p = 0.0315) and preSMA 40/368 (p = 0.0005) are below 0.05; hippocampus 17/368 (p = 0.896) and vmPFC 28/336 (p = 0.0645, Monte Carlo s.e. 0.0055) are not. Every count is within tolerance (four are exact) and the denominators are the paper's.

In [10]:
t, sm = res_mem["LFP_macro"]
print(sm.merge(paper_mem["LFP_macro"]).round(4).to_string())
print("channels outside the five areas:", int((~t.area.isin(bm.AREAS)).sum()))
print("selective channels with novel > familiar:", int((t.selective & (t["diff"] > 0)).sum()), "of", int(t.selective.sum()))
print("by participant:")
print(t.assign(p=t.session.str[:5]).groupby("p").agg(sel=("selective", "sum"), n=("selective", "size")).T.to_string())
          area    n  selective  p_perm  null_mean  null_95th   mc_se  paper_selective  paper_n  paper_p
0     amygdala  368         25  0.4678    24.2840       32.0  0.0112               25      368    0.470
1  hippocampus  368         31  0.0935    24.1455       32.0  0.0065               32      368    0.067
2          ACC  368         41  0.0005    23.1840       31.0  0.0005               41      368    0.001
3       preSMA  368         45  0.0005    22.5755       30.0  0.0005               45      368    0.001
4        vmPFC  368         34  0.0155    22.8440       31.0  0.0028               34      368    0.012
channels outside the five areas: 0
selective channels with novel > familiar: 112 of 176
by participant:
p    P41CS  P42CS  P43CS  P47CS  P48CS  P49CS  P51CS  P53CS  P54CS  P55CS  P56CS  P58CS  P60CS  P62CS
sel      5     12     22      4     22      7     17     11      6     29      0     16     19      6
n      160    160    160    160    160    160     80    160    160    160     80     80     80     80

Result: reproduced. ACC 41/368 (p = 0.0005), vmPFC 34/368 (p = 0.0155) and preSMA 45/368 (p = 0.0005) are below 0.05; amygdala 25/368 (p = 0.468) and hippocampus 31/368 (p = 0.0935) are not. The counts are the paper's except hippocampus (31 against 32), within tolerance.

event-lfp and event-ieeg¶

For microwire LFP HFB power, significant proportions of channels were event selective in all five areas; amygdala 20/448 (p = 0.005), hippocampus 40/448 (p < 0.001), ACC 33/448 (p < 0.001), vmPFC 15/400 (p = 0.015), preSMA 22/448 (p = 0.001).

For macroelectrode iEEG HFB power, significant proportions of channels were event selective in all five areas; amygdala 67/448, hippocampus 41/448, ACC 25/448, vmPFC 33/449 (all p < 0.001) and preSMA 21/448 (p = 0.002).

All 29 sessions; mean HFB in 0 to 1.0 s after each cut onset; bootstrap B (scene change against continuity cut, each group its own size, seed 13), counted when scene change is above continuity cut; permutation test P with the same rule.

In [11]:
paper_ev = {
    "LFP_micro": pd.DataFrame({"area": bm.AREAS, "paper_selective": [20, 40, 33, 22, 15],
                               "paper_n": [448, 448, 448, 448, 400], "paper_p": [0.005, 0.001, 0.001, 0.001, 0.015]}),
    "LFP_macro": pd.DataFrame({"area": bm.AREAS, "paper_selective": [67, 41, 25, 21, 33],
                               "paper_n": [448, 448, 448, 448, 449], "paper_p": [0.001, 0.001, 0.001, 0.002, 0.001]}),
}
res_ev = {}
for k, et in enumerate(["LFP_micro", "LFP_macro"]):
    bl, tb = chan_table(et, "events")
    res_ev[et] = bm.selection_and_null(bl, tb, balanced=False, positive_only=True, seed=0)
In [12]:
t, sm = res_ev["LFP_micro"]
print(sm.merge(paper_ev["LFP_micro"]).round(4).to_string())
print("variant, either direction:", {a: int(t.selective_any_direction[t.area == a].sum()) for a in bm.AREAS})
print("by participant:")
print(t.assign(p=t.session.str[:5]).groupby("p").agg(sel=("selective", "sum"), n=("selective", "size")).T.to_string())
          area    n  selective  p_perm  null_mean  null_95th   mc_se  paper_selective  paper_n  paper_p
0     amygdala  448         20  0.0035    10.2460       16.0  0.0013               20      448    0.005
1  hippocampus  448         40  0.0005    10.4995       16.0  0.0005               40      448    0.001
2          ACC  448         33  0.0005     9.3060       15.0  0.0005               33      448    0.001
3       preSMA  448         22  0.0020    10.3655       16.0  0.0010               22      448    0.001
4        vmPFC  400         15  0.0175     8.0615       13.0  0.0029               15      400    0.015
variant, either direction: {'amygdala': 46, 'hippocampus': 53, 'ACC': 77, 'preSMA': 63, 'vmPFC': 51}
by participant:
p    P41CS  P42CS  P43CS  P44CS  P47CS  P48CS  P49CS  P51CS  P53CS  P54CS  P55CS  P56CS  P57CS  P58CS  P60CS  P62CS
sel     13     15      9      4     13      7     13     24      4      1      4      7      6      8      1      1
n      160    128    160     64    160    160    160    160    160    160    160    160    160     80     80     80

Result: reproduced. All five areas are below 0.05 with the paper's counts: amygdala 20/448 (p = 0.0035), hippocampus 40/448 (p = 0.0005), ACC 33/448 (p = 0.0005), vmPFC 15/400 (p = 0.0175) and preSMA 22/448 (p = 0.0020). In either direction 46 to 77 channels per area are selective.

In [13]:
t, sm = res_ev["LFP_macro"]
print(sm.merge(paper_ev["LFP_macro"]).round(4).to_string())
print("variant, either direction:", {a: int(t.selective_any_direction[t.area == a].sum()) for a in bm.AREAS})
print("by participant:")
print(t.assign(p=t.session.str[:5]).groupby("p").agg(sel=("selective", "sum"), n=("selective", "size")).T.to_string())
          area    n  selective  p_perm  null_mean  null_95th   mc_se  paper_selective  paper_n  paper_p
0     amygdala  448         66  0.0005     8.6765       14.0  0.0005               67      448    0.001
1  hippocampus  448         41  0.0005     8.7155       14.0  0.0005               41      448    0.001
2          ACC  448         25  0.0005     9.4930       15.0  0.0005               25      448    0.001
3       preSMA  448         21  0.0005    10.0245       16.0  0.0005               21      448    0.002
4        vmPFC  448         33  0.0005     9.3315       15.0  0.0005               33      449    0.001
variant, either direction: {'amygdala': 79, 'hippocampus': 54, 'ACC': 44, 'preSMA': 41, 'vmPFC': 50}
by participant:
p    P41CS  P42CS  P43CS  P44CS  P47CS  P48CS  P49CS  P51CS  P53CS  P54CS  P55CS  P56CS  P57CS  P58CS  P60CS  P62CS
sel      1     24     19     24      1     14     15     32      0      2     13      5     10     15      0     11
n      160    160    160     80    160    160    160    160    160    160    160    160    160     80     80     80

Result: reproduced. All five areas are below 0.05: amygdala 66/448, hippocampus 41/448, ACC 25/448, vmPFC 33/448 and preSMA 21/448 (each p = 0.0005). The counts are the paper's but amygdala (66 against 67), within tolerance. The vmPFC denominator is 448, so the paper's 449 is a misprint.

memory-modalities-differ¶

The areas with memory selectivity differ by modality; the ACC is selective in all three (cells, LFP, iEEG), the hippocampus in none, and the amygdala in cells and LFP but not iEEG.

The single-cell result is computed again as in reproduce_keles_2024.ipynb (same seeds, so the same numbers).

In [14]:
blocks_m, table_m = bm.cell_blocks(S, "memory", sessions=mem_sessions)
cells_m, sum_m = bm.selection_and_null(blocks_m, table_m, balanced=True, positive_only=False, seed=0,
                                      rate_window=bm.MEMORY_WINDOW[1] - bm.MEMORY_WINDOW[0])
pt = pd.DataFrame({"cells": sum_m.set_index("area").p_perm,
                   "LFP": res_mem["LFP_micro"][1].set_index("area").p_perm,
                   "iEEG": res_mem["LFP_macro"][1].set_index("area").p_perm})
print(pt.round(4).to_string())
print()
print((pt < 0.05).to_string())
sig = pt < 0.05
print("\nACC in all three:", bool(sig.loc["ACC"].all()), "; hippocampus in none:", bool((~sig.loc["hippocampus"]).all()),
      "; amygdala in cells and LFP but not iEEG:", bool(sig.loc["amygdala", "cells"] and sig.loc["amygdala", "LFP"] and not sig.loc["amygdala", "iEEG"]))
              cells     LFP    iEEG
area                               
amygdala     0.0095  0.0015  0.4678
hippocampus  0.2824  0.8961  0.0935
ACC          0.0005  0.0315  0.0005
preSMA       0.1824  0.0005  0.0005
vmPFC        0.0220  0.0645  0.0155

             cells    LFP   iEEG
area                            
amygdala      True   True  False
hippocampus  False  False  False
ACC           True   True   True
preSMA       False   True   True
vmPFC         True  False   True

ACC in all three: True ; hippocampus in none: True ; amygdala in cells and LFP but not iEEG: True

Result: reproduced. At p < 0.05 the ACC is memory selective in cells (p = 0.0005), LFP (p = 0.0315) and iEEG (p = 0.0005); the hippocampus in none (0.282, 0.896, 0.0935); and the amygdala in cells (0.0095) and LFP (0.0015) but not iEEG (0.468).

fig6-examples¶

Example memory-selective units and channels; a preSMA neuron firing more to familiar images (p = 0.003), an ACC neuron firing more to novel images (p < 0.001), and a preSMA macro channel and an ACC microwire channel with higher HFB to novel images (both p < 0.001).

In [15]:
def find(t, prefix, col):
    m = t[t[col].str.startswith(prefix)]
    return m
ex = []
for pid in ["P53CS_R1_11_1_3077", "P58CS_R1_34_2_3239"]:
    m = find(cells_m, pid, "unit_id_session")
    for _, r in m.iterrows():
        ex.append(dict(example=r.unit_id_session, kind="cell", area=r.area, diff_novel_minus_familiar=r["diff"], p=r.p))
for et, cid in [("LFP_macro", "P42CS_R2_RSMA3"), ("LFP_micro", "P58CS_R1_RACC2")]:
    t = res_mem[et][0]
    m = t[(t.session + "_" + t.channel) == cid]
    for _, r in m.iterrows():
        ex.append(dict(example=cid, kind=et, area=r.area, diff_novel_minus_familiar=r["diff"], p=r.p))
print(pd.DataFrame(ex).to_string())
print("(cell differences in spikes/s; channel differences in z-scored HFB)")
                example       kind    area  diff_novel_minus_familiar       p
0  P53CS_R1_11_1_3077_8       cell  preSMA                  -3.130556  0.0030
1  P58CS_R1_34_2_3239_5       cell     ACC                   1.688889  0.0002
2        P42CS_R2_RSMA3  LFP_macro  preSMA                   0.158280  0.0002
3        P58CS_R1_RACC2  LFP_micro     ACC                   0.280458  0.0002
(cell differences in spikes/s; channel differences in z-scored HFB)

Result: reproduced. The preSMA cell P53CS_R1_11_1_3077 fires more to familiar images (-3.13 spikes/s, p = 0.0030); the ACC cell P58CS_R1_34_2_3239 fires more to novel images (1.69 spikes/s, p = 0.0002); the preSMA macro channel P42CS_R2_RSMA3 and the ACC micro channel P58CS_R1_RACC2 have higher HFB to novel images (p = 0.0002 each, the smallest p of 10,000 resamples).

fig7-examples¶

Example event-selective units and channels; a preSMA neuron (p = 0.024) and a vmPFC neuron (p = 0.030), a hippocampal macro channel (p = 0.026) and a preSMA microwire channel (p < 0.001), each responding differently to scene changes than to continuity cuts.

In [16]:
blocks_e, table_e = bm.cell_blocks(S, "event", cuts=cuts)
de, pe = [], []
for V, a, b in blocks_e:
    d, p = bm.observed_selection(V, a, b, False)
    de.append(d)
    pe.append(p)
table_e["diff"] = np.concatenate(de)
table_e["p"] = np.concatenate(pe)
ex = []
for pid in ["P42CS_R1_47_2_1347", "P47CS_R1_78_1_2233"]:
    for _, r in find(table_e, pid, "unit_id_session").iterrows():
        ex.append(dict(example=r.unit_id_session, kind="cell", area=r.area, diff_change_minus_cont=r["diff"], p=r.p))
for et, cid in [("LFP_macro", "P62CS_R2_RHIP6"), ("LFP_micro", "P51CS_R2_RSMA8")]:
    t = res_ev[et][0]
    for _, r in t[(t.session + "_" + t.channel) == cid].iterrows():
        ex.append(dict(example=cid, kind=et, area=r.area, diff_change_minus_cont=r["diff"], p=r.p))
print(pd.DataFrame(ex).to_string())
print("(cell differences in spikes/s; channel differences in z-scored HFB)")
print("notebook run time so far: %.1f min" % ((time.time() - t_start) / 60))
                 example       kind         area  diff_change_minus_cont         p
0   P42CS_R1_47_2_1347_7       cell       preSMA                4.959615  0.024398
1  P47CS_R1_78_1_2233_10       cell        vmPFC                3.706731  0.029797
2         P62CS_R2_RHIP6  LFP_macro  hippocampus                0.112271  0.025797
3         P51CS_R2_RSMA8  LFP_micro       preSMA                0.320164  0.000200
(cell differences in spikes/s; channel differences in z-scored HFB)
notebook run time so far: 37.1 min

Result: reproduced. The preSMA cell P42CS_R1_47_2_1347 (p = 0.0244) and the vmPFC cell P47CS_R1_78_1_2233 (p = 0.0298), the hippocampal macro channel P62CS_R2_RHIP6 (p = 0.0258) and the preSMA micro channel P51CS_R2_RSMA8 (p = 0.0002) all respond more to scene changes than to continuity cuts, with the legend's areas and p-values within tolerance.

Summary¶

Claim Outcome
nwb-contents reproduced; the LFP's stored starting time is the movie start, and the samples begin 10 s before it, as the Usage Notes say
memory-lfp reproduced
memory-ieeg reproduced
event-lfp reproduced
event-ieeg reproduced
memory-modalities-differ reproduced
fig6-examples reproduced
fig7-examples reproduced

How the analysis differs from the paper's. HFB is computed as prep_filterLFP.py does, but reduced at once to the window means each test uses, with no intermediate files; the line-noise power and the per-channel HFB statistics are printed as checks of the steps. The permutation tests are seeded (seed 0, open detail 8 of the claims file) and share each shuffle's bootstrap resamples among the channels of a session (see bmovie.py).

What was found about the dataset. The LFP series store a starting time at the movie start, while their samples begin 10 s before it. The Usage Notes say so and the paper's code applies the offset, but the NWB format defines starting_time as the time of the first sample, so a reader of the file alone is 10 s off; the image-onset check shows the offset is needed, and bounds it to roughly 9.9 to 10.25 s. The vmPFC macro denominator is 448, not the 449 the paper prints. Channel areas come only from the channel names (characters 2 to 4 of origchannel_name), as the code reads them.