Reproducing Kim & Shin (2025) on its main dataset: Allen Visual Coding Neuropixels natural scenes¶

Paper: Kim, J. H. & Shin, H. (2025), bioRxiv doi:10.1101/2025.06.30.662469 (July 2025 preprint, the text the claims file was written from).

The registry tests this paper on dandiset 000248, which the paper uses only for pictures (first notebook). Its findings rest on the Allen Brain Observatory Visual Coding Neuropixels data, "Brain Observatory 1.1" sessions, which the paper reads through AllenSDK without naming a release. These claims are data: elsewhere. Here they are tested on the same sessions as deposited on DANDI: dandiset 000021, "Allen Institute - Visual Coding - Neuropixels (Brain Observatory 1.1 Stimulus Set)", version 0.251116.2246 (doi:10.48324/dandi.000021/0.251116.2246), the only published version, streamed from the archive. The 32 session files it holds match the paper's 32 Brain Observatory 1.1 sessions in number.

Units: those whose peak channel lies in the area (VISp for V1; VISl, VISrl, VISal, VISpm, VISam for LM, RL, AL, PM, AM), that pass the Allen quality criteria of the Methods (isi_violations < 0.5, amplitude_cutoff < 0.1, presence_ratio > 0.9) and whose quality label is "good". The label is an assumption: the Methods name only the three criteria, but the paper read the data through AllenSDK, whose default units table also keeps only units labelled "good" (filter_by_validity, allensdk/brain_observatory/ecephys/probes.py, lines 128 to 129, at commit a56bd8ea7613a812334602b64746cdd30c325a96), and the paper's unit counts match only with it. It is applied in every analysis; the Methods' three criteria alone are shown as a variant for the unit counts, the slope fits, behavioural state, higher visual areas and the movie data. The measures under slope manipulation were run with the Methods' criteria alone in the first round of this attempt and are not repeated here, for lack of time. Counts are spikes in the 250 ms from each natural scenes onset (Methods). Sessions with more than 10% of trials silent in all V1 units are excluded (Methods).

Claim Tested here
data-v1-units, fig1b-across-neuron-slope-near-1, fig1b-across-stimulus-slope, figs3-higher-visual-areas yes
figs4ab-noise-correlation-under-manipulation, fig1d-dimensionality-falls-with-slope, figs5c-space-occupancy-peak yes
fig2a-overlap-rises-with-slope, fig2c-continuity-from-slope-1 yes
fig3bc-geodesic-orthogonal-correlation, fig3d-correlation-peaks-near-1, fig3e-local-alignment-peaks-near-1, fig3f-global-alignment-peaks-near-1 yes
fig4a-overlap-consistency-within-mice, fig4c-rsm-similarity-within-mice, fig4d-overlap-consistency-across-mice, fig4e-rsm-similarity-across-mice, figs6-higher-areas-consistency yes
figs2-behavioral-state yes (pupil in the sessions with eye tracking)
figs5a-movie-slope-near-1 yes, on the Functional Connectivity sessions of dandiset 000022
fig2b-decoding-falls-with-slope, figs4c-shuffling-alters-dependence in the third notebook, reproduce_kim_2025_decoding.ipynb (decoding at as-is and slopes 0 and 1 over the 30 sessions, and at slope 2 in four sessions)
figs1-gain-variance, fig2d-tangent-angle-rises-below-1 blocked: the paper's procedures (negative binomial fits; tangent space angle) were not ported within the time of this attempt's runs; the data they need are loaded here

Seeds: each random result uses the seed of its claim, zlib.crc32(b"kim-2025/<claim id>"), and the RSM-based results are repeated under the seed plus 1000, 2000, 3000 and 4000.

In [1]:
import os
os.environ["OMP_NUM_THREADS"] = "1"
os.environ["OPENBLAS_NUM_THREADS"] = "1"
os.environ["MKL_NUM_THREADS"] = "1"
import time, zlib, itertools, resource
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from concurrent.futures import ProcessPoolExecutor
import multiprocessing as mp
from scipy.stats import mannwhitneyu, kruskal, spearmanr

import kim2025 as K

def wilcoxon(x, y=None, **kw):
    """scipy's Wilcoxon signed-rank test, with p = 1 when every difference is zero."""
    from scipy.stats import wilcoxon as _w
    d = np.asarray(x) - (0 if y is None else np.asarray(y))
    if np.all(d == 0):
        return type("R", (), {"pvalue": 1.0, "statistic": 0.0})()
    return _w(x, y, **kw) if y is not None else _w(x, **kw)

T0 = time.time()
pd.set_option("display.width", 220)
SLOPES = [float(s) for s in K.TARGET_SLOPES]
def seed(claim):
    return zlib.crc32(f"kim-2025/{claim}".encode())
paths = [p for p in K.asset_paths(K.ABO_ID, K.ABO_VERSION) if "probe" not in p]
print(f"dandiset {K.ABO_ID} version {K.ABO_VERSION}: {len(paths)} session files")
dandiset 000021 version 0.251116.2246: 32 session files

Data check¶

In [2]:
with ProcessPoolExecutor(4, mp_context=mp.get_context("fork")) as ex:
    SQ = list(ex.map(K.abo_session, paths))     # units by the Methods' three criteria
S = [K.restrict(s, s["good"]) for s in SQ]      # main reading: also labelled "good", as AllenSDK serves them
print(f"loaded in {(time.time() - T0) / 60:.1f} min; peak memory {resource.getrusage(resource.RUSAGE_SELF).ru_maxrss / 1e6:.2f} GB")
rows = []
for i, (s, sq) in enumerate(zip(S, SQ)):
    v1 = s["area"] == "V1"
    lab = s["labels"]
    _, n = np.unique(lab, return_counts=True)
    rows.append(dict(index=i, session=s["info"]["path"].split("/")[0], trials=s["info"]["trials"], stimuli=len(n),
                     repeats_min=n.min(), repeats_max=n.max(),
                     **{f"{a}_q": int((sq["area"] == a).sum()) for a in K.ABO_AREAS},
                     **{f"{a}_g": int((s["area"] == a).sum()) for a in K.ABO_AREAS},
                     V1_all=s["info"]["area_units_all"]["V1"],
                     silent_V1=round(K.silent_fraction(s["X"][:, v1]), 4),
                     silent_V1_q=round(K.silent_fraction(sq["X"][:, sq["area"] == "V1"]), 4),
                     speed_mean=round(float(np.nanmean(s["speed"])), 2), eye=s["info"]["eye_tracking"]))
tab = pd.DataFrame(rows).set_index("index")
tab["included"] = tab.silent_V1 <= K.SILENT_TRIAL_LIMIT
print("columns: <area>_q units by the Methods' three criteria, <area>_g also labelled good (main); silent_V1 with the good units, silent_V1_q with the Methods units")
print(tab.to_string())
print("frame codes:", np.unique(S[1]["labels"])[[0, 1, -1]], "(-1 is the gray image)")
print("running speed unit:", {s["info"]["running_unit"] for s in S}, "; trial-mean speed range",
      f"{min(np.nanmin(s['speed']) for s in S):.1f} to {max(np.nanmax(s['speed']) for s in S):.1f}")
allc = np.concatenate([s["X"].ravel() for s in S])
print(f"spike counts per 250 ms: min {allc.min():.0f}, max {allc.max():.0f}, mean {allc.mean():.3f}")
keep = [i for i in tab.index if tab.loc[i, "included"]]
print("excluded sessions:", [i for i in tab.index if i not in keep], "; included:", len(keep),
      "; the same under the Methods units:", list(tab.index[tab.silent_V1_q <= K.SILENT_TRIAL_LIMIT]) == keep)
ses_id = {i: int(S[i]["info"]["path"].split("_ses-")[1].split(".")[0]) for i in tab.index}
by_id = sorted(tab.index, key=ses_id.get)
print("excluded sessions by position in ascending session id (AllenSDK's order, 0-based):", {i: by_id.index(i) for i in tab.index if i not in keep})
print("duplicate check: distinct V1 count vectors", len({tuple(S[i]["X"][:, S[i]["area"] == "V1"].sum(0)) for i in tab.index}), "of", len(S))
loaded in 2.5 min; peak memory 1.16 GB
columns: <area>_q units by the Methods' three criteria, <area>_g also labelled good (main); silent_V1 with the good units, silent_V1_q with the Methods units
             session  trials  stimuli  repeats_min  repeats_max  V1_q  LM_q  RL_q  AL_q  PM_q  AM_q  V1_g  LM_g  RL_g  AL_g  PM_g  AM_g  V1_all  silent_V1  silent_V1_q  speed_mean    eye  included
index                                                                                                                                                                                               
0      sub-699733573    5950      119           50           50    62    50    85     0    53    34    62    47    77     0    51    31     160     0.1215       0.1215        6.99  False     False
1      sub-703279277    5950      119           50           50    56    42    18    10    21    40    52    41    15     9    18    40     134     0.0000       0.0000       11.37  False      True
2      sub-707296975    5950      119           50           50    42    30    50    38     0    41    42    27    46    37     0    41     133     0.0000       0.0000       13.25  False      True
3      sub-716813540    5950      119           50           50    19    37    73     0     0    60    19    37    71     0     0    58      67     0.0000       0.0000        3.80  False      True
4      sub-717038285    5950      119           50           50   113    40    66    89    68     0   112    40    65    89    68     0     259     0.0000       0.0000       19.49  False      True
5      sub-718643564    5950      119           50           50    45    25    72     0    15     0    45    23    70     0    15     0     136     0.0000       0.0000       20.58  False      True
6      sub-719817799    5950      119           50           50    39    33    32    43     0     0    38    31    28    41     0     0     126     0.0000       0.0000        0.75   True      True
7      sub-719828686    5950      119           50           50   112    14    48    34    25    67   106    14    44    33    25    65     233     0.0000       0.0000        3.14   True      True
8      sub-722882751    5950      119           50           50    59    20    76     0     0    58    47    19    73     0     0    55     157     0.0000       0.0000        1.10   True      True
9      sub-723627600    5950      119           50           50    35    54    83    49    23     0    34    52    80    46    23     0     158     0.1800       0.1800        0.76   True     False
10     sub-726141242    5950      119           50           50    70    41    52    74    23    65    67    39    50    73    19    62     192     0.0000       0.0000        3.10   True      True
11     sub-726162193    5950      119           50           50    60    25    49    50    69    70    59    23    47    47    67    67     177     0.0000       0.0000        7.39   True      True
12     sub-726170927    5950      119           50           50    14    26    42    38   121     0    14    23    40    34   116     0      72     0.0000       0.0000        8.71   True      True
13     sub-726298249    5950      119           50           50    99     0    34     0    22    48    93     0    32     0    21    48     243     0.0000       0.0000        2.27   True      True
14     sub-730756767    5950      119           50           50    92     0    57    64     0    78    87     0    54    62     0    73     238     0.0000       0.0000        0.48   True      True
15     sub-730760263    5950      119           50           50    88    47    55    43    69    99    82    41    52    42    66    96     230     0.0000       0.0000       16.61   True      True
16     sub-732548371    5950      119           50           50    53    30   107     0    38    74    50    30    98     0    38    73     149     0.0000       0.0000        1.25   True      True
17     sub-733457986    5950      119           50           50    91    54    40    57     0    69    87    53    37    53     0    67     261     0.0000       0.0000        7.17   True      True
18     sub-734865729    5950      119           50           50    55    34    24    54    95    80    52    34    24    53    93    77     167     0.0000       0.0000       21.54   True      True
19     sub-735109599    5950      119           50           50    47     0     0    84    25    53    47     0     0    82    23    51     184     0.0000       0.0000       35.57   True      True
20     sub-738651046    5950      119           50           50    98     0    67   135    56    73    91     0    66   129    55    71     217     0.0000       0.0000       40.32   True      True
21     sub-739783158    5950      119           50           50    84    56     0    59    46    57    76    51     0    57    45    55     200     0.0000       0.0000       48.79   True      True
22     sub-740268983    5950      119           50           50    75     0     0    49    57    60    67     0     0    46    56    58     237     0.0000       0.0000       19.93   True      True
23     sub-742602884    5950      119           50           50    79    36    48     0     0    81    74    36    45     0     0    77     175     0.0000       0.0000        1.91   True      True
24     sub-742714472    5950      119           50           50    43     0   119   198    44     0    38     0   114   188    41     0     113     0.0000       0.0000       52.12   True      True
25     sub-744915196    5950      119           50           50    86     0    68     0     0    55    80     0    65     0     0    53     219     0.0000       0.0000       46.59   True      True
26     sub-745276220    5950      119           50           50    92    81     0    99     0    33    88    77     0    93     0    33     234     0.0000       0.0000       21.39   True      True
27     sub-757329617    5950      119           50           50    44     0    42   183     0    20    41     0    40   177     0    19     178     0.0000       0.0000        1.66   True      True
28     sub-769360771    5950      119           50           50   106    59    66    46    24    54    97    57    59    46    22    50     241     0.0000       0.0000       10.02   True      True
29     sub-772616820    5950      119           50           50    80    44    31    56     0    32    75    40    29    53     0    30     185     0.0000       0.0000        1.51   True      True
30     sub-775876808    5950      119           50           50   100    78    52    98     0   149    95    78    48    92     0   139     235     0.0000       0.0000       18.37   True      True
31     sub-776061236    5950      119           50           50    92    60    11    25    56    74    87    58    11    25    55    70     239     0.0000       0.0000        2.51   True      True
frame codes: [ -1   0 117] (-1 is the gray image)
running speed unit: {'cm/s'} ; trial-mean speed range -30.7 to 131.5
spike counts per 250 ms: min 0, max 146, mean 1.802
excluded sessions: [0, 9] ; included: 30 ; the same under the Methods units: True
excluded sessions by position in ascending session id (AllenSDK's order, 0-based): {0: 0, 9: 6}
duplicate check: distinct V1 count vectors 32 of 32

Clock check: the image identity is decoded from V1 counts in the 250 ms after onset and in a window shifted 2 s later (several presentations later in the random sequence), in one session.

In [3]:
from sklearn.discriminant_analysis import LinearDiscriminantAnalysis
from sklearn.model_selection import StratifiedKFold, cross_val_score
i0 = keep[0]
f = K.open_nwb(S[i0]["info"]["path"], K.ABO_ID, K.ABO_VERSION)
u = K.units_table(f)
rows_v1 = np.where((u.location == "VISp").to_numpy() & u.passes_quality.to_numpy())[0]
g = f["intervals/natural_scenes_presentations"]
fr, on = g["frame"][:].astype(int), g["start_time"][:]
for shift in (0.0, 2.0):
    C = K.spike_counts(f, rows_v1, on + shift, 0.25)
    acc = cross_val_score(LinearDiscriminantAnalysis(), C, fr, cv=StratifiedKFold(5, shuffle=False)).mean()
    print(f"session {i0}, window shifted {shift:+.1f} s: 119-way accuracy {acc:.3f} (chance {1/119:.4f})")
f.close()
session 1, window shifted +0.0 s: 119-way accuracy 0.442 (chance 0.0084)
session 1, window shifted +2.0 s: 119-way accuracy 0.009 (chance 0.0084)

data-v1-units¶

The main analysis uses V1 units from 30 sessions of 30 mice, 64 +- 25 units per session (14 to 110), 1920 units in all, with 119 stimuli per session (3570 stimulus fits).

In [4]:
for label, SS in (("main: Methods criteria and the label 'good'", S), ("variant: Methods criteria alone", SQ)):
    nv1 = pd.Series({i: int((SS[i]["area"] == "V1").sum()) for i in keep})
    print(f"{label}: sessions {len(keep)} (of {len(SS)}); V1 units per session mean {nv1.mean():.1f}, SD {nv1.std(ddof=1):.1f} "
          f"(ddof 1; ddof 0 {nv1.std(ddof=0):.1f}), range {nv1.min()} to {nv1.max()}, total {nv1.sum()}")
print(f"stimuli per session {set(tab.loc[keep, 'stimuli'])}; fits {119 * len(keep)}")
print("mice: one session per subject folder,", tab.loc[keep, "session"].nunique(), "distinct subjects")
main: Methods criteria and the label 'good': sessions 30 (of 32); V1 units per session mean 66.9, SD 25.5 (ddof 1; ddof 0 25.1), range 14 to 112, total 2008
variant: Methods criteria alone: sessions 30 (of 32); V1 units per session mean 71.1, SD 27.1 (ddof 1; ddof 0 26.6), range 14 to 113, total 2133
stimuli per session {119}; fits 3570
mice: one session per subject folder, 30 distinct subjects

AllenSDK, through which the paper read these data, keeps only units whose quality label is "good" in its default units table (filter_by_validity=True; allensdk/brain_observatory/ecephys/probes.py, lines 128 to 129, at commit a56bd8ea7613a812334602b64746cdd30c325a96), on top of the three criteria the Methods name. The NWB files hold all units with the label. This reading is the main one in every analysis of this notebook; the Methods' criteria alone are a variant.

Result: data-v1-units reproduced, resting on the AllenSDK reading of the unit selection. Two of 32 sessions have more than 10% of trials silent in all V1 units (indices 0 and 9 here, the first and seventh by session id, which is how AllenSDK orders them, as the data check prints; the code drops indices 0 and 6), under either unit reading, leaving 30 sessions of 30 mice, each with 119 stimuli (3570 fits). With the label "good" there are 66.9 +- 25.5 V1 units per session (14 to 112), 2008 in all, every value within tolerance. With the Methods' three criteria alone, 71.1 +- 27.1 (14 to 113), 2133 in all: the mean and the total are outside their tolerances (57.6 to 70.4; 1728 to 2112).

fig1b-across-neuron-slope-near-1 and fig1b-across-stimulus-slope¶

In [5]:
fits = {i: K.fit_slopes(S[i]["X"][:, S[i]["area"] == "V1"], S[i]["labels"]) for i in keep}
an = pd.concat([fits[i].assign(session=i) for i in keep])
print(f"across-neuron slopes (main, good units): n {len(an)}, mean {an.slope.mean():.4f}, SEM {an.slope.sem():.4f}, SD {an.slope.std(ddof=1):.4f}, "
      f"median {an.slope.median():.4f}, range {an.slope.min():.3f} to {an.slope.max():.3f}")
print("per-session mean slope range:", round(an.groupby('session').slope.mean().min(), 3), "to", round(an.groupby('session').slope.mean().max(), 3))
print("neurons per fit (mean > 0): median", an.n.median(), ", min", an.n.min())
an_q = pd.concat([K.fit_slopes(SQ[i]["X"][:, SQ[i]["area"] == "V1"], SQ[i]["labels"]) for i in keep])
print(f"variant, Methods criteria alone: n {len(an_q)}, mean {an_q.slope.mean():.4f}, SEM {an_q.slope.sem():.4f}, SD {an_q.slope.std(ddof=1):.4f}")
across-neuron slopes (main, good units): n 3570, mean 1.0489, SEM 0.0011, SD 0.0665, median 1.0516, range 0.605 to 1.381
per-session mean slope range: 0.942 to 1.155
neurons per fit (mean > 0): median 69.5 , min 13
variant, Methods criteria alone: n 3570, mean 1.0552, SEM 0.0011, SD 0.0655

Result: fig1b-across-neuron-slope-near-1 reproduced, resting on the AllenSDK reading of the unit selection. With the good units the 3570 across-neuron slopes have mean 1.0489 (SEM 0.0011) and SD 0.0665, within 1.048 +- 0.001 and 0.07 +- 0.007; they lie between 0.605 and 1.381. With the Methods' three criteria alone the mean is 1.0552 (SEM 0.0011), outside the tolerance, and the SD 0.0655 within it.

In [6]:
ast = np.concatenate([K.across_stimulus_slopes(S[i]["X"][:, S[i]["area"] == "V1"], S[i]["labels"]) for i in keep])
dropped = int(np.isnan(ast).sum()); ast = ast[~np.isnan(ast)]
mw = mannwhitneyu(ast, an.slope, alternative="two-sided")
print(f"across-stimulus slopes: n {len(ast)} ({dropped} neurons without 2 stimuli of nonzero mean dropped), mean {ast.mean():.4f}, SD {ast.std(ddof=1):.4f}, median {np.median(ast):.4f}")
print(f"across-neuron: mean {an.slope.mean():.4f}, median {an.slope.median():.4f}; rank-sum (Mann-Whitney U, two-sided) U = {mw.statistic:.0f}, p = {mw.pvalue:.3g}")
ast_q = np.concatenate([K.across_stimulus_slopes(SQ[i]["X"][:, SQ[i]["area"] == "V1"], SQ[i]["labels"]) for i in keep])
ast_q = ast_q[~np.isnan(ast_q)]
print(f"variant, Methods criteria alone: across-stimulus n {len(ast_q)}, mean {ast_q.mean():.4f}, SD {ast_q.std(ddof=1):.4f}, median {np.median(ast_q):.4f}; "
      f"across-neuron mean {an_q.slope.mean():.4f}, median {an_q.slope.median():.4f}; Mann-Whitney p = {mannwhitneyu(ast_q, an_q.slope).pvalue:.3g}")
fig, ax = plt.subplots(figsize=(5, 3))
ax.hist(an.slope, bins=np.linspace(0, 3, 61), alpha=0.6, density=True, label="across neurons")
ax.hist(ast, bins=np.linspace(0, 3, 61), alpha=0.6, density=True, label="across stimuli"); ax.legend(); ax.set_xlabel("slope")
print("points outside 0 to 3:", int((an.slope < 0).sum() + (an.slope > 3).sum()), "across-neuron,", int((ast < 0).sum() + (ast > 3).sum()), "across-stimulus")
plt.show()
across-stimulus slopes: n 2008 (0 neurons without 2 stimuli of nonzero mean dropped), mean 1.1351, SD 0.2073, median 1.1507
across-neuron: mean 1.0489, median 1.0516; rank-sum (Mann-Whitney U, two-sided) U = 4911106, p = 6.87e-117
variant, Methods criteria alone: across-stimulus n 2133, mean 1.1344, SD 0.2057, median 1.1485; across-neuron mean 1.0552, median 1.0583; Mann-Whitney p = 5.12e-105
points outside 0 to 3: 0 across-neuron, 2 across-stimulus
No description has been provided for this image

Result: fig1b-across-stimulus-slope reproduced. The 2008 across-stimulus slopes of the good units have mean 1.135 and SD 0.207 (expected 1.13 +- 0.21 and 0.21 +- 0.021), larger than the across-neuron slopes in mean (1.135 against 1.049) and median (1.151 against 1.052), two-sided rank-sum p = 7e-117. With the Methods' criteria alone (2133 units), mean 1.134 and SD 0.206, also larger in mean and median, p = 5e-105.

figs2-behavioral-state¶

The across-neuron slope is slightly but significantly modulated by behavioral state, smallest when the mouse runs and when its pupils are dilated, while staying near 1.

Locomotion: trial mean running speed >= 1 cm/s is moving; M1 per session, stimulus and state, pooled; stimulus and state cells with fewer than 2 trials cannot give a variance and are dropped. Pupil: trial mean of the blink-filtered pupil area (processing/filtered_gaze_mapping/pupil_area), present in the sessions marked eye in the data check; tertiles over the trials of all sessions pooled (code, fit_slope_histogram.ipynb cell 67), per-session tertiles as a variant; Kruskal-Wallis across the three groups of slopes.

In [7]:
def state_slope(X, m):
    Y = X[m]; mu, v = Y.mean(0), Y.var(0, ddof=1); ok = (mu > 0) & (v > 0)
    return np.polyfit(np.log10(mu[ok]), np.log10(v[ok]), 1)[0] if ok.sum() >= 2 else None

pup = {i: K.abo_pupil(S[i]["info"]["path"], K.abo_onsets(S[i]["info"]["path"])) for i in keep}
pup = {i: v for i, v in pup.items() if v is not None}
allp = np.concatenate([v for v in pup.values()])
edges = np.nanpercentile(allp, [100 / 3, 200 / 3])
print(f"pupil: {len(pup)} included sessions with eye tracking; trials without a pupil value {np.isnan(allp).mean():.3f}; "
      f"pooled tertile edges {edges[0]:.4f} and {edges[1]:.4f}; range {np.nanmin(allp):.4g} to {np.nanmax(allp):.4g} (labelled pixels^2)")
print("fraction of trials moving (trial mean speed >= 1 cm/s):", round(float(np.mean(np.concatenate([S[i]["speed"] >= 1 for i in keep]))), 3))

for reading, SS in (("main, good units", S), ("variant, Methods criteria alone", SQ)):
    print(f"=== {reading}")
    st_rows = []
    for i in keep:
        X, lab, sp = SS[i]["X"][:, SS[i]["area"] == "V1"], SS[i]["labels"], SS[i]["speed"]
        for state, sel in (("moving", sp >= 1), ("stationary", sp < 1)):
            for c in np.unique(lab):
                m = (lab == c) & sel
                if m.sum() >= 2 and (b := state_slope(X, m)) is not None:
                    st_rows.append((i, state, c, b, m.sum()))
    bs = pd.DataFrame(st_rows, columns=["session", "state", "stim", "slope", "trials"])
    print(bs.groupby("state").slope.describe().round(4).to_string())
    mv, stn = bs[bs.state == "moving"].slope, bs[bs.state == "stationary"].slope
    print(f"moving vs stationary: medians {mv.median():.4f} vs {stn.median():.4f}; Mann-Whitney two-sided p = {mannwhitneyu(mv, stn).pvalue:.3g}; "
          f"sessions with moving fits {bs[bs.state == 'moving'].session.nunique()}")
    for label, per_session in (("pooled tertiles (code)", False), ("per-session tertiles (variant)", True)):
        pr = []
        for i, pv in pup.items():
            X, lab = SS[i]["X"][:, SS[i]["area"] == "V1"], SS[i]["labels"]
            e = np.nanpercentile(pv, [100 / 3, 200 / 3]) if per_session else edges
            tert = np.where(np.isnan(pv), -1, np.digitize(pv, e))
            for t_ in range(3):
                for c in np.unique(lab):
                    m = (lab == c) & (tert == t_)
                    if m.sum() >= 2 and (b := state_slope(X, m)) is not None:
                        pr.append((i, t_, b))
        pdf = pd.DataFrame(pr, columns=["session", "tertile", "slope"])
        meds = pdf.groupby("tertile").slope.median()
        kw = kruskal(*[pdf[pdf.tertile == t_].slope for t_ in range(3)])
        print(f"{label}: fits per tertile {pdf.groupby('tertile').size().to_dict()}, median slope per tertile {meds.round(4).to_dict()}, "
              f"largest tertile lowest: {bool(meds.idxmin() == 2)}, Kruskal-Wallis p = {kw.pvalue:.3g}, medians in 0.9-1.1: {bool(meds.between(0.9, 1.1).all())}")
    print("per-session median slope, moving minus stationary:",
          (bs.groupby(["session", "state"]).slope.median().unstack().dropna().pipe(lambda d: d.moving - d.stationary)).describe().round(4).to_dict())
pupil: 25 included sessions with eye tracking; trials without a pupil value 0.105; pooled tertile edges 0.0016 and 0.0026; range 0.000188 to 0.01165 (labelled pixels^2)
fraction of trials moving (trial mean speed >= 1 cm/s): 0.446
=== main, good units
             count    mean     std     min     25%     50%     75%     max
state                                                                     
moving      3550.0  0.9883  0.0865  0.3053  0.9481  0.9909  1.0347  1.4673
stationary  3264.0  1.0589  0.0789  0.3984  1.0189  1.0612  1.1061  1.5210
moving vs stationary: medians 0.9909 vs 1.0612; Mann-Whitney two-sided p = 2.35e-307; sessions with moving fits 30
pooled tertiles (code): fits per tertile {0: 2228, 1: 2521, 2: 2116}, median slope per tertile {0: 1.0696, 1: 1.0459, 2: 1.029}, largest tertile lowest: True, Kruskal-Wallis p = 9.92e-49, medians in 0.9-1.1: True
per-session tertiles (variant): fits per tertile {0: 2975, 1: 2974, 2: 2975}, median slope per tertile {0: 1.0665, 1: 1.0462, 2: 1.0342}, largest tertile lowest: True, Kruskal-Wallis p = 4.64e-42, medians in 0.9-1.1: True
per-session median slope, moving minus stationary: {'count': 30.0, 'mean': -0.0461, 'std': 0.1047, 'min': -0.1927, '25%': -0.099, '50%': -0.0575, '75%': -0.0214, 'max': 0.429}
=== variant, Methods criteria alone
             count    mean     std     min     25%     50%     75%     max
state                                                                     
moving      3550.0  0.9951  0.0855  0.3241  0.9544  0.9990  1.0412  1.4039
stationary  3264.0  1.0640  0.0780  0.4317  1.0247  1.0667  1.1097  1.5114
moving vs stationary: medians 0.9990 vs 1.0667; Mann-Whitney two-sided p = 1.52e-303; sessions with moving fits 30
pooled tertiles (code): fits per tertile {0: 2228, 1: 2521, 2: 2116}, median slope per tertile {0: 1.0769, 1: 1.0528, 2: 1.0394}, largest tertile lowest: True, Kruskal-Wallis p = 1.96e-46, medians in 0.9-1.1: True
per-session tertiles (variant): fits per tertile {0: 2975, 1: 2974, 2: 2975}, median slope per tertile {0: 1.0745, 1: 1.053, 2: 1.0427}, largest tertile lowest: True, Kruskal-Wallis p = 2.73e-42, medians in 0.9-1.1: True
per-session median slope, moving minus stationary: {'count': 30.0, 'mean': -0.0467, 'std': 0.0999, 'min': -0.1903, '25%': -0.0959, '50%': -0.0564, '75%': -0.021, 'max': 0.4021}

Result: reproduced. With the good units, moving trials (44.6% of trials) give lower slopes than stationary ones (medians 0.991 against 1.061, rank-sum p = 2e-307). Over the 25 included sessions with eye tracking, the largest pupil tertile has the lowest median slope (1.029, against 1.070 and 1.046), Kruskal-Wallis p = 1e-48 with pooled tertiles (per-session tertiles, 1.034 against 1.067 and 1.046, p = 5e-42). Every state's median slope lies between 0.9 and 1.1. With the Methods' criteria alone the same holds (medians 0.999 against 1.067; pupil tertiles 1.077, 1.053, 1.039). Five included sessions have no eye tracking, and 10.5% of trials in the others have no pupil value.

figs3-higher-visual-areas¶

The across-neuron slope is concentrated around 1 in the five higher visual areas as in V1.

M1 per area in every session with at least two quality units in the area (a line needs two neurons), over all 32 sessions and over the 30 included sessions, and, as a variant, over the sessions of all 32 that have no more than 10% of trials silent in all units of the area (the Methods exclude "2 sessions for V1 and 1 session for RL" by this rule; Methods, Main dataset and visual stimuli).

In [8]:
for reading, SS in (("good units (main)", S), ("Methods criteria alone (variant)", SQ)):
    for label, idx in (("all 32 sessions", list(tab.index)), ("30 included sessions", keep), ("all 32 sessions, area-specific silence exclusion", list(tab.index))):
        out = {}
        for a in K.ABO_AREAS:
            sl, ns = [], 0
            for i in idx:
                m = SS[i]["area"] == a
                if label.endswith("exclusion") and m.sum() and K.silent_fraction(SS[i]["X"][:, m]) > K.SILENT_TRIAL_LIMIT:
                    continue
                if m.sum() >= 2:
                    ns += 1
                    sl.append(K.fit_slopes(SS[i]["X"][:, m], SS[i]["labels"]).slope.to_numpy())
            sl = np.concatenate(sl)
            out[a] = dict(sessions=ns, sessions_any_unit=int(sum((SS[i]["area"] == a).sum() > 0 for i in idx)), fits=len(sl),
                          median=round(float(np.median(sl)), 4), mean=round(float(sl.mean()), 4),
                          within_0_9_1_1=bool(0.9 <= np.median(sl) <= 1.1))
        print(f"{reading}, {label}"); print(pd.DataFrame(out).T.to_string())
good units (main), all 32 sessions
   sessions sessions_any_unit  fits  median    mean within_0_9_1_1
V1       32                32  3808  1.0569  1.0582           True
LM       24                24  2856  1.0559  1.0449           True
RL       28                28  3332  1.0474  1.0369           True
AL       24                24  2856  1.0452   1.049           True
PM       20                20  2380  1.0016  0.9898           True
AM       26                26  3094  1.0239  1.0117           True
good units (main), 30 included sessions
   sessions sessions_any_unit  fits  median    mean within_0_9_1_1
V1       30                30  3570  1.0516  1.0489           True
LM       22                22  2618  1.0565  1.0438           True
RL       26                26  3094  1.0439  1.0335           True
AL       23                23  2737  1.0477  1.0508           True
PM       18                18  2142  1.0001  0.9888           True
AM       25                25  2975  1.0262  1.0154           True
good units (main), all 32 sessions, area-specific silence exclusion
   sessions sessions_any_unit  fits  median    mean within_0_9_1_1
V1       30                32  3570  1.0516  1.0489           True
LM       24                24  2856  1.0559  1.0449           True
RL       27                28  3213  1.0443  1.0328           True
AL       24                24  2856  1.0452   1.049           True
PM       20                20  2380  1.0016  0.9898           True
AM       26                26  3094  1.0239  1.0117           True
Methods criteria alone (variant), all 32 sessions
   sessions sessions_any_unit  fits  median    mean within_0_9_1_1
V1       32                32  3808  1.0629  1.0641           True
LM       24                24  2856  1.0578  1.0488           True
RL       28                28  3332  1.0606  1.0471           True
AL       24                24  2856   1.046  1.0503           True
PM       20                20  2380  1.0036  0.9914           True
AM       26                26  3094  1.0262  1.0178           True
Methods criteria alone (variant), 30 included sessions
   sessions sessions_any_unit  fits  median    mean within_0_9_1_1
V1       30                30  3570  1.0583  1.0552           True
LM       22                22  2618  1.0591  1.0481           True
RL       26                26  3094  1.0596  1.0457           True
AL       23                23  2737  1.0483   1.052           True
PM       18                18  2142   1.003  0.9909           True
AM       25                25  2975  1.0292  1.0206           True
Methods criteria alone (variant), all 32 sessions, area-specific silence exclusion
   sessions sessions_any_unit  fits  median    mean within_0_9_1_1
V1       30                32  3570  1.0583  1.0552           True
LM       24                24  2856  1.0578  1.0488           True
RL       27                28  3213  1.0572  1.0419           True
AL       24                24  2856   1.046  1.0503           True
PM       20                20  2380  1.0036  0.9914           True
AM       26                26  3094  1.0262  1.0178           True

Result: reproduced. With the good units, over all 32 sessions, the sessions with at least two units are LM 24, RL 28, AL 24, PM 20 and AM 26, each within tolerance of 24, 27, 24, 20 and 26, and the median slopes are 1.056, 1.047, 1.045, 1.002 and 1.024, all between 0.9 and 1.1 (V1 1.057). The Methods' criteria alone give the same session counts, and over the 30 included sessions (22, 26, 23, 18 and 25) the medians again lie between 0.9 and 1.1 under both readings. RL has one session more than the paper's 27: with the Methods' area-specific exclusion of sessions with more than 10% of trials silent in all units of the area, which removes one RL session (and the two V1 sessions), the counts over all 32 sessions are 24, 27, 24, 20 and 26, the paper's exactly, under both unit readings, with medians 1.056, 1.044, 1.045, 1.002 and 1.024 (good units).

Measures under slope manipulation¶

For every included session, V1 units, the as-is data and the 21 target slopes 0 to 2, K.session_measures computes the effective dimensionality, the PC1 fraction, pairwise noise correlations, the overlap matrices (Methods and code thresholds), occupied voxels, geodesic distances and orthogonal variances, local and global alignment, the RSM, and the half-split consistencies; and, for LM and PM, the RSM and its half-split consistency. Sessions run in 4 processes.

In [9]:
SEEDS = {k: seed(k) for k in ["fig4e-rsm-similarity-across-mice", "fig4c-rsm-similarity-within-mice",
                              "fig4a-overlap-consistency-within-mice", "figs6-higher-areas-consistency"]}
def job(i, seeds=SEEDS, halves=True):
    s = S[i]
    areas = {a: s["X"][:, s["area"] == a] for a in ("LM", "PM") if (s["area"] == a).sum() >= 2}
    return K.session_measures(s["X"][:, s["area"] == "V1"], s["labels"], seeds, areas=areas, do_halves=halves)
t = time.time()
with ProcessPoolExecutor(4, mp_context=mp.get_context("fork")) as ex:
    M = dict(zip(keep, ex.map(job, keep)))
print(f"measures for {len(M)} sessions in {(time.time() - t) / 60:.1f} min")
CONDS = ["as-is"] + SLOPES

def curve(key, f=lambda v: v):
    return pd.DataFrame({i: {c: f(M[i][key][c]) for c in CONDS} for i in M}).T

def o1(df, label, n_label="sessions"):
    m = df[SLOPES].mean()
    peak = m.idxmax()
    p0, p2 = wilcoxon(df[0.0], df["as-is"]).pvalue, wilcoxon(df[2.0], df["as-is"]).pvalue
    lower = bool(m[0.0] < df["as-is"].mean() and m[2.0] < df["as-is"].mean())
    res = dict(peak_slope=peak, peak_mean=round(m.max(), 4), mean_asis=round(df["as-is"].mean(), 4), mean_slope0=round(m[0.0], 4),
               mean_slope1=round(m[1.0], 4), mean_slope2=round(m[2.0], 4), p_slope0=float(f"{p0:.3g}"), p_slope2=float(f"{p2:.3g}"),
               ends_lower=lower, reading_a=bool(0.8 <= peak <= 1.2 and lower and p0 < 0.05 and p2 < 0.05),
               reading_b=bool(0.7 <= peak <= 1.3 and lower and p0 < 0.05 and p2 < 0.05))
    print(f"{label} (n = {len(df)} {n_label}):", res)
    print("   curve:", " ".join(f"{c}:{v:.3f}" for c, v in m.items()))
    return res

def o2(df, direction, label):
    m = df[SLOPES].mean()
    a0, a1, a2, asis = m[0.0], m[1.0], m[2.0], df["as-is"].mean()
    order = (a2 < a1 < a0) if direction == "decrease" else (a2 > a1 > a0)
    p0, p2 = wilcoxon(df[0.0], df["as-is"]).pvalue, wilcoxon(df[2.0], df["as-is"]).pvalue
    steps = np.diff(m.to_numpy())
    strict = bool(np.all(steps < 0)) if direction == "decrease" else bool(np.all(steps > 0))
    res = dict(mean_asis=round(asis, 4), mean_slope0=round(a0, 4), mean_slope1=round(a1, 4), mean_slope2=round(a2, 4),
               order=order, p_slope0=float(f"{p0:.3g}"), p_slope2=float(f"{p2:.3g}"), strict_every_step=strict,
               holds=bool(order and p0 < 0.05 and p2 < 0.05))
    print(f"{label} (n = {len(df)} sessions):", res)
    print("   curve:", " ".join(f"{c}:{v:.3f}" for c, v in m.items()))
    return res
measures for 30 sessions in 26.6 min

figs4ab-noise-correlation-under-manipulation¶

Rescaling residuals to change the slope leaves pairwise noise correlations unchanged but changes population-wise noise correlation.

In [10]:
ncd = pd.DataFrame({i: M[i]["nc_maxdiff"] for i in M}).T
print("largest |noise correlation change| over sessions, stimuli and pairs, at slopes 0, 1, 2:", ncd.max().to_dict())
pc = curve("pc1")
for sl in (0.0, 2.0):
    frac = [np.mean(np.abs(M[i]["pc1"][sl] - M[i]["pc1"]["as-is"]) > 1e-9) for i in M]
    print(f"slope {sl}: fraction of stimuli whose PC1 variance fraction differs from as-is, per session min {min(frac):.3f}, mean {np.mean(frac):.3f}; "
          f"pooled mean PC1 fraction {np.mean([np.nanmean(M[i]['pc1'][sl]) for i in M]):.4f} vs as-is {np.mean([np.nanmean(M[i]['pc1']['as-is']) for i in M]):.4f}")
ex7 = keep[7] if len(keep) > 7 else keep[0]
print(f"example (session index {ex7}): mean PC1 fraction as-is {np.nanmean(M[ex7]['pc1']['as-is']):.4f}, slope 0 {np.nanmean(M[ex7]['pc1'][0.0]):.4f}, slope 2 {np.nanmean(M[ex7]['pc1'][2.0]):.4f}")
largest |noise correlation change| over sessions, stimuli and pairs, at slopes 0, 1, 2: {0.0: 7.549516567451064e-15, 1.0: 8.215650382226158e-15, 2.0: 7.771561172376096e-15}
slope 0.0: fraction of stimuli whose PC1 variance fraction differs from as-is, per session min 1.000, mean 1.000; pooled mean PC1 fraction 0.1614 vs as-is 0.3349
slope 2.0: fraction of stimuli whose PC1 variance fraction differs from as-is, per session min 1.000, mean 1.000; pooled mean PC1 fraction 0.5069 vs as-is 0.3349
example (session index 8): mean PC1 fraction as-is 0.4769, slope 0 0.2276, slope 2 0.6414

Result: reproduced. Over the 30 sessions, every stimulus's pairwise noise correlations at slopes 0, 1 and 2 equal the as-is values to within 8.0e-15, and the fraction of variance on the first principal component differs from as-is for every stimulus at slopes 0 and 2 (pooled mean 0.161 at slope 0 and 0.507 at slope 2, against 0.335 as-is).

fig1d-dimensionality-falls-with-slope¶

In [11]:
dim = curve("dim", np.mean)
r_dim = o2(dim, "decrease", "effective dimensionality")
effective dimensionality (n = 30 sessions): {'mean_asis': np.float64(0.1253), 'mean_slope0': np.float64(0.2916), 'mean_slope1': np.float64(0.1288), 'mean_slope2': np.float64(0.0646), 'order': np.True_, 'p_slope0': 1.86e-09, 'p_slope2': 1.86e-09, 'strict_every_step': True, 'holds': True}
   curve: 0.0:0.292 0.1:0.275 0.2:0.256 0.3:0.237 0.4:0.218 0.5:0.200 0.6:0.183 0.7:0.168 0.8:0.154 0.9:0.141 1.0:0.129 1.1:0.118 1.2:0.109 1.3:0.101 1.4:0.093 1.5:0.087 1.6:0.081 1.7:0.076 1.8:0.072 1.9:0.068 2.0:0.065

Result: reproduced. The mean effective dimensionality falls at every 0.1 step from 0.292 at slope 0 to 0.129 at slope 1 and 0.065 at slope 2 (as-is 0.125); slopes 0 and 2 differ from as-is by the Wilcoxon signed-rank test (p = 1.9e-09 each).

figs5c-space-occupancy-peak¶

In [12]:
vox = curve("vox").astype(float)
r_vox = o1(vox, "occupied unit voxels")
print("sessions where the as-is count equals the number of trials (every trial in its own voxel):",
      int(sum(vox.loc[i, 'as-is'] == len(S[i]['labels']) for i in M)), "of", len(M))
print("sessions whose maximum over slopes is reached at more than one slope:", int(sum((vox.loc[i, SLOPES] == vox.loc[i, SLOPES].max()).sum() > 1 for i in M)))
occupied unit voxels (n = 30 sessions): {'peak_slope': 0.8, 'peak_mean': np.float64(5949.9), 'mean_asis': np.float64(5949.9333), 'mean_slope0': np.float64(5728.5667), 'mean_slope1': np.float64(5946.5333), 'mean_slope2': np.float64(379.1333), 'p_slope0': 1.73e-06, 'p_slope2': 1.73e-06, 'ends_lower': True, 'reading_a': True, 'reading_b': True}
   curve: 0.0:5728.567 0.1:5820.100 0.2:5876.267 0.3:5912.133 0.4:5932.100 0.5:5942.467 0.6:5947.167 0.7:5948.967 0.8:5949.900 0.9:5949.400 1.0:5946.533 1.1:5874.467 1.2:5313.633 1.3:4249.500 1.4:3168.733 1.5:2283.100 1.6:1606.200 1.7:1124.367 1.8:782.667 1.9:542.433 2.0:379.133
sessions where the as-is count equals the number of trials (every trial in its own voxel): 28 of 30
sessions whose maximum over slopes is reached at more than one slope: 28

Result: reproduced. The mean count of occupied unit voxels peaks at slope 0.8 (5949.9), within both windows, and is lower at slope 0 (5728.6) and slope 2 (379.1) than as-is (5949.9), with p = 1.7e-06 for each. The measure is at its ceiling near the peak: in 28 of 30 sessions every as-is trial occupies a voxel of its own, and in 28 sessions the maximum is shared by more than one slope, so the peak at 0.8 marks the middle of a plateau that runs from about 0.6 to 1.0 (means 5946.5 to 5949.9). The fall at high slopes comes from points that leave the as-is box and are dropped, as compute_percent_filled does (box_and_overlap.py, lines 107 to 111 at ac3300b), which also anchors the grid at the minimum of the points kept (line 122), as here.

fig2a-overlap-rises-with-slope and fig2c-continuity-from-slope-1¶

In [13]:
ov = curve("O_m", K.mean_offdiag)
r_ov = o2(ov, "increase", "overlap, distinct pairs, Methods threshold (main)")
ov_code = curve("O_c", lambda O: float(O.mean()))
r_ov_code = o2(ov_code, "increase", "overlap, code variant (code threshold, full matrix with diagonal)")
ov_c2 = curve("O_c", K.mean_offdiag)
o2(ov_c2, "increase", "overlap, code threshold, distinct pairs")
overlap, distinct pairs, Methods threshold (main) (n = 30 sessions): {'mean_asis': np.float64(0.2881), 'mean_slope0': np.float64(0.0653), 'mean_slope1': np.float64(0.2793), 'mean_slope2': np.float64(0.4217), 'order': np.True_, 'p_slope0': 1.86e-09, 'p_slope2': 1.86e-09, 'strict_every_step': True, 'holds': True}
   curve: 0.0:0.065 0.1:0.075 0.2:0.088 0.3:0.104 0.4:0.124 0.5:0.148 0.6:0.175 0.7:0.202 0.8:0.230 0.9:0.255 1.0:0.279 1.1:0.302 1.2:0.323 1.3:0.342 1.4:0.360 1.5:0.377 1.6:0.390 1.7:0.402 1.8:0.410 1.9:0.417 2.0:0.422
overlap, code variant (code threshold, full matrix with diagonal) (n = 30 sessions): {'mean_asis': np.float64(0.2353), 'mean_slope0': np.float64(0.0487), 'mean_slope1': np.float64(0.2248), 'mean_slope2': np.float64(0.3182), 'order': np.True_, 'p_slope0': 1.86e-09, 'p_slope2': 4.71e-07, 'strict_every_step': True, 'holds': True}
   curve: 0.0:0.049 0.1:0.056 0.2:0.065 0.3:0.077 0.4:0.093 0.5:0.112 0.6:0.134 0.7:0.158 0.8:0.182 0.9:0.205 1.0:0.225 1.1:0.243 1.2:0.259 1.3:0.273 1.4:0.285 1.5:0.295 1.6:0.304 1.7:0.310 1.8:0.314 1.9:0.317 2.0:0.318
overlap, code threshold, distinct pairs (n = 30 sessions):
 {'mean_asis': np.float64(0.2289), 'mean_slope0': np.float64(0.0407), 'mean_slope1': np.float64(0.2183), 'mean_slope2': np.float64(0.3124), 'order': np.True_, 'p_slope0': 1.86e-09, 'p_slope2': 4.71e-07, 'strict_every_step': True, 'holds': True}
   curve: 0.0:0.041 0.1:0.048 0.2:0.057 0.3:0.070 0.4:0.085 0.5:0.105 0.6:0.127 0.7:0.151 0.8:0.175 0.9:0.198 1.0:0.218 1.1:0.237 1.2:0.253 1.3:0.267 1.4:0.279 1.5:0.289 1.6:0.298 1.7:0.304 1.8:0.308 1.9:0.311 2.0:0.312
Out[13]:
{'mean_asis': np.float64(0.2289),
 'mean_slope0': np.float64(0.0407),
 'mean_slope1': np.float64(0.2183),
 'mean_slope2': np.float64(0.3124),
 'order': np.True_,
 'p_slope0': 1.86e-09,
 'p_slope2': 4.71e-07,
 'strict_every_step': True,
 'holds': True}

Result: fig2a-overlap-rises-with-slope reproduced. The mean overlap over ordered pairs of distinct stimuli rises at every 0.1 step from 0.065 at slope 0 to 0.279 at slope 1 and 0.422 at slope 2 (as-is 0.288), with p = 1.9e-09 for slopes 0 and 2 against as-is. The code's variant (its threshold, the full matrix with the diagonal) gives 0.049, 0.225 and 0.318 (p = 1.9e-09 and 4.7e-07), also rising at every step.

In [14]:
scc = curve("O_m", K.largest_scc).astype(float)
scc_c = curve("O_c", K.largest_scc).astype(float)
for name, df in (("Methods threshold", scc), ("code threshold", scc_c)):
    m = df[SLOPES].mean()
    full = [c for c in SLOPES if m[c] >= 119]
    first = full[0] if full else None
    try:
        p0 = wilcoxon(df[0.0], df["as-is"]).pvalue
    except ValueError:
        p0 = float("nan")
    print(f"{name}: mean largest SCC size by slope", " ".join(f"{c}:{v:.1f}" for c, v in m.items()), f"| as-is {df['as-is'].mean():.1f}")
    print(f"   first slope with mean 119: {first}; reading a (0.8-1.2): {first is not None and 0.8 <= first <= 1.2}; reading b (0.7-1.3): {first is not None and 0.7 <= first <= 1.3}; "
          f"slope 0 mean {m[0.0]:.1f}, Wilcoxon vs as-is p = {p0:.3g}; sessions at 119 as-is {int((df['as-is'] == 119).sum())} of {len(df)}")
    print("   sessions reaching 119 by slope:", " ".join(f"{c}:{int((df[c] == 119).sum())}" for c in SLOPES))
Methods threshold: mean largest SCC size by slope 0.0:108.1 0.1:110.0 0.2:111.9 0.3:113.8 0.4:115.0 0.5:116.4 0.6:117.5 0.7:118.3 0.8:118.6 0.9:118.8 1.0:118.9 1.1:119.0 1.2:119.0 1.3:119.0 1.4:119.0 1.5:119.0 1.6:119.0 1.7:119.0 1.8:119.0 1.9:119.0 2.0:119.0 | as-is 118.9
   first slope with mean 119: 1.1; reading a (0.8-1.2): True; reading b (0.7-1.3): True; slope 0 mean 108.1, Wilcoxon vs as-is p = 5.8e-05; sessions at 119 as-is 29 of 30
   sessions reaching 119 by slope: 0.0:9 0.1:9 0.2:10 0.3:13 0.4:14 0.5:21 0.6:25 0.7:26 0.8:27 0.9:28 1.0:29 1.1:30 1.2:30 1.3:30 1.4:30 1.5:30 1.6:30 1.7:30 1.8:30 1.9:30 2.0:30
code threshold: mean largest SCC size by slope 0.0:104.3 0.1:106.8 0.2:109.1 0.3:111.4 0.4:113.6 0.5:115.2 0.6:116.6 0.7:117.8 0.8:118.3 0.9:118.6 1.0:118.9 1.1:119.0 1.2:119.0 1.3:119.0 1.4:119.0 1.5:119.0 1.6:119.0 1.7:119.0 1.8:119.0 1.9:119.0 2.0:119.0 | as-is 118.9
   first slope with mean 119: 1.2; reading a (0.8-1.2): True; reading b (0.7-1.3): True; slope 0 mean 104.3, Wilcoxon vs as-is p = 3.96e-05; sessions at 119 as-is 29 of 30
   sessions reaching 119 by slope: 0.0:8 0.1:9 0.2:9 0.3:9 0.4:13 0.5:16 0.6:22 0.7:26 0.8:26 0.9:27 1.0:29 1.1:29 1.2:30 1.3:30 1.4:30 1.5:30 1.6:30 1.7:30 1.8:30 1.9:30 2.0:30

Result: fig2c-continuity-from-slope-1 reproduced. The mean size of the largest strongly connected component first reaches 119 at slope 1.1 (Methods threshold; 1.2 with the code's threshold), inside both windows; at slope 0 it is 108.1 (104.3) and differs from as-is (118.9, 29 of 30 sessions complete) with p = 5.8e-05 (4.0e-05). The number of sessions whose component covers all stimuli grows from 9 at slope 0 to 29 at slope 1 and 30 from 1.1.

fig3bc-geodesic-orthogonal-correlation, fig3d, fig3e, fig3f¶

In [15]:
geo = curve("geo_rho")
rho = geo["as-is"]
w = wilcoxon(rho, alternative="greater")
print(f"as-is Spearman rho per session: mean {rho.mean():.4f}, range {rho.min():.4f} to {rho.max():.4f}, positive in {(rho > 0).sum()} of {len(rho)}; "
      f"one-sided Wilcoxon against 0 p = {w.pvalue:.3g}; pairs per session {int(np.isfinite(K._offdiag(M[keep[0]]['asis_ortho'])).sum())}")
print("sessions with non-finite geodesics:", int(sum((~np.isfinite(M[i]["asis_geo"])).any() for i in M)))
as-is Spearman rho per session: mean 0.3254, range 0.0275 to 0.5640, positive in 30 of 30; one-sided Wilcoxon against 0 p = 9.31e-10; pairs per session 14042
sessions with non-finite geodesics: 0

Result: fig3bc-geodesic-orthogonal-correlation reproduced. The as-is Spearman correlation between inter-centroid geodesic distance and orthogonal variance over the 14042 ordered pairs is positive in all 30 sessions (mean 0.325, 0.028 to 0.564), and the one-sided Wilcoxon test against 0 gives p = 9.3e-10.

In [16]:
r_geo = o1(geo, "geodesic-orthogonal variance Spearman")
geodesic-orthogonal variance Spearman (n = 30 sessions): {'peak_slope': 1.2, 'peak_mean': np.float64(0.3315), 'mean_asis': np.float64(0.3254), 'mean_slope0': np.float64(0.2275), 'mean_slope1': np.float64(0.3268), 'mean_slope2': np.float64(0.3067), 'p_slope0': 3.15e-07, 'p_slope2': 0.0093, 'ends_lower': True, 'reading_a': True, 'reading_b': True}
   curve: 0.0:0.227 0.1:0.241 0.2:0.252 0.3:0.264 0.4:0.275 0.5:0.284 0.6:0.293 0.7:0.303 0.8:0.312 0.9:0.320 1.0:0.327 1.1:0.330 1.2:0.332 1.3:0.330 1.4:0.327 1.5:0.325 1.6:0.322 1.7:0.318 1.8:0.314 1.9:0.311 2.0:0.307

Result: fig3d-correlation-peaks-near-1 reproduced. The mean correlation peaks at slope 1.2 (0.332), inside both windows; it is lower at slope 0 (0.228) and slope 2 (0.307) than as-is (0.325), with p = 3.2e-07 and 0.0093.

In [17]:
r_loc = o1(curve("local"), "local alignment (as-is neighbour, code)")
o1(curve("local_slope_nn"), "local alignment (variant, neighbour from the slope-changed data)")
local alignment (as-is neighbour, code) (n = 30 sessions): {'peak_slope': 1.0, 'peak_mean': np.float64(0.8226), 'mean_asis': np.float64(0.822), 'mean_slope0': np.float64(0.7272), 'mean_slope1': np.float64(0.8226), 'mean_slope2': np.float64(0.7934), 'p_slope0': 1.42e-06, 'p_slope2': 0.00113, 'ends_lower': True, 'reading_a': True, 'reading_b': True}
   curve: 0.0:0.727 0.1:0.752 0.2:0.770 0.3:0.784 0.4:0.796 0.5:0.805 0.6:0.812 0.7:0.817 0.8:0.821 0.9:0.822 1.0:0.823 1.1:0.821 1.2:0.819 1.3:0.817 1.4:0.814 1.5:0.812 1.6:0.808 1.7:0.805 1.8:0.801 1.9:0.798 2.0:0.793
local alignment (variant, neighbour from the slope-changed data) (n = 30 sessions): {'peak_slope': 1.0, 'peak_mean': np.float64(0.8232), 'mean_asis': np.float64(0.822), 'mean_slope0': np.float64(0.7243), 'mean_slope1': np.float64(0.8232), 'mean_slope2': np.float64(0.7937), 'p_slope0': 1.42e-06, 'p_slope2': 0.00172, 'ends_lower': True, 'reading_a': True, 'reading_b': True}
   curve: 0.0:0.724 0.1:0.749 0.2:0.768 0.3:0.783 0.4:0.795 0.5:0.804 0.6:0.811 0.7:0.816 0.8:0.820 0.9:0.823 1.0:0.823 1.1:0.822 1.2:0.820 1.3:0.817 1.4:0.815 1.5:0.812 1.6:0.809 1.7:0.805 1.8:0.801 1.9:0.798 2.0:0.794
Out[17]:
{'peak_slope': 1.0,
 'peak_mean': np.float64(0.8232),
 'mean_asis': np.float64(0.822),
 'mean_slope0': np.float64(0.7243),
 'mean_slope1': np.float64(0.8232),
 'mean_slope2': np.float64(0.7937),
 'p_slope0': 1.42e-06,
 'p_slope2': 0.00172,
 'ends_lower': True,
 'reading_a': True,
 'reading_b': True}

Result: fig3e-local-alignment-peaks-near-1 reproduced. Mean local alignment peaks at slope 1.0 (0.823); slope 0 (0.727) and slope 2 (0.793) are lower than as-is (0.822), p = 1.4e-06 and 0.0011. With the neighbour taken from the slope-changed data (variant) the peak is also at 1.0.

In [18]:
r_glo = o1(curve("global"), "global alignment")
global alignment (n = 30 sessions): {'peak_slope': 1.0, 'peak_mean': np.float64(0.8318), 'mean_asis': np.float64(0.8318), 'mean_slope0': np.float64(0.6975), 'mean_slope1': np.float64(0.8318), 'mean_slope2': np.float64(0.796), 'p_slope0': 1.64e-07, 'p_slope2': 0.000209, 'ends_lower': True, 'reading_a': True, 'reading_b': True}
   curve: 0.0:0.697 0.1:0.726 0.2:0.750 0.3:0.771 0.4:0.789 0.5:0.803 0.6:0.815 0.7:0.823 0.8:0.829 0.9:0.831 1.0:0.832 1.1:0.830 1.2:0.828 1.3:0.826 1.4:0.827 1.5:0.823 1.6:0.818 1.7:0.812 1.8:0.807 1.9:0.801 2.0:0.796

Result: fig3f-global-alignment-peaks-near-1 reproduced. Mean global alignment peaks at slope 1.0 (0.832); slope 0 (0.698) and slope 2 (0.796) are lower than as-is (0.832), p = 1.6e-07 and 0.00021.

fig4a, fig4c, fig4d, fig4e, figs6¶

In [19]:
r_4a = o1(curve("ov_half"), "overlap consistency within session, full matrices (code, main)")
o1(curve("ov_half_off"), "overlap consistency within session, off-diagonal (variant)")
overlap consistency within session, full matrices (code, main) (n = 30 sessions): {'peak_slope': 0.9, 'peak_mean': np.float64(0.6512), 'mean_asis': np.float64(0.6406), 'mean_slope0': np.float64(0.4269), 'mean_slope1': np.float64(0.6479), 'mean_slope2': np.float64(0.3579), 'p_slope0': 1.86e-09, 'p_slope2': 1.86e-09, 'ends_lower': True, 'reading_a': True, 'reading_b': True}
   curve: 0.0:0.427 0.1:0.447 0.2:0.470 0.3:0.498 0.4:0.530 0.5:0.563 0.6:0.596 0.7:0.625 0.8:0.644 0.9:0.651 1.0:0.648 1.1:0.636 1.2:0.618 1.3:0.594 1.4:0.566 1.5:0.533 1.6:0.498 1.7:0.461 1.8:0.425 1.9:0.390 2.0:0.358
overlap consistency within session, off-diagonal (variant) (n = 30 sessions): {'peak_slope': 0.9, 'peak_mean': np.float64(0.6422), 'mean_asis': np.float64(0.6313), 'mean_slope0': np.float64(0.4035), 'mean_slope1': np.float64(0.6388), 'mean_slope2': np.float64(0.3415), 'p_slope0': 1.86e-09, 'p_slope2': 1.86e-09, 'ends_lower': True, 'reading_a': True, 'reading_b': True}
   curve: 0.0:0.404 0.1:0.426 0.2:0.452 0.3:0.483 0.4:0.516 0.5:0.551 0.6:0.585 0.7:0.615 0.8:0.635 0.9:0.642 1.0:0.639 1.1:0.627 1.2:0.608 1.3:0.583 1.4:0.555 1.5:0.521 1.6:0.485 1.7:0.448 1.8:0.410 1.9:0.375 2.0:0.341
Out[19]:
{'peak_slope': 0.9,
 'peak_mean': np.float64(0.6422),
 'mean_asis': np.float64(0.6313),
 'mean_slope0': np.float64(0.4035),
 'mean_slope1': np.float64(0.6388),
 'mean_slope2': np.float64(0.3415),
 'p_slope0': 1.86e-09,
 'p_slope2': 1.86e-09,
 'ends_lower': True,
 'reading_a': True,
 'reading_b': True}

Result: fig4a-overlap-consistency-within-mice reproduced. The mean Spearman correlation between the overlap matrices of two random halves of the neurons peaks at slope 0.9 (0.651, with 0.648 at 1.0); slope 0 (0.427) and slope 2 (0.358) are lower than as-is (0.641), p = 1.9e-09 each. The off-diagonal variant also peaks at 0.9. Only the claim's seed was run for this measure.

In [20]:
r_4c = o1(curve("rsm_half"), "RSM similarity within session")
RSM similarity within session (n = 30 sessions): {'peak_slope': 1.1, 'peak_mean': np.float64(0.4351), 'mean_asis': np.float64(0.4559), 'mean_slope0': np.float64(0.4094), 'mean_slope1': np.float64(0.4303), 'mean_slope2': np.float64(0.2157), 'p_slope0': 0.00113, 'p_slope2': 1.86e-08, 'ends_lower': True, 'reading_a': True, 'reading_b': True}
   curve: 0.0:0.409 0.1:0.411 0.2:0.412 0.3:0.413 0.4:0.414 0.5:0.415 0.6:0.416 0.7:0.418 0.8:0.421 0.9:0.425 1.0:0.430 1.1:0.435 1.2:0.431 1.3:0.410 1.4:0.378 1.5:0.343 1.6:0.309 1.7:0.280 1.8:0.254 1.9:0.233 2.0:0.216

Result: fig4c-rsm-similarity-within-mice reproduced. The mean half-split RSM correlation peaks at slope 1.1 (0.435); slope 0 (0.409) and slope 2 (0.216) are lower than as-is (0.456), p = 0.0011 and 1.9e-08. The as-is value is higher than at any changed slope. Under the four further seeds the peak is at 1.1 each time (seed check at the end of reproduce_kim_2025_decoding.ipynb).

In [21]:
pairs = list(itertools.combinations(keep, 2))
def across(key, f):
    return pd.DataFrame({p: {c: f(M[p[0]][key][c], M[p[1]][key][c]) for c in CONDS} for p in pairs}).T
full_sp = lambda A, B: spearmanr(A.ravel(), B.ravel()).statistic
off_sp = lambda A, B: spearmanr(K._offdiag(A), K._offdiag(B)).statistic
r_4d = o1(across("O_m", full_sp), "overlap consistency across sessions, full matrices (main)", "session pairs")
o1(across("O_m", off_sp), "overlap consistency across sessions, off-diagonal (variant)", "session pairs")
overlap consistency across sessions, full matrices (main) (n = 435 session pairs): {'peak_slope': 1.2, 'peak_mean': np.float64(0.4302), 'mean_asis': np.float64(0.4114), 'mean_slope0': np.float64(0.253), 'mean_slope1': np.float64(0.4247), 'mean_slope2': np.float64(0.3484), 'p_slope0': 1.97e-69, 'p_slope2': 1.07e-31, 'ends_lower': True, 'reading_a': True, 'reading_b': True}
   curve: 0.0:0.253 0.1:0.261 0.2:0.273 0.3:0.288 0.4:0.308 0.5:0.332 0.6:0.358 0.7:0.382 0.8:0.402 0.9:0.416 1.0:0.425 1.1:0.429 1.2:0.430 1.3:0.428 1.4:0.424 1.5:0.417 1.6:0.408 1.7:0.396 1.8:0.381 1.9:0.365 2.0:0.348
overlap consistency across sessions, off-diagonal (variant) (n = 435 session pairs): {'peak_slope': 1.2, 'peak_mean': np.float64(0.4155), 'mean_asis': np.float64(0.3962), 'mean_slope0': np.float64(0.2167), 'mean_slope1': np.float64(0.4098), 'mean_slope2': np.float64(0.3316), 'p_slope0': 1.88e-72, 'p_slope2': 1.9e-31, 'ends_lower': True, 'reading_a': True, 'reading_b': True}
   curve: 0.0:0.217 0.1:0.229 0.2:0.244 0.3:0.263 0.4:0.285 0.5:0.312 0.6:0.339 0.7:0.365 0.8:0.386 0.9:0.401 1.0:0.410 1.1:0.415 1.2:0.416 1.3:0.413 1.4:0.409 1.5:0.402 1.6:0.393 1.7:0.381 1.8:0.366 1.9:0.349 2.0:0.332
Out[21]:
{'peak_slope': 1.2,
 'peak_mean': np.float64(0.4155),
 'mean_asis': np.float64(0.3962),
 'mean_slope0': np.float64(0.2167),
 'mean_slope1': np.float64(0.4098),
 'mean_slope2': np.float64(0.3316),
 'p_slope0': 1.88e-72,
 'p_slope2': 1.9e-31,
 'ends_lower': True,
 'reading_a': True,
 'reading_b': True}

Result: fig4d-overlap-consistency-across-mice reproduced. Over the 435 session pairs, the mean Spearman correlation between overlap matrices peaks at slope 1.2 (0.430); slope 0 (0.253) and slope 2 (0.348) are lower than as-is (0.411), p = 2.0e-69 and 1.1e-31. The off-diagonal variant also peaks at 1.2.

In [22]:
rsm_sp = lambda A, B: spearmanr(A.ravel(), B.ravel(), nan_policy="omit").statistic
r_4e = o1(across("rsm", rsm_sp), "RSM similarity across sessions", "session pairs")
RSM similarity across sessions (n = 435 session pairs): {'peak_slope': 1.1, 'peak_mean': np.float64(0.3878), 'mean_asis': np.float64(0.3978), 'mean_slope0': np.float64(0.3483), 'mean_slope1': np.float64(0.3827), 'mean_slope2': np.float64(0.1862), 'p_slope0': 1.26e-51, 'p_slope2': 1.49e-70, 'ends_lower': True, 'reading_a': True, 'reading_b': True}
   curve: 0.0:0.348 0.1:0.348 0.2:0.349 0.3:0.350 0.4:0.352 0.5:0.355 0.6:0.358 0.7:0.363 0.8:0.369 0.9:0.376 1.0:0.383 1.1:0.388 1.2:0.385 1.3:0.366 1.4:0.336 1.5:0.305 1.6:0.276 1.7:0.250 1.8:0.227 1.9:0.205 2.0:0.186

Result: fig4e-rsm-similarity-across-mice reproduced. Over the 435 session pairs the mean RSM correlation peaks at slope 1.1 (0.388); slope 0 (0.348) and slope 2 (0.186) are lower than as-is (0.398), p = 1.3e-51 and 1.5e-70. The as-is value is higher than at any changed slope. Under the four further seeds the peak is at 1.1 each time (seed check at the end of reproduce_kim_2025_decoding.ipynb).

In [23]:
def near_max(df, n_label):
    m, se = df[SLOPES].mean(), df[SLOPES].sem()
    peak = m.idxmax()
    a = bool(m[1.0] >= m.max() - se[peak])
    b = bool(0.8 <= peak <= 1.2)
    b2 = bool(0.7 <= peak <= 1.3)
    return dict(n=len(df), peak=peak, mean_at_1=round(m[1.0], 4), max=round(m.max(), 4), sem_at_peak=round(se[peak], 4),
                reading_a=a, reading_b_08_12=b, reading_b_07_13=b2)
s6 = {}
for a in ("LM", "PM"):
    ids = [i for i in M if a in M[i]["area_rsm_half"]]
    within = pd.DataFrame({i: M[i]["area_rsm_half"][a] for i in ids}).T
    pa = list(itertools.combinations(ids, 2))
    acr = pd.DataFrame({p: {c: rsm_sp(M[p[0]]["area_rsm"][a][c], M[p[1]]["area_rsm"][a][c]) for c in CONDS} for p in pa}).T
    s6[(a, "S6B within")] = near_max(within, "sessions")
    s6[(a, "S6C across")] = near_max(acr, "pairs")
    print(a, "within curve:", " ".join(f"{c}:{v:.3f}" for c, v in within[SLOPES].mean().items()))
    print(a, "across curve:", " ".join(f"{c}:{v:.3f}" for c, v in acr[SLOPES].mean().items()))
print(pd.DataFrame(s6).T.to_string())
LM within curve: 0.0:0.257 0.1:0.260 0.2:0.262 0.3:0.262 0.4:0.261 0.5:0.260 0.6:0.259 0.7:0.257 0.8:0.256 0.9:0.255 1.0:0.255 1.1:0.252 1.2:0.244 1.3:0.227 1.4:0.205 1.5:0.179 1.6:0.154 1.7:0.132 1.8:0.113 1.9:0.097 2.0:0.084
LM across curve: 0.0:0.215 0.1:0.214 0.2:0.214 0.3:0.214 0.4:0.214 0.5:0.215 0.6:0.216 0.7:0.217 0.8:0.220 0.9:0.223 1.0:0.227 1.1:0.230 1.2:0.230 1.3:0.222 1.4:0.206 1.5:0.184 1.6:0.159 1.7:0.136 1.8:0.115 1.9:0.098 2.0:0.083
PM within curve: 0.0:0.310 0.1:0.314 0.2:0.316 0.3:0.317 0.4:0.316 0.5:0.315 0.6:0.314 0.7:0.312 0.8:0.308 0.9:0.304 1.0:0.298 1.1:0.292 1.2:0.282 1.3:0.264 1.4:0.238 1.5:0.208 1.6:0.179 1.7:0.153 1.8:0.130 1.9:0.111 2.0:0.095
PM across curve: 0.0:0.280 0.1:0.281 0.2:0.283 0.3:0.285 0.4:0.288 0.5:0.291 0.6:0.295 0.7:0.299 0.8:0.303 0.9:0.306 1.0:0.306 1.1:0.299 1.2:0.281 1.3:0.250 1.4:0.214 1.5:0.178 1.6:0.145 1.7:0.117 1.8:0.094 1.9:0.075 2.0:0.060
                 n peak mean_at_1     max sem_at_peak reading_a reading_b_08_12 reading_b_07_13
LM S6B within   22  0.3    0.2547  0.2619      0.0233      True           False           False
   S6C across  231  1.2    0.2267  0.2304      0.0077      True            True            True
PM S6B within   18  0.3    0.2983  0.3165      0.0366      True           False           False
   S6C across  153  0.9    0.3058  0.3058      0.0089      True            True            True

Result: figs6-higher-areas-consistency reproduced under reading (a). For LM and PM, within sessions (S6B; 22 and 18 sessions) and across session pairs (S6C; 231 and 153 pairs), the mean at slope 1 lies within one SEM of the curve's maximum in all four panels (reading a). Under reading (b) the maximum lies in the window only across pairs (LM 1.2, PM 0.9); within sessions the curves are nearly flat from slope 0 to 1.1 and peak at 0.3 (LM, 0.262 against 0.255 at slope 1, SEM 0.023) and 0.3 (PM, 0.317 against 0.298, SEM 0.037). Within sessions the SEM is larger than the spread of the curve between slopes 0 and 1.1, so slope 0 also lies within one SEM of the maximum there, and reading (a) does not tell slope 1 from slope 0 in those two panels. Reading (a) holds in all four panels under every seed of the seed check in reproduce_kim_2025_decoding.ipynb.

figs5a-movie-slope-near-1¶

In the natural movie data the across-neuron log-mean against log-variance relation is also linear with slope near 1.

The paper's natural movie data are the Allen "Functional Connectivity" sessions, deposited as dandiset 000022, version 0.251116.2247 (the only published version; doi:10.48324/dandi.000022/0.251116.2247), streamed. In these files the 60-repeat block of natural movie one is natural_movie_one_more_repeats_presentations (a 20-repeat shuffled version is a separate table). Each repeat is cut into 75 bins of 12 frames; M1 per bin and session.

Exclusions. The Methods exclude 3 of 26 sessions "for truncated movies or no V1 units". The paper's code skips sessions 5, 14 and 43 of AllenSDK's session table, all 58 Brain Observatory 1.1 and Functional Connectivity sessions, with the comment "movie one presentation had trouble in some trials...stimtable.stimulus_name 'invalid_presentation' (session 5, 14, 43)" (extract_natural_movie_neuropixels.m, lines 19 and 101, at ac3300b). AllenSDK marks a presentation invalid when it overlaps an invalid_times interval tagged "stimulus" (_mask_invalid_stimulus_presentations, allensdk/brain_observatory/ecephys/ecephys_session.py, lines 645 to 680, at commit a56bd8ea7613a812334602b64746cdd30c325a96); here a frame counts when its onset lies in such an interval. Below, the 58 session ids of the two dandisets are put in AllenSDK's order (ascending session id) to show which sessions 5, 14 and 43 are, and each Functional Connectivity session's movie block is checked for such intervals, for incomplete repeats, for its longest repeat and for its longest gap between frames. A session is used when no movie frame falls in an invalid "stimulus" interval, every repeat is complete, and it has at least two V1 units. Units: the Methods' criteria and the label "good" (main, as for the natural scenes; the code reads AllenSDK's units table), and the Methods' criteria alone (variant).

In [24]:
import re
all_ids = sorted([(int(re.search(r"ses-(\d+)", p_).group(1)), "Brain Observatory 1.1", p_.split("/")[0])
                  for p_ in K.asset_paths(K.ABO_ID, K.ABO_VERSION) if "probe" not in p_]
                 + [(int(re.search(r"ses-(\d+)", p_).group(1)), "Functional Connectivity", p_.split("/")[0])
                    for p_ in K.asset_paths(K.FC_ID, K.FC_VERSION) if "probe" not in p_])
print(f"{len(all_ids)} sessions in ascending session id; the code's sessions 5, 14 and 43 (1-based):")
for k in (5, 14, 43):
    print("  ", k, all_ids[k - 1])
with ProcessPoolExecutor(4, mp_context=mp.get_context("fork")) as ex:
    bo_inv = list(ex.map(K.movie_invalid_frames, paths, [K.ABO_ID] * len(paths), [K.ABO_VERSION] * len(paths)))
print("Brain Observatory 1.1 sessions (dandiset 000021) with an invalid_times interval tagged stimulus, and the natural movie one frames inside one:")
for r in bo_inv:
    if any("stimulus" in t for _, _, t in r["intervals"]):
        print("  ", r["session"], {k: v for k, v in r.items() if k.startswith("natural_movie_one")},
              [(a, b) for a, b, t in r["intervals"] if "stimulus" in t])
print("Brain Observatory 1.1 sessions with natural movie one frames inside such an interval:",
      [r["session"] for r in bo_inv if any(v > 0 for k, v in r.items() if k.startswith("natural_movie_one"))])
fc_paths = [p for p in K.asset_paths(K.FC_ID, K.FC_VERSION) if "probe" not in p]
with ProcessPoolExecutor(4, mp_context=mp.get_context("fork")) as ex:
    movie = list(ex.map(K.movie_session, fc_paths))
mvt = pd.DataFrame([dict(session=r["path"].split("/")[0], **{k: v for k, v in r.items() if k != "path"}) for _, _, _, r in movie])
mvt["valid"] = (mvt.invalid_stimulus_frames == 0) & (mvt.repeats_incomplete == 0)
print(mvt.to_string())
print("Functional Connectivity sessions with movie frames inside such an interval:", list(mvt.session[mvt.invalid_stimulus_frames > 0]))
for reading, use_good in (("main, good units", True), ("variant, Methods criteria alone", False)):
    for excl, need_valid in (("invalid movie sessions excluded (code)", True), ("no invalid exclusion", False)):
        sl, n_used = [], 0
        for (Xm, labm, goodm, r), v in zip(movie, mvt.valid):
            Xu = Xm[:, goodm] if use_good else Xm
            if Xu.shape[1] >= 2 and (v or not need_valid):
                n_used += 1
                sl.append(K.fit_slopes(Xu, labm).slope.to_numpy())
        ms = np.concatenate(sl)
        print(f"{reading}, {excl}: sessions used {n_used} of {len(movie)}; bins per session {set(len(x) for x in sl)}; fits {len(ms)}; "
              f"median {np.median(ms):.4f}, mean {ms.mean():.4f}, SD {ms.std(ddof=1):.4f}, range {ms.min():.3f} to {ms.max():.3f}; "
              f"median in 0.9-1.1: {0.9 <= np.median(ms) <= 1.1}, in 0.85-1.15: {0.85 <= np.median(ms) <= 1.15}")
58 sessions in ascending session id; the code's sessions 5, 14 and 43 (1-based):
   5 (737581020, 'Brain Observatory 1.1', 'sub-718643564')
   14 (754312389, 'Brain Observatory 1.1', 'sub-719828686')
   43 (793224716, 'Functional Connectivity', 'sub-769319621')
Brain Observatory 1.1 sessions (dandiset 000021) with an invalid_times interval tagged stimulus, and the natural movie one frames inside one:
   sub-703279277 {'natural_movie_one_presentations': 0} [(970.0, 982.0)]
   sub-716813540 {'natural_movie_one_presentations': 0} [(1998.0, 2005.0), (2114.0, 2121.0), (8834.0, 8841.0), (8897.0, 9003.0)]
   sub-718643564 {'natural_movie_one_presentations': 239} [(1490.0, 1497.0), (5726.0, 5744.0), (5795.0, 5815.0), (6385.0, 6395.0), (7492.0, 7500.0), (7766.0, 7774.0)]
   sub-719828686 {'natural_movie_one_presentations': 954} [(7830.0, 7862.0)]
Brain Observatory 1.1 sessions with natural movie one frames inside such an interval: ['sub-718643564', 'sub-719828686']
          session  repeats_complete  repeats_incomplete  v1_units  v1_good  invalid_stimulus_frames  longest_repeat_s  longest_frame_gap_s           bin_s  valid
0   sub-744912845                60                   0        60       55                        0            30.025                0.050  (0.384, 0.417)   True
1   sub-753795604                60                   0       117      108                        0            30.025                0.033      (0.4, 0.4)   True
2   sub-754477355                60                   0        81       76                        0            30.042                0.050    (0.4, 0.417)   True
3   sub-754488976                60                   0        90       86                        0            30.025                0.033      (0.4, 0.4)   True
4   sub-756578432                60                   0        61       56                        0            30.025                0.033      (0.4, 0.4)   True
5   sub-759674767                60                   0        78       75                        0            30.025                0.033      (0.4, 0.4)   True
6   sub-759711149                60                   0        78       73                        0            30.025                0.033      (0.4, 0.4)   True
7   sub-760938794                60                   0       101       91                        0            30.025                0.050      (0.4, 0.4)   True
8   sub-760946810                60                   0        85       84                        0            30.025                0.050  (0.384, 0.417)   True
9   sub-760960650                60                   0       140      130                        0            30.025                0.033      (0.4, 0.4)   True
10  sub-763236006                60                   0        74       70                        0            30.025                0.033      (0.4, 0.4)   True
11  sub-763808588                60                   0        21       15                        0            30.025                0.033      (0.4, 0.4)   True
12  sub-763884096                60                   0        90       87                        0            30.042                0.050    (0.4, 0.417)   True
13  sub-769319621                60                   0        93       85                     1497            30.719                0.133    (0.368, 0.5)  False
14  sub-774672354                60                   0       131      113                        0            30.025                0.033      (0.4, 0.4)   True
15  sub-791857600                60                   0        70       66                        0            30.025                0.033      (0.4, 0.4)   True
16  sub-795770029                60                   0         0        0                        0            30.025                0.050  (0.384, 0.417)   True
17  sub-800249582                60                   0         0        0                        0            30.042                0.050  (0.384, 0.417)   True
18  sub-800250054                60                   0        37       36                        0            30.025                0.033      (0.4, 0.4)   True
19  sub-803390283                60                   0        69       69                        0            30.025                0.033      (0.4, 0.4)   True
20  sub-811322604                60                   0        55       55                        0            30.025                0.033      (0.4, 0.4)   True
21  sub-813701555                60                   0        87       83                        0            30.025                0.033      (0.4, 0.4)   True
22  sub-817060743                60                   0        86       85                        0            30.025                0.033      (0.4, 0.4)   True
23  sub-820866111                60                   0        55       51                        0            30.025                0.033      (0.4, 0.4)   True
24  sub-821469659                60                   0        61       59                        0            30.025                0.050      (0.4, 0.4)   True
25  sub-827809879                60                   0        53       52                        0            30.025                0.050  (0.384, 0.417)   True
Functional Connectivity sessions with movie frames inside such an interval: ['sub-769319621']
main, good units, invalid movie sessions excluded (code): sessions used 23 of 26; bins per session {75}; fits 1725; median 1.1163, mean 1.1216, SD 0.0585, range 0.921 to 1.320; median in 0.9-1.1: False, in 0.85-1.15: True
main, good units, no invalid exclusion: sessions used 24 of 26; bins per session {75}; fits 1800; median 1.1194, mean 1.1234, SD 0.0583, range 0.921 to 1.320; median in 0.9-1.1: False, in 0.85-1.15: True
variant, Methods criteria alone, invalid movie sessions excluded (code): sessions used 23 of 26; bins per session {75}; fits 1725; median 1.1287, mean 1.1302, SD 0.0574, range 0.935 to 1.321; median in 0.9-1.1: False, in 0.85-1.15: True
variant, Methods criteria alone, no invalid exclusion: sessions used 24 of 26; bins per session {75}; fits 1800; median 1.1309, mean 1.1319, SD 0.0571, range 0.935 to 1.321; median in 0.9-1.1: False, in 0.85-1.15: True

Result: reproduced, resting on the reading of the paper's code for the excluded session. The code's sessions 5, 14 and 43 in AllenSDK's order are sub-718643564 and sub-719828686 (Brain Observatory 1.1) and sub-769319621 (Functional Connectivity), and these are the three sessions of the 58 whose files hold an invalid_times interval tagged "stimulus" that overlaps natural movie one (239 and 954 frames of natural_movie_one_presentations in the two Brain Observatory 1.1 sessions; two other Brain Observatory 1.1 sessions, sub-703279277 and sub-716813540, have such intervals that do not overlap the movie). In sub-769319621, 1497 frames of the 60-repeat movie block fall in that interval, its longest repeat lasts 30.719 s (30.025 s elsewhere, 30.042 s at most) and its longest gap between frames is 0.133 s (0.050 s at most elsewhere). No session has an incomplete repeat. Dropping sub-769319621 and the two sessions without V1 units leaves 23 of 26 sessions, as the paper says, each with 75 bins. With the good units the 1725 pooled slopes have median 1.116: outside 0.9 to 1.1 (reading 1) and inside 0.85 to 1.15 (reading 2); with the Methods' criteria alone, median 1.129, the same under both readings. Keeping sub-769319621 (24 sessions) gives medians 1.119 and 1.131.

Summary¶

All claims here are data: elsewhere: they are tested on the Allen data as deposited in dandisets 000021 and 000022, not on dandiset 000248. Units are those passing the Methods' three criteria and labelled "good", an assumption (header) on which every outcome below rests; the Methods' criteria alone are shown for the unit counts, the slope fits, behavioural state, higher visual areas and the movie data.

Claim Outcome
data-v1-units reproduced (assumed: AllenSDK's default "good" unit label; not within tolerance without it)
fig1b-across-neuron-slope-near-1 reproduced (same assumption; the mean is outside tolerance without it)
fig1b-across-stimulus-slope reproduced (both unit readings)
figs2-behavioral-state reproduced (both unit readings)
figs3-higher-visual-areas reproduced (both unit readings)
figs4ab-noise-correlation-under-manipulation reproduced
fig1d-dimensionality-falls-with-slope reproduced
figs5c-space-occupancy-peak reproduced (the measure is at its ceiling from about 0.6 to 1.0)
fig2a-overlap-rises-with-slope reproduced
fig2c-continuity-from-slope-1 reproduced
fig3bc-geodesic-orthogonal-correlation reproduced
fig3d-correlation-peaks-near-1 reproduced
fig3e-local-alignment-peaks-near-1 reproduced
fig3f-global-alignment-peaks-near-1 reproduced
fig4a-overlap-consistency-within-mice reproduced
fig4c-rsm-similarity-within-mice reproduced
fig4d-overlap-consistency-across-mice reproduced
fig4e-rsm-similarity-across-mice reproduced
figs6-higher-areas-consistency reproduced (reading a, which within sessions does not tell slope 1 from slope 0)
figs5a-movie-slope-near-1 reproduced (assumed: the third excluded session is the one AllenSDK marks invalid, as the paper's code reads; 23 sessions; median 1.116, inside the second reading's window only)
fig2b-decoding-falls-with-slope blocked, too large (run in part in reproduce_kim_2025_decoding.ipynb: as-is and slopes 0 and 1 in 30 sessions, slope 2 in four)
figs4c-shuffling-alters-dependence reproduced (reproduce_kim_2025_decoding.ipynb)
figs1-gain-variance, fig2d-tangent-angle-rises-below-1 blocked: the procedures were not ported within the time of this attempt's runs

How the analysis differs from the paper's: the data are read from the DANDI copies of the Allen release with h5py, not through AllenSDK. The units are those AllenSDK serves by default (the Methods' three criteria and the label "good"); the Methods name only the three criteria. The measures under slope manipulation were not repeated here with the Methods' criteria alone. The slope fits, slope changes, overlap, geodesic distances, orthogonal variance, alignment and RSMs follow the claims file and the paper's code at commit ac3300b, including the code's as-is nearest neighbour for local alignment. The movie sessions are excluded as the paper's code excludes them, by AllenSDK's invalid presentations. The random neuron partitions and trial orders use this attempt's seeds, not the code's np.random.seed(0) sequence.

What was found about the data: the 32 Brain Observatory 1.1 sessions of dandiset 000021 match the paper's 32, the exclusion rule removes the two sessions that the paper's code drops (by position in ascending session id, printed in the data check; this order is AllenSDK's), the sessions per higher visual area match the paper once the Methods' area-specific exclusion removes one RL session (RL 28 without it), and the V1 unit counts and the across-neuron slope match it once AllenSDK's "good" label is applied. In dandiset 000022, the session whose movie presentations overlap an invalid "stimulus" interval (sub-769319621) and the two sessions without V1 units leave the paper's 23. The pupil area in filtered_gaze_mapping is labelled "Pixels ^ 2" but holds values of the order of 0.001 (pooled tertile edges 0.0016 and 0.0026), too small for an area in pixels. Five of the 30 included sessions have no eye tracking.