Reproducing Gillespie et al. (2021) from dandiset 000115¶

Paper. Gillespie AK, Astudillo Maya DA, Denovellis EL, Liu DF, Kastner DB, Coulter ME, Roumis DK, Eden UT, Frank LM (2021). Neuron 109, 3149-3163. doi:10.1016/j.neuron.2021.07.029. The claims file was written from the accepted author manuscript in PubMed Central (PMC8497431) with its Supplemental Information, and from the paper's code (LorenFrankLab/Gillespie_Neuron_2021, commit 1be6a6a).

Dandiset. DANDI:000115, version 0.210914.1732 (doi:10.48324/dandi.000115/0.210914.1732). The paper cites no version, and its code's README links the draft. 0.210914.1732 is the only published version, and it is pinned. The draft (modified 2024-02-22) has the same 57 paths, but 55 of its files differ in content from the published version's (their draft assets were modified in February and March 2022). The data check below compares one of them in detail, written as NWB 2.4.0 in January 2022: the DIO timestamps agree to within a microsecond, but the draft's position timestamps are no longer on the DIO clock, while the published version's are. The published version therefore fits the analysis better as well as being fixed.

What the dandiset holds. One NWB file per recording day for each of four rats (jaq, roquefort, despereaux, montague): the raw 30 kHz broadband of 128 channels, port beam breaks, lights and pumps, head position, and the StateScript log of each epoch, which records every port entry, reward, timeout and the current goal arm. It holds no spike times, LFP, ripple times, linearised position or decoder output. Every replay and ripple claim would have to start from the raw broadband, about 9.1 TB in all.

Questions answered. Two questions on fig1d-sessions-blocks were answered by a reader and the claims file updated. Which jaq sessions are "sessions 1 and 3": the paper does not say, and the criterion now allows (a) the first and third run sessions in order of recording and (b) the two sessions the Methods describe, with (b) deciding when they differ. Which trial closes a block: the first valid trial after each goal change, whatever arm it visits, as the paper's code does. Both claims are re-run below under these rules. After the first verification round, the data check adds a per-session table, the arms entered in the DIO, and trial counts against the legends; fig1ef-reward-rate adds the per-trial values; and the behavioural half of fig6b-visits-decay is computed.

Claims. 33 claims. Two can be tested here, both on behaviour. The other 31 need ripples or the clusterless decoder run on the raw data.

claim tested here
fig1d-sessions-blocks tested
fig1ef-reward-rate tested
figs1c-swr-reward-consumption blocked, too_large (ripple detection on raw broadband)
figs3abc-decode-accuracy, figs3df-goal-arm-no-remapping, figs3g-continuous-fraction, likelihood-decode-same-segment blocked, too_large (clusterless decoding)
fig2f-remote-fraction, fig3a-box-majority, fig3b-search-prevgoal-enriched, fig3b-search-past-depleted, fig3b-search-future-inconsistent, fig3b-search-other, fig3c-repeat-prevgoal blocked, too_large
fig3d-glm-search, fig3e-glm-repeat, fig4ab-current-goal-late, fig4c-current-goal-reward-correlation blocked, too_large
fig5a-future-replay-rate, fig5b-future-correct-error, fig5c-current-goal-correct-error, figs7-early-late-correct-error, figs7e-remote-rate-error, fig5d-glm-predict-chance blocked, too_large
fig6b-visits-decay blocked, too_large (its behavioural half is computed below)
pg-replay-visits-correlation, fig5e-pg-replay-no-avoidance, fig6a-pg-replay-persists, fig6c-pg-replay-two-blocks, fig7-recency, fig8-outer-prevgoal, figs8-outbound-final-events, robustness-controls blocked, too_large
In [1]:
import time
import warnings

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from scipy import stats

import replaytask as rt

pd.set_option("display.width", 220)
pd.set_option("display.max_columns", 40)
pd.set_option("display.max_rows", 200)
warnings.filterwarnings("ignore", category=RuntimeWarning)

started = time.time()
assets = rt.list_assets()
days = rt.load_all(assets)
print(f"loaded {len(days)} files of dandiset {rt.DANDISET_ID} version {rt.DANDISET_VERSION} "
      f"in {time.time() - started:.0f} s")
loaded 57 files of dandiset 000115 version 0.210914.1732 in 358 s

Data check¶

Each check of the metadata against the values is stated under its output.

In [2]:
files = pd.DataFrame([{"subject": d["subject"], "day": d["day"], "session_id": d["session_id"],
                       "date": d["session_start"][:10], "epochs": " ".join(d["tags"]),
                       "run_epochs": len(d["runs"]), "GB": round(d["bytes"] / 1e9, 1),
                       "channels": d["n_channels"], "samples": d["n_samples"],
                       "electrode_location": ",".join(d["electrode_locations"])} for d in days])
files = files.sort_values(["subject", "day"]).reset_index(drop=True)
print("Files, run epochs and size per subject:")
print(files.groupby("subject").agg(files=("day", "size"), run_epochs=("run_epochs", "sum"),
                                   TB=("GB", lambda x: round(x.sum() / 1000, 2))).loc[rt.SUBJECTS].to_string())
print("Total size (TB):", round(files.GB.sum() / 1000, 2), "; assets:", len(assets))
print("\nTask names of the run epochs:", sorted({v[0] + " / " + v[1] for d in days for v in d["tasks"].values() if v[0] != "Sleep"}))
print("Electrode 'location' values over all files:", sorted(set(files.electrode_location)))
print("Channels per file:", sorted(set(files.channels)))
print("\n", files.to_string())
Files, run epochs and size per subject:
            files  run_epochs    TB
subject                            
jaq            13          27  2.05
roquefort      16          32  2.62
despereaux     12          24  1.81
montague       16          33  2.62
Total size (TB): 9.1 ; assets: 57

Task names of the run epochs: ['Eight arm flexible spatial task / goal_delay']
Electrode 'location' values over all files: ['None']
Channels per file: [128]

        subject  day     session_id        date                                     epochs  run_epochs     GB  channels    samples electrode_location
0   despereaux    3  despereaux_03  2019-11-24              01_s1 02_r1 03_s2 04_r2 05_s3           2  152.4       128  470206344               None
1   despereaux    4  despereaux_04  2019-11-25  01_s1 02_r1 03_s2 04_r2 05_s3 06_r3 07_s4           3  199.7       128  616092560               None
2   despereaux    5  despereaux_05  2019-11-26              01_s1 02_r1 03_s2 04_r2 05_s3           2  154.7       128  477280106               None
3   despereaux    6  despereaux_06  2019-11-27              01_s1 02_r1 03_s2 04_r2 05_s3           2  161.4       128  498016380               None
4   despereaux    7  despereaux_07  2019-11-28                          01_s1 02_r1 03_s2           1   89.8       128  277157577               None
5   despereaux    8  despereaux_08  2019-11-29                          01_s1 02_r1 03_s2           1   89.3       128  275431266               None
6   despereaux    9  despereaux_09  2019-11-30              01_s1 02_r1 03_s2 04_r2 05_s3           2  148.9       128  459325677               None
7   despereaux   10  despereaux_10  2019-12-01              01_s1 02_r1 03_s2 04_r2 05_s3           2  152.0       128  469059923               None
8   despereaux   11  despereaux_11  2019-12-02              01_s1 02_r1 03_s2 04_r2 05_s3           2  148.6       128  458444733               None
9   despereaux   12  despereaux_12  2019-12-03              01_s1 02_r1 03_s2 04_r2 05_s3           2  141.4       128  436177538               None
10  despereaux   13  despereaux_13  2019-12-04              01_s1 02_r1 03_s2 04_r2 05_s3           2  155.8       128  480714084               None
11  despereaux   14  despereaux_14  2019-12-05  01_s1 02_r1 03_s2 04_r2 05_s3 06_r3 07_s4           3  218.5       128  674321906               None
12         jaq    6         jaq_06  2019-08-06        01_s1 02_r1 03_s2 04_r2 05_r3 06_s3           3  189.0       128  583095598               None
13         jaq    7         jaq_07  2019-08-07              01_s1 02_r1 03_s2 04_r2 05_s3           2  157.8       128  487017040               None
14         jaq    8         jaq_08  2019-08-08              01_s1 02_r1 03_s2 04_r2 05_s3           2  158.3       128  488390283               None
15         jaq    9         jaq_09  2019-08-09  01_s1 02_r1 03_s2 04_r2 05_s3 06_r3 07_s4           3  189.7       128  585376227               None
16         jaq   10         jaq_10  2019-08-10                          01_s1 02_r1 03_s2           1   90.5       128  279102912               None
17         jaq   11         jaq_11  2019-08-11              01_s1 02_r1 03_s2 04_r2 05_s3           2  161.0       128  496766330               None
18         jaq   12         jaq_12  2019-08-12              01_s1 02_r1 03_s2 04_r2 05_s3           2  155.7       128  480279732               None
19         jaq   13         jaq_13  2019-08-13              01_s1 02_r1 03_s2 04_r2 05_s3           2  160.5       128  495358938               None
20         jaq   14         jaq_14  2019-08-14              01_s1 02_r1 03_s2 04_r2 05_s3           2  158.5       128  489184984               None
21         jaq   15         jaq_15  2019-08-15              01_s1 02_r1 03_s2 04_r2 05_s3           2  163.5       128  504363108               None
22         jaq   16         jaq_16  2019-08-16              01_s1 02_r1 03_s2 04_r2 05_s3           2  160.2       128  494433000               None
23         jaq   17         jaq_17  2019-08-17              01_s1 02_r1 03_s2 04_r2 05_s3           2  159.3       128  491612816               None
24         jaq   18         jaq_18  2019-08-18              01_s1 02_r1 03_s2 04_r2 05_s3           2  149.0       128  459711800               None
25    montague    3    montague_03  2020-07-20  01_s1 02_r1 03_s2 04_r2 05_s3 06_r3 07_s4           3  185.0       128  570716813               None
26    montague    4    montague_04  2020-07-21              01_s1 02_r1 03_s2 04_r2 05_s3           2  147.7       128  455757523               None
27    montague    5    montague_05  2020-07-22              01_s1 02_r1 03_s2 04_r2 05_s3           2  163.6       128  504779827               None
28    montague    6    montague_06  2020-07-23              01_s1 02_r1 03_s2 04_r2 05_s3           2  158.2       128  488257923               None
29    montague    7    montague_07  2020-07-24              01_s1 02_r1 03_s2 04_r2 05_s3           2  160.6       128  495402802               None
30    montague    8    montague_08  2020-07-25              01_s1 02_r1 03_s2 04_r2 05_s3           2  158.2       128  488141621               None
31    montague    9    montague_09  2020-07-26              01_s1 02_r1 03_s2 04_r2 05_s3           2  187.8       128  579407494               None
32    montague   10    montague_10  2020-07-27              01_s1 02_r1 03_s2 04_r2 05_s3           2  161.3       128  497761742               None
33    montague   11    montague_11  2020-07-28              01_s1 02_r1 03_s2 04_r2 05_s3           2  161.0       128  496907850               None
34    montague   12    montague_12  2020-07-29              01_s1 02_r1 03_s2 04_r2 05_s3           2  163.5       128  504480937               None
35    montague   13    montague_13  2020-07-30              01_s1 02_r1 03_s2 04_r2 05_s3           2  160.8       128  496128268               None
36    montague   14    montague_14  2020-07-31              01_s1 02_r1 03_s2 04_r2 05_s3           2  158.5       128  488905211               None
37    montague   15    montague_15  2020-08-01              01_s1 02_r1 03_s2 04_r2 05_s3           2  166.8       128  514536994               None
38    montague   16    montague_16  2020-08-02              01_s1 02_r1 03_s2 04_r2 05_s3           2  165.4       128  510454372               None
39    montague   17    montague_17  2020-08-03              01_s1 02_r1 03_s2 04_r2 05_s3           2  159.9       128  493434810               None
40    montague   18    montague_18  2020-08-04              01_s1 02_r1 03_s2 04_r2 05_s3           2  162.9       128  502728643               None
41   roquefort    7   roquefort_07  2019-10-06              01_s1 02_r1 03_s2 04_r2 05_s3           2  160.8       128  496057775               None
42   roquefort    8   roquefort_08  2019-10-07              01_s1 02_r1 03_s2 04_r2 05_s3           2  159.8       128  492974558               None
43   roquefort    9   roquefort_09  2019-10-08              01_s1 02_r1 03_s2 04_r2 05_s3           2  160.7       128  495971694               None
44   roquefort   10   roquefort_10  2019-10-09              01_s1 02_r1 03_s2 04_r2 05_s3           2  189.8       128  585670023               None
45   roquefort   11   roquefort_11  2019-10-10              01_s1 02_r1 03_s2 04_r2 05_s3           2  163.1       128  503344796               None
46   roquefort   12   roquefort_12  2019-10-11                    01_s1 02_r1 03_s2 04_r2           2  142.6       128  439962790               None
47   roquefort   13   roquefort_13  2019-10-12              01_s1 02_r1 03_s2 04_r2 05_s3           2  171.4       128  528860955               None
48   roquefort   14   roquefort_14  2019-10-13              01_s1 02_r1 03_s2 04_r2 05_s3           2  163.8       128  505296836               None
49   roquefort   15   roquefort_15  2019-10-14              01_s1 02_r1 03_s2 04_r2 05_s3           2  168.0       128  518379298               None
50   roquefort   16   roquefort_16  2019-10-15              01_s1 02_r1 03_s2 04_r2 05_s3           2  161.8       128  499183419               None
51   roquefort   17   roquefort_17  2019-10-16              01_s1 02_r1 03_s2 04_r2 05_s3           2  166.3       128  513092780               None
52   roquefort   18   roquefort_18  2019-10-17              01_s1 02_r1 03_s2 04_r2 05_s3           2  165.9       128  511819449               None
53   roquefort   19   roquefort_19  2019-10-18              01_s1 02_r1 03_s2 04_r2 05_s3           2  162.0       128  499736066               None
54   roquefort   20   roquefort_20  2019-10-19              01_s1 02_r1 03_s2 04_r2 05_s3           2  158.1       128  487665919               None
55   roquefort   21   roquefort_21  2019-10-20              01_s1 02_r1 03_s2 04_r2 05_s3           2  158.4       128  488803206               None
56   roquefort   22   roquefort_22  2019-10-21              01_s1 02_r1 03_s2 04_r2 05_s3           2  164.5       128  507499708               None

The paper used 24, 32, 23 and 33 run sessions after excluding two of subject 1 (26, 32, 23 and 33 before). The files hold 27, 32, 24 and 33 run epochs, all with the task "Eight arm flexible spatial task / goal_delay"; jaq and despereaux have one more than the paper reports. The electrode table gives no location for any channel ("None"), so the CA1 cell-layer tetrodes and the corpus callosum reference tetrode the Methods name cannot be identified from the files.

In [3]:
runs = []
for d in days:
    for r in d["runs"]:
        tr = r["trials"]
        v = tr[~tr.lockout]
        clk = rt.statescript_to_nwb_clock(r)
        runs.append({"subject": d["subject"], "day": d["day"], "epoch": r["epoch_index"], "tag": r["epoch_tag"],
                     "minutes": round(r["duration_min"], 1), "trials": len(tr), "lockout": int(tr.lockout.sum()),
                     "valid": len(v), "rewards_log": int(v.rewarded.sum()), "reward_lines": r["n_outer_reward_lines"],
                     "pumps_dio": len(r["dio_pump_t"]), "arms_visited": v.outer.nunique(),
                     "forageNum": r["forageNum"], "outerReps_setting": r["outerReps_setting"],
                     "outerreps_printed": r["outerreps_printed"],
                     "clock_slope": None if clk is None else clk[0],
                     "clock_median_ms": None if clk is None else round(clk[2], 1),
                     "clock_max_ms": None if clk is None else round(clk[3], 1),
                     "unmatched_pumps": None if clk is None else clk[5],
                     "pos_fs": round(r.get("pos_fs", np.nan), 2), "pos_nan_t": r.get("pos_nan_t"), "pos_nan_tail": r.get("pos_nan_tail"),
                     "pos_nonincreasing": r.get("pos_nonincreasing"), "pos_unit": r.get("pos_unit"),
                     "pos_x_range_m": round(float(np.ptp(r["pos_xy"][:, 0])), 3),
                     "pos_y_range_m": round(float(np.ptp(r["pos_xy"][:, 1])), 3),
                     "sc_hash": r["sc_hash"], "run": r})
runs = pd.DataFrame(runs).sort_values(["subject", "day", "epoch"]).reset_index(drop=True)
runs["session"] = runs.groupby("subject").cumcount() + 1
show = runs.drop(columns=["run", "sc_hash"])
print(show.to_string())
        subject  day  epoch    tag  minutes  trials  lockout  valid  rewards_log  reward_lines  pumps_dio  arms_visited forageNum            outerReps_setting         outerreps_printed  clock_slope  clock_median_ms  clock_max_ms  unmatched_pumps  pos_fs  pos_nan_t  pos_nan_tail  pos_nonincreasing pos_unit  pos_x_range_m  pos_y_range_m  session
0    despereaux    3      2  02_r1     65.6      72        3     69           30            30         30             8         1                           15                    [4, 6]     0.999999              1.5           5.7                0   33.00          1             1                  0   meters          1.142          1.234        1
1    despereaux    3      4  04_r2     92.5     127        5    122           75            75         75             8         1                           15            [8, 9, 11, 12]     1.000000              2.3           6.9                0   33.00          1             1                  0   meters          1.182          1.216        2
2    despereaux    4      2  02_r1     91.4     139        7    132           54            54         54             8       NaN                          NaN                   [8, 12]     1.000000              2.2           5.9                0   32.93          2             2                  0   meters          1.210          1.214        3
3    despereaux    4      4  04_r2     39.2      50        2     48           29            29         29             8         1                           10                    [6, 8]     0.999996              2.5          10.8                0   32.97          2             2                  0   meters          1.148          1.166        4
4    despereaux    4      6  06_r3     90.2     105        1    104           45            45         45             8         1                           10              [4, 6, 7, 8]     1.000000              2.6          16.3                0   32.97          0             0                  0   meters          1.198          1.264        5
5    despereaux    5      2  02_r1     85.1     102        2    100           40            40         40             8         1                           10             [4, 8, 9, 12]     1.000000              1.7           4.5                0   32.93          2             2                  0   meters          1.204          1.204        6
6    despereaux    5      4  04_r2     60.5      77        0     77           40            40         40             8         1                           10            [5, 6, 10, 12]     1.000000              2.5          17.2                0   32.97          3             3                  0   meters          1.202          1.190        7
7    despereaux    6      2  02_r1     90.2     132        2    130           50            50         50             8         1  np.random.randint(4,13) #10      [5, 6, 8, 9, 11, 12]     0.999999              2.3          12.2                0   32.93          2             2                  0   meters          1.196          1.206        8
8    despereaux    6      4  04_r2     90.2     100        3     97           25            25         25             8         1  np.random.randint(4,13) #10            [6, 9, 11, 12]     1.000000              2.7           5.4                0   32.97          2             2                  0   meters          1.156          1.298        9
9    despereaux    7      2  02_r1     92.1     115        0    115           54            54         54             8         1  np.random.randint(4,13) #10            [4, 9, 10, 11]     1.000000              2.1           6.3                0   32.97          2             2                  0   meters          1.152          1.250       10
10   despereaux    8      2  02_r1     90.3     118        1    117           48            48         48             8         1  np.random.randint(4,13) #10          [4, 5, 7, 8, 12]     1.000000              3.0           9.6                0   33.00          3             3                  0   meters          1.158          1.246       11
11   despereaux    9      2  02_r1     90.5     106        1    105           36            36         36             8         1  np.random.randint(4,13) #10  [4, 5, 8, 9, 10, 11, 12]     1.000000              2.6           7.0                0   32.89          0             0                  0   meters          1.142          1.212       12
12   despereaux    9      4  04_r2     71.0      91        0     91           36            36         36             8         1  np.random.randint(4,13) #10             [4, 8, 9, 10]     1.000001              2.7           7.4                0   32.89          3             3                  0   meters          1.080          1.188       13
13   despereaux   10      2  02_r1     80.8      93        0     93           40            40         40             8         1  np.random.randint(4,13) #10         [5, 6, 7, 10, 12]     1.000001              2.3          10.6                0   32.89          3             3                  0   meters          1.148          1.258       14
14   despereaux   10      4  04_r2     81.8      66        1     65           41            41         41             8         1  np.random.randint(4,13) #10                [7, 9, 12]     1.000001              2.9          14.1                0   32.89          3             3                  0   meters          1.132          1.188       15
15   despereaux   11      2  02_r1     79.5      57        1     56           27            27         27             8         1  np.random.randint(4,13) #10                    [6, 9]     1.000001              2.5           5.8                0   32.93          3             3                  0   meters          1.194          1.206       16
16   despereaux   11      4  04_r2     78.4      69        1     68           29            29         29             8         1  np.random.randint(4,13) #10               [6, 10, 11]     1.000000              2.1           6.2                0   32.97          3             3                  0   meters          1.208          1.190       17
17   despereaux   12      2  02_r1     90.1      78        1     77           27            27         27             8         1  np.random.randint(4,13) #10                   [6, 12]     1.000000              2.8          12.2                0   32.93          2             2                  0   meters          1.196          1.252       18
18   despereaux   12      4  04_r2     57.5      35        0     35           16            16         16             7         1  np.random.randint(4,13) #10                       [8]     0.999998              2.4          14.4                0   32.93          4             4                  0   meters          1.198          1.214       19
19   despereaux   13      2  02_r1     90.2      77        1     76           40            40         40             8         1  np.random.randint(4,13) #10               [8, 10, 11]     1.000000              2.9           8.9                0   32.93          1             1                  0   meters          1.198          1.230       20
20   despereaux   13      4  04_r2     86.3      59        0     59           36            36         36             8         1  np.random.randint(4,13) #10                 [4, 8, 9]     1.000000              2.1           6.1                0   32.93          2             2                  0   meters          1.142          1.202       21
21   despereaux   14      2  02_r1     90.0      58        0     58           32            32         32             7         1  np.random.randint(4,13) #10               [5, 10, 12]     1.000000              2.4           5.4                0   32.93          2             2                  0   meters          1.154          1.266       22
22   despereaux   14      4  04_r2     54.5      25        1     24           10            10         10             7         1  np.random.randint(4,13) #10                       [4]     0.999999              1.3           3.5                0   32.93          2             2                  0   meters          1.198          1.198       23
23   despereaux   14      6  06_r3     91.9      86        1     85           39            39         39             8         1  np.random.randint(4,13) #10            [5, 6, 10, 12]     1.000000              2.6          16.3                0   32.89          2             2                  0   meters          1.194          1.208       24
24          jaq    6      2  02_r1     90.9     119       12    107           46            46         46             8       NaN                          NaN                      [15]     1.000000              1.9           6.2                0   33.04          3             3                  0   meters          1.208          1.198        1
25          jaq    6      4  04_r2     44.0      71        5     66           30            30         31             7         1                           15                      [15]     1.000000              1.9           8.2                1   33.04          3             3                  0   meters          1.206          1.244        2
26          jaq    6      5  05_r3     91.8     117        7    110           65            65         65             8         1                           15                      [15]     1.000000              2.6          17.3                0   33.00          3             3                  0   meters          1.196          1.202        3
27          jaq    7      2  02_r1     90.1      98       24     74            6             6          6             8         1                           15                        []     1.000002              1.5           5.4                0   33.04          2             2                  0   meters          1.208          1.188        4
28          jaq    7      4  04_r2     90.2     116        9    107           49            49         49             8         1                           15                      [15]     1.000000              2.1           9.9                0   33.04          3             3                  0   meters          1.204          1.246        5
29          jaq    8      2  02_r1     90.5     106        5    101           45            45         45             8         1                           15                      [15]     1.000000              2.5           8.9                0   33.04          3             3                  0   meters          1.208          1.196        6
30          jaq    8      4  04_r2     90.4      97        3     94           50            50         50             8         1                           15                      [15]     1.000000              2.5           5.4                0   33.04          2             2                  0   meters          1.200          1.246        7
31          jaq    9      2  02_r1     91.4      91        9     82           44            44         44             8         1                           15                      [15]     1.000000              2.6           8.9                0   33.00          3             3                  0   meters          1.136          1.234        8
32          jaq    9      4  04_r2     64.6      77        4     73           45            45         45             8         1                           15                      [15]     1.000001              2.4          14.4                0   33.00          3             3                  0   meters          1.206          1.206        9
33          jaq    9      6  06_r3     33.9      38        2     36           16            16         16             8         1                           15                      [15]     0.999995              2.5           4.4                0   33.00          0             0                  0   meters          1.174          1.248       10
34          jaq   10      2  02_r1     90.1      99       13     86           40            40         40             8         1                           10                      [10]     1.000000              2.2           6.9                0   33.00          3             3                  0   meters          1.188          1.198       11
35          jaq   11      2  02_r1     91.3     120       15    105           54            54         54             8         1                           10                      [10]     1.000000              2.8          20.6                0   33.00          2             2                  0   meters          1.200          1.254       12
36          jaq   11      4  04_r2     79.9      89       12     77           40            40         40             8         1                           10                      [10]     1.000001              2.2           7.6                0   33.00          2             2                  0   meters          1.200          1.174       13
37          jaq   12      2  02_r1     90.1     119       14    105           57            57         57             8         1                           10                      [10]     1.000000              2.1          17.4                0   33.00          2             2                  0   meters          1.192          1.232       14
38          jaq   12      4  04_r2     90.2     110       19     91           24            24         24             8         1                           10                      [10]     1.000000              1.6           5.2                0   33.04          2             2                  0   meters          1.188          1.216       15
39          jaq   13      2  02_r1     90.4     108       20     88           47            47         47             8       NaN                          NaN                      [10]     1.000000              2.0           6.6                0   33.04          3             3                  0   meters          1.202          1.244       16
40          jaq   13      4  04_r2     90.1      74        7     67           31            31         31             8         1                           10                      [10]     1.000000              2.8           5.1                0   33.04          2             2                  0   meters          1.136          1.232       17
41          jaq   14      2  02_r1     90.0      91       14     77           35            35         35             8       NaN                          NaN                      [10]     0.999999              2.8          12.3                0   33.04          1             1                  0   meters          1.158          1.270       18
42          jaq   14      4  04_r2     90.2     104       10     94           42            42         42             8         1                           10                      [10]     1.000000              2.8           5.8                0   33.04          3             3                  0   meters          1.206          1.184       19
43          jaq   15      2  02_r1     90.1     112       14     98           51            51         51             8       NaN                          NaN                      [10]     1.000000              2.6          17.1                0   33.00          4             4                  0   meters          1.200          1.250       20
44          jaq   15      4  04_r2     92.4     108        7    101           40            40         40             8         1                           10                      [10]     1.000000              2.0           6.2                0   33.00          2             2                  0   meters          1.194          1.172       21
45          jaq   16      2  02_r1     90.6      86       17     69           31            31         31             8         1                           10                      [10]     1.000000              3.3          13.8                0   33.00          2             2                  0   meters          1.128          1.174       22
46          jaq   16      4  04_r2     92.3      73        3     70           36            36         36             8         1                           10                      [10]     1.000000              2.4           5.9                0   33.00          2             2                  0   meters          1.188          1.254       23
47          jaq   17      2  02_r1     90.3     110        4    106           30            30         30             8         1                           10                      [10]     1.000000              2.9           6.6                0   33.00          1             1                  0   meters          1.182          1.218       24
48          jaq   17      4  04_r2     90.5      76        5     71           20            20         20             8         1                           10                      [10]     1.000000              2.6          15.7                0   33.00          3             3                  0   meters          1.190          1.242       25
49          jaq   18      2  02_r1     59.1      49        2     47           22            22         22             8         1                           10                      [10]     0.999998              2.4          10.4                0   33.04          1             1                  0   meters          1.188          1.248       26
50          jaq   18      4  04_r2     92.9      95        3     92           48            48         48             8         1                           10                      [10]     1.000000              2.0           6.0                0   33.04          3             3                  0   meters          1.138          1.180       27
51     montague    3      2  02_r1     90.1      93       22     71           37            37         37             7         1                           15                      [15]     1.000000              1.7           5.5                0   32.89          2             2                  0   meters          1.162          1.192        1
52     montague    3      4  04_r2     75.9      65        6     59           30            30         30             8         1                           15                      [15]     1.000001              2.7           6.5                0   32.89          1             1                  0   meters          1.194          1.200        2
53     montague    3      6  06_r3     31.8      29        3     26           15            15         15             6         1                           15                      [15]     1.000002              2.1           4.3                0   32.89          1             1                  0   meters          1.208          1.192        3
54     montague    4      2  02_r1     90.6      77        9     68           34            34         34             8         1                           15                      [15]     1.000000              2.7           7.1                0   32.89          1             1                  0   meters          1.206          1.200        4
55     montague    4      4  04_r2     70.2      52        5     47           35            35         35             7         1                           15                      [15]     1.000000              2.4          11.2                0   32.89          0             0                  0   meters          1.174          1.182        5
56     montague    5      2  02_r1     94.1     112       13     99           50            50         50             8         1                           10                      [10]     1.000000              2.4          15.5                0   32.89          0             0                  0   meters          1.162          1.184        6
57     montague    5      4  04_r2     90.0     118        7    111           66            66         66             8         1                           10                      [10]     1.000000              2.4           7.0                0   32.89          3             3                  0   meters          1.148          1.204        7
58     montague    6      2  02_r1     90.1     104       21     83           30            30         30             8         1                           10                      [10]     1.000000              1.8           4.9                0   32.93          4             4                  0   meters          1.150          1.188        8
59     montague    6      4  04_r2     90.6     100       18     82           40            40         40             8         1                           10                      [10]     1.000000              3.1           6.6                0   32.89          1             1                  0   meters          1.142          1.200        9
60     montague    7      2  02_r1     91.4     114       19     95           51            51         51             8         1                           10                      [10]     1.000000              2.4          13.7                0   32.97          3             3                  0   meters          1.196          1.176       10
61     montague    7      4  04_r2     90.2     105       11     94           40            40         40             8         1                           10                      [10]     1.000000              2.3          14.7                0   32.97          3             3                  0   meters          1.190          1.254       11
62     montague    8      2  02_r1     90.5     104        7     97           43            43         43             8         1                           10                      [10]     1.000000              3.0          10.6                0   32.97          1             1                  0   meters          1.156          1.192       12
63     montague    8      4  04_r2     90.1     104        6     98           35            35         35             8         1                           10                      [10]     1.000000              3.0           7.2                0   32.97          2             2                  0   meters          1.160          1.170       13
64     montague    9      2  02_r1     90.8     107        7    100           52            52         52             8         1  np.random.randint(4,13) #10                       [7]     0.999999              2.5          13.3                0   32.89          2             2                  0   meters          1.242          1.182       14
65     montague    9      4  04_r2     81.8      80        2     78           30            30         30             8         1  np.random.randint(4,13) #10                       [6]     0.999999              2.8           9.3                0   32.93          3             3                  0   meters          1.186          1.198       15
66     montague   10      2  02_r1     90.2      55        0     55           32            32         32             7         1  np.random.randint(4,13) #10                      [11]     1.000000              1.7           5.5                0   32.89          3             3                  0   meters          1.142          1.184       16
67     montague   10      4  04_r2     92.7      90        4     86           35            35         35             8         1  np.random.randint(4,13) #10                       [7]     1.000000              2.0          11.1                0   32.89          3             3                  0   meters          1.184          1.170       17
68     montague   11      2  02_r1     90.3     106        6    100           56            56         56             8         1  np.random.randint(4,13) #10                       [9]     1.000000              2.5           6.4                0   32.93          2             2                  0   meters          1.146          1.180       18
69     montague   11      4  04_r2     90.1     120        5    115           42            42         42             8         1  np.random.randint(4,13) #10                       [6]     1.000000              2.2           5.7                0   32.93          3             3                  0   meters          1.150          1.200       19
70     montague   12      2  02_r1     90.3     101        8     93           49            49         49             8         1  np.random.randint(4,13) #10                       [7]     1.000000              2.5          16.1                0   32.93          3             3                  0   meters          1.144          1.178       20
71     montague   12      4  04_r2     91.1     112        7    105           54            54         54             8         1  np.random.randint(4,13) #10                       [9]     1.000000              2.4          13.8                0   32.93          3             3                  0   meters          1.196          1.192       21
72     montague   13      2  02_r1     91.9     108        4    104           55            55         55             8         1  np.random.randint(4,13) #10                       [5]     1.000000              2.2          13.5                0   32.89          2             2                  0   meters          1.144          1.182       22
73     montague   13      4  04_r2     93.4     113        3    110           61            61         61             8         1  np.random.randint(4,13) #10                      [10]     1.000000              2.8           7.8                0   32.93          1             1                  0   meters          1.148          1.228       23
74     montague   14      2  02_r1     90.1     113        5    108           49            49         49             8         1  np.random.randint(4,13) #10                       [7]     1.000000              2.7          22.9                0   32.93          3             3                  0   meters          1.096          1.184       24
75     montague   14      4  04_r2     90.4     118        3    115           40            40         40             8         1  np.random.randint(4,13) #10                       [4]     1.000001              2.2           9.6                0   32.93          1             1                  0   meters          1.154          1.188       25
76     montague   15      2  02_r1     90.1     100        3     97           67            67         67             8         1  np.random.randint(4,13) #10                      [12]     1.000000              3.0          15.2                0   32.97          3             3                  0   meters          1.162          1.178       26
77     montague   15      4  04_r2     90.7      90        1     89           48            48         48             8         1  np.random.randint(4,13) #10                       [6]     1.000000              2.9          14.7                0   32.97          3             3                  0   meters          1.152          1.184       27
78     montague   16      2  02_r1     91.4      88        1     87           44            44         44             8         1  np.random.randint(4,13) #10                      [11]     0.999604            512.8        5426.3                0   32.93          3             3                200   meters          1.158          1.154       28
79     montague   16      4  04_r2     92.8      94        1     93           35            35         35             8         1  np.random.randint(4,13) #10                       [7]     1.000001              2.0          10.6                0   32.93          3             3                  0   meters          1.192          1.172       29
80     montague   17      2  02_r1     91.1      77        5     72           35            35         35             8         1  np.random.randint(4,13) #10                       [8]     1.000000              2.5          11.7                0   32.93          2             2                  0   meters          1.192          1.186       30
81     montague   17      4  04_r2     90.4      90        1     89           55            55         55             6         1  np.random.randint(4,13) #10                      [11]     1.000000              2.6          13.7                0   32.93          3             3                  0   meters          1.180          1.202       31
82     montague   18      2  02_r1     90.3      77        5     72           32            32         32             8         1  np.random.randint(4,13) #10                       [6]     1.000000              1.8           6.0                0   32.97          1             1                  0   meters          1.154          1.196       32
83     montague   18      4  04_r2     90.6      61        2     59           16            16         16             7         1  np.random.randint(4,13) #10                      [10]     1.000002              2.3          11.8                0   32.93          3             3                  0   meters          1.162          1.174       33
84    roquefort    7      2  02_r1     90.1     123        3    120           34            34         34             8         1                           15                   [6, 11]     1.000000              2.5           6.6                0   32.97          2             2                  0   meters          1.196          1.164        1
85    roquefort    7      4  04_r2     90.7     114       10    104           30            30         30             8         1                           15                       [7]     0.999996              2.0           5.4                0   33.00          3             3                  0   meters          1.156          1.172        2
86    roquefort    8      2  02_r1     91.2     107        9     98           45            45         45             8         1                           15               [6, 11, 12]     1.000000              2.2           6.0                0   32.89          3             3                  0   meters          1.172          1.168        3
87    roquefort    8      4  04_r2     90.3     107        2    105           46            46         46             8         1                           15                [4, 5, 12]     0.999998              2.1          13.1                0   33.00          1             1                  0   meters          1.146          1.168        4
88    roquefort    9      2  02_r1     90.2     117        3    114           45            45         45             8         1                           15                  [11, 12]     1.000000              2.5          12.7                0   33.00          2             2                  0   meters          1.102          1.174        5
89    roquefort    9      4  04_r2     90.6      99        5     94           30            30         30             8         1                           15                  [10, 12]     1.000000              2.8           5.1                0   33.00          1             1                  0   meters          1.198          1.178        6
90    roquefort   10      2  02_r1     91.0      89        8     81           30            30         30             8         1                           10                   [9, 11]     1.000000              2.9           7.0                0   32.89          1             1                  0   meters          1.146          1.170        7
91    roquefort   10      4  04_r2     91.1      98        2     96           46            46         46             8         1                           15               [8, 11, 12]     0.999998              2.4           6.1                0   32.89          3             3                  0   meters          1.156          1.182        8
92    roquefort   11      2  02_r1     90.4      91        2     89           33            33         33             8         1                           15                    [6, 9]     0.999998              2.0           6.2                0   32.89          4             4                  0   meters          1.174          1.184        9
93    roquefort   11      4  04_r2     90.5      91        4     87           46            46         46             8         1                           15                   [8, 11]     0.999997              2.1           6.0                0   32.89          2             2                  0   meters          1.198          1.166       10
94    roquefort   12      2  02_r1     90.0      92        1     91           30            30         30             8         1                           15                   [8, 10]     0.999997              2.9           6.6                0   32.89          3             3                  0   meters          1.116          1.186       11
95    roquefort   12      4  04_r2     90.9      88        2     86           31            31         31             8         1                           15                    [7, 9]     0.999996              3.0           6.5                0   32.89          2             2                  0   meters          1.188          1.158       12
96    roquefort   13      2  02_r1     90.2      96        5     91           46            46         46             8         1                           15                    [8, 9]     1.000000              2.6           7.1                0   32.93          3             3                  0   meters          1.136          1.172       13
97    roquefort   13      4  04_r2     91.1      81        2     79           15            15         15             8         1                           15                      [12]     1.000001              2.3           6.4                0   32.89          1             1                  0   meters          1.136          1.172       14
98    roquefort   14      2  02_r1     90.5      86        4     82           45            45         45             8         1                           15               [4, 11, 12]     1.000000              2.3           6.4                0   32.93          3             3                  0   meters          1.196          1.162       15
99    roquefort   14      4  04_r2     89.6      68        2     66           32            32         32             8         1                           15                       [5]     1.000000              2.4           6.1                0   32.93          2             2                  0   meters          1.122          1.168       16
100   roquefort   15      2  02_r1     93.3      83        0     83           45            45         45             8         1                           15               [4, 10, 12]     0.999999              2.5           7.9                0   32.93          2             2                  0   meters          1.100          1.178       17
101   roquefort   15      4  04_r2     90.7      75        2     73           20            20         20             8         1                           10                    [4, 5]     1.000000              2.4           4.4                0   32.93          3             3                  0   meters          1.154          1.182       18
102   roquefort   16      2  02_r1     90.1      79        2     77           36            36         36             8         1                           10                [4, 5, 11]     1.000000              2.7           8.8                0   32.93          3             3                  0   meters          1.204          1.168       19
103   roquefort   16      4  04_r2     90.5      67        2     65           20            20         20             8         1                           10                   [7, 12]     1.000000              2.2           6.2                0   32.89          4             4                  0   meters          1.152          1.212       20
104   roquefort   17      2  02_r1     90.1      75        0     75           31            31         31             8         1                           10               [9, 10, 11]     1.000000              2.0           8.6                0   32.89          2             2                  0   meters          1.138          1.222       21
105   roquefort   17      4  04_r2    103.1      70        2     68           40            40         40             7         1                           10             [4, 8, 9, 11]     0.999998              2.4           9.5                0   32.93          2             2                  0   meters          1.144          1.188       22
106   roquefort   18      2  02_r1     90.4      79        4     75           31            31         31             8         1                           10                 [4, 5, 9]     1.000002              2.8           8.5                0   32.89          1             1                  0   meters          1.132          1.174       23
107   roquefort   18      4  04_r2     90.5      83        5     78           38            38         38             8         1                           10                 [4, 6, 7]     1.000000              2.1           5.9                0   32.89          1             1                  0   meters          1.142          1.188       24
108   roquefort   19      2  02_r1     92.2      86        3     83           30            30         30             8         1                           10                [7, 9, 11]     1.000000              2.6           6.8                0   32.89          4             4                  0   meters          1.190          1.190       25
109   roquefort   19      4  04_r2     91.1      77        5     72           20            20         20             8         1                           10                   [5, 11]     0.999999              2.0           6.3                0   32.89          0             0                  0   meters          1.188          1.164       26
110   roquefort   20      2  02_r1     90.0      72        1     71           30            30         30             8         1                           10                   [8, 10]     1.000000              2.9           6.3                0   32.89          2             2                  0   meters          1.110          1.186       27
111   roquefort   20      4  04_r2     90.1      72        1     71           30            30         30             8         1                           10                   [8, 12]     0.999999              1.8           6.4                0   32.89          4             4                  0   meters          1.148          1.168       28
112   roquefort   21      2  02_r1     90.0      47        2     45           26            26         26             7         1                           10                   [8, 11]     0.999999              3.6           5.7                0   32.89          1             1                  1   meters          1.148          1.200       29
113   roquefort   21      4  04_r2     90.0      43        1     42           20            20         20             7         1                           10                    [6, 8]     0.999998              2.0           6.8                0   32.89          3             3                  0   meters          1.166          1.174       30
114   roquefort   22      2  02_r1     91.5      56        3     53           11            11         11             8         1                           10                       [4]     1.000000              3.3           5.9                0   32.89          2             2                  0   meters          1.194          1.176       31
115   roquefort   22      4  04_r2     91.2      44        1     43           26            26         26             8         1                           10                    [4, 7]     1.000000              2.7           6.7                0   32.89          2             2                  0   meters          1.152          1.222       32
In [4]:
print("Run epochs per subject:", runs.groupby("subject").size().loc[rt.SUBJECTS].to_dict())
print("Epoch length (min): median", runs.minutes.median(), "range", runs.minutes.min(), "to", runs.minutes.max(),
      "(Methods: 45 to 90 min)")
print("forageNum values (forage assist when above 1):", runs.forageNum.fillna("not in log header").value_counts().to_dict())
print("outerReps settings:", runs.outerReps_setting.fillna("not in log header").value_counts().to_dict())
print("\nValid (non-timeout) trials per subject:", runs.groupby("subject").valid.sum().loc[rt.SUBJECTS].to_dict())
print("Timeout trials per subject:", runs.groupby("subject").lockout.sum().loc[rt.SUBJECTS].to_dict())
print("\nLogged rewards equal 'outer reward' lines in", int((runs.rewards_log == runs.reward_lines).sum()), "of", len(runs), "epochs")
print("Logged rewards equal DIO pump onsets in", int((runs.rewards_log == runs.pumps_dio).sum()), "of", len(runs), "epochs")
print(runs.loc[runs.rewards_log != runs.pumps_dio, ["subject", "day", "epoch", "rewards_log", "pumps_dio", "unmatched_pumps"]].to_string())
# Rewarded only when the visited arm is the goal the log printed for that trial
allv = pd.concat([r["trials"][~r["trials"].lockout] for r in runs.run])
print("\nRewarded exactly when the visited arm is the printed goal:", bool((allv.rewarded == (allv.outer == allv.goal)).all()),
      f"({len(allv)} trials)")
# Rewards per completed block against the programmed number
comp = []
for _, row in runs.iterrows():
    lab = rt.label_task_phase(row.run["trials"])
    for k in lab.block.unique():
        b = lab[lab.block == k]
        if b.final.any():
            comp.append({"subject": row.subject, "rewards": int(b.rewarded[~b.final].sum())})
comp = pd.DataFrame(comp)
print("\nRewards per completed block (Methods: 15, then 10, then 4 to 12 for two subjects):")
print(pd.crosstab(comp.subject, comp.rewards).loc[rt.SUBJECTS].to_string())
Run epochs per subject: {'jaq': 27, 'roquefort': 32, 'despereaux': 24, 'montague': 33}
Epoch length (min): median 90.3 range 31.8 to 103.1 (Methods: 45 to 90 min)
forageNum values (forage assist when above 1): {'1': 111, 'not in log header': 5}
outerReps settings: {'10': 42, 'np.random.randint(4,13) #10': 37, '15': 32, 'not in log header': 5}

Valid (non-timeout) trials per subject: {'jaq': 2294, 'roquefort': 2557, 'despereaux': 2003, 'montague': 2857}
Timeout trials per subject: {'jaq': 259, 'roquefort': 98, 'despereaux': 34, 'montague': 220}

Logged rewards equal 'outer reward' lines in 116 of 116 epochs
Logged rewards equal DIO pump onsets in 115 of 116 epochs
   subject  day  epoch  rewards_log  pumps_dio  unmatched_pumps
25     jaq    6      4           30         31                1

Rewarded exactly when the visited arm is the printed goal: True (9711 trials)
Rewards per completed block (Methods: 15, then 10, then 4 to 12 for two subjects):
rewards     3   4   5   6   7   8   9   10  11  12  15
subject                                               
jaq          0   0   0   0   0   0   1  58   0   0  24
roquefort    0   0   0   0   0   0   0  41   0   0  39
despereaux   0  10   7   4  29   6   4  24   5   5   7
montague     1  10  10  25  31   4  12  41  11   5   9

Trials are rebuilt from the StateScript log (see replaytask.py). In every one of the 116 run epochs, the logged rewards equal the log's own outer reward lines, and a trial is rewarded exactly when the visited arm is the goal printed for that trial. The logged rewards equal the reward pump onsets of the DIO channels in 115 epochs. In jaq day 6 epoch 4 the DIO has one more pump (arm 8), with no log line, 226 s after the last logged reward and 40 s after the last logged trial (both printed in the per-session check below), so the log appears to stop before the epoch ends. The number of rewards per completed block is a programmed value (15 and 10, and 4 to 12 for despereaux and montague, as the Methods and Supplementary Figure 1A say) in all blocks but two, jaq with 9 and montague with 3; the per-session check below explains both. forageNum is 1 in the 111 logs whose header holds it; five logs carry no Python header, and the per-session check below tests them for forage assist from the log lines.

In [5]:
print("StateScript clock to NWB clock, fit on rewarded entries against DIO pump onsets:")
print("slope range:", runs.clock_slope.min(), "to", runs.clock_slope.max())
print("median residual per epoch (ms): median", runs.clock_median_ms.median(), "max", runs.clock_median_ms.max())
print("largest residual per epoch (ms): median", runs.clock_max_ms.median(), "; epochs above 50 ms:")
print(runs.loc[runs.clock_max_ms > 50, ["subject", "day", "epoch", "clock_median_ms", "clock_max_ms"]].to_string())
bad = runs.loc[runs.clock_max_ms > 50].iloc[0].run
tr = bad["trials"]
rt_s = tr[tr.rewarded & ~tr.lockout].t_ms.to_numpy() / 1000
print("Interval differences between consecutive rewards, log minus DIO (s), in that epoch:",
      np.round(np.diff(rt_s) - np.diff(bad["dio_pump_t"]), 2)[:8], "...")

# Position against DIO beam breaks: decode the poked arm from position at the beam break
acc = []
for _, row in runs.iterrows():
    a0, n = rt.arm_from_position(row.run, 0.0)
    a1, _ = rt.arm_from_position(row.run, -20.0)
    a2, _ = rt.arm_from_position(row.run, 20.0)
    acc.append({"subject": row.subject, "acc_0s": a0, "acc_minus20s": a1, "acc_plus20s": a2, "entries": n})
acc = pd.DataFrame(acc)
print("\nPoked arm decoded from head position at the DIO beam break (leave-one-out nearest centroid; chance about 0.125):")
print(acc.groupby("subject")[["acc_0s", "acc_minus20s", "acc_plus20s"]].median().loc[rt.SUBJECTS].round(3).to_string())
print("epochs:", len(acc), "; outer beam breaks per epoch: median", acc.entries.median(),
      "; lowest accuracy at 0 s:", round(acc.acc_0s.min(), 3))
StateScript clock to NWB clock, fit on rewarded entries against DIO pump onsets:
slope range: 0.9996037059004799 to 1.0000024541649737
median residual per epoch (ms): median 2.4 max 512.8
largest residual per epoch (ms): median 7.0 ; epochs above 50 ms:
     subject  day  epoch  clock_median_ms  clock_max_ms
78  montague   16      2            512.8        5426.3
Interval differences between consecutive rewards, log minus DIO (s), in that epoch: [ 3.41 -0.01 -0.    3.42 -0.    0.   -0.   -0.  ] ...
Poked arm decoded from head position at the DIO beam break (leave-one-out nearest centroid; chance about 0.125):
            acc_0s  acc_minus20s  acc_plus20s
subject                                      
jaq            1.0         0.230        0.186
roquefort      1.0         0.216        0.236
despereaux     1.0         0.173        0.192
montague       1.0         0.194        0.187
epochs: 116 ; outer beam breaks per epoch: median 747.5 ; lowest accuracy at 0 s: 0.986

The StateScript times map onto the NWB clock with a slope of 1 and a median residual of a few milliseconds, so the trial table and the DIO events share one clock. In montague day 16 epoch 2 the log's clock steps by about 3.4 s twice against the DIO early in the epoch; the trials are unaffected because the analysis uses their order, not their times. Head position at the moment of each outer-port beam break identifies the arm, while position taken 20 s earlier or later does not, so position and the DIO share a clock. The raw broadband is not used here; its timestamps are checked only for the span below.

In [6]:
pos = runs[["subject", "pos_fs", "pos_nan_t", "pos_nan_tail", "pos_nonincreasing", "pos_unit", "pos_x_range_m", "pos_y_range_m"]]
print("Position: unit", pos.pos_unit.unique().tolist(), "; sampling rate (Hz)", pos.pos_fs.min(), "to", pos.pos_fs.max(),
      "(Methods: 30 Hz)")
print("x range (m):", pos.pos_x_range_m.min(), "to", pos.pos_x_range_m.max(), "; y range (m):",
      pos.pos_y_range_m.min(), "to", pos.pos_y_range_m.max())
print("Epochs with NaN position timestamps:", int((pos.pos_nan_t > 0).sum()), "of", len(pos), "; NaN timestamps per epoch up to",
      int(pos.pos_nan_t.max()))
nanpos = pos[pos.pos_nan_t > 0]
print("  of these, epochs whose NaN timestamps are all at the end of the series:", int((nanpos.pos_nan_tail == nanpos.pos_nan_t).sum()),
      "; NaN timestamps elsewhere in the series, over all epochs:", int((pos.pos_nan_t - pos.pos_nan_tail).sum()))
print("Epochs with non-increasing position timestamps:", int((pos.pos_nonincreasing > 0).sum()), "; most in one epoch:",
      int(pos.pos_nonincreasing.max()))
print("\nRun epochs whose StateScript log is identical to another's:", int(runs.sc_hash.duplicated().sum()))
ephys = pd.DataFrame([{"subject": d["subject"], "day": d["day"], "samples": d["n_samples"],
                       "span_s": d["ephys_t1"] - d["ephys_t0"], "chunks": str(d["ephys_chunks"]),
                       "conversion": d["ephys_conversion"]} for d in days])
ephys["rate_over_span"] = ephys.samples / ephys.span_s
print("Raw broadband: chunk shapes", ephys.chunks.unique().tolist(), "; conversion to volts", ephys.conversion.unique().tolist())
print("samples / time span (Hz): median", round(ephys.rate_over_span.median()), "range",
      round(ephys.rate_over_span.min()), "to", round(ephys.rate_over_span.max()),
      "(30 kHz with the gaps between epochs inside the span)")
ephys["epoch_seconds"] = [d["epoch_seconds"] for d in days]
ephys["samples_over_epoch_time"] = ephys.samples / ephys.epoch_seconds
print("samples / summed epoch durations (Hz): median", round(ephys.samples_over_epoch_time.median()), "range",
      round(ephys.samples_over_epoch_time.min()), "to", round(ephys.samples_over_epoch_time.max()))
print("Recorded hours of raw broadband at 30 kHz:", round(ephys.samples.sum() / 30000 / 3600, 1))

# Pinned version against the draft: content digests of every asset, then one file in detail
ver = rt.compare_versions()
print("\nAssets of the pinned version:", len(ver), "; same path in the draft:", int(ver.in_draft.sum()),
      "; content (SHA-256) differs in the draft:", int(ver.content_differs.sum()))
print("Draft modification month of the assets that differ:",
      ver[ver.content_differs].draft_modified.str[:7].value_counts().sort_index().to_dict(),
      "; of those that do not:", ver[~ver.content_differs].draft_modified.str[:7].value_counts().sort_index().to_dict())
cmp = rt.compare_with_draft("sub-montague/sub-montague_ses-montague-04_behavior+ecephys.nwb")
pub, dr = cmp[rt.DANDISET_VERSION], cmp["draft"]
print("\nmontague day 4, pinned version against draft:")
for v in (rt.DANDISET_VERSION, "draft"):
    print(f"  {v}: NWB {cmp[v]['nwb_version']}, file created {cmp[v]['file_create_date'][:10]}, "
          f"position timestamps {np.nanmin(cmp[v]['pos_t']):.1f} to {np.nanmax(cmp[v]['pos_t']):.1f} s, "
          f"home beam timestamps {cmp[v]['dio_t'].min():.1f} to {cmp[v]['dio_t'].max():.1f} s")
print("  largest home beam timestamp difference (s):", float(np.max(np.abs(pub['dio_t'] - dr['dio_t']))))
print("  position timestamp difference, draft minus pinned (s): median",
      float(np.nanmedian(dr['pos_t'] - pub['pos_t'])), "; position values identical:", cmp["pos_data_equal"])
Position: unit ['meters'] ; sampling rate (Hz) 32.89 to 33.04 (Methods: 30 Hz)
x range (m): 1.08 to 1.242 ; y range (m): 1.154 to 1.298
Epochs with NaN position timestamps: 110 of 116 ; NaN timestamps per epoch up to 4
  of these, epochs whose NaN timestamps are all at the end of the series: 110 ; NaN timestamps elsewhere in the series, over all epochs: 0
Epochs with non-increasing position timestamps: 2 ; most in one epoch: 200

Run epochs whose StateScript log is identical to another's: 0
Raw broadband: chunk shapes ['(229593, 1)', '(300827, 1)', '(233047, 1)', '(243173, 1)', '(270662, 1)', '(268976, 1)', '(224281, 1)', '(229034, 1)', '(223850, 1)', '(212978, 1)', '(234724, 1)', '(329259, 1)', '(284715, 1)', '(237802, 1)', '(238472, 1)', '(285829, 1)', '(272562, 1)', '(242562, 1)', '(234512, 1)', '(241875, 1)', '(238860, 1)', '(246272, 1)', '(241423, 1)', '(240046, 1)', '(224469, 1)', '(278671, 1)', '(222538, 1)', '(246475, 1)', '(238408, 1)', '(241896, 1)', '(238351, 1)', '(282914, 1)', '(243048, 1)', '(242631, 1)', '(246329, 1)', '(242251, 1)', '(238724, 1)', '(251239, 1)', '(249246, 1)', '(240935, 1)', '(245473, 1)', '(242216, 1)', '(240711, 1)', '(242174, 1)', '(285972, 1)', '(245774, 1)', '(214826, 1)', '(258233, 1)', '(246727, 1)', '(253115, 1)', '(243742, 1)', '(250534, 1)', '(249912, 1)', '(244012, 1)', '(238119, 1)', '(238674, 1)', '(247803, 1)'] ; conversion to volts [1e-06]
samples / time span (Hz): median 24976 range 17093 to 29464 (30 kHz with the gaps between epochs inside the span)
samples / summed epoch durations (Hz): median 30000 range 30000 to 30000
Recorded hours of raw broadband at 30 kHz: 260.1
Assets of the pinned version: 57 ; same path in the draft: 57 ; content (SHA-256) differs in the draft: 55
Draft modification month of the assets that differ: {'2022-02': 48, '2022-03': 7} ; of those that do not: {'2021-08': 2}
montague day 4, pinned version against draft:
  0.210914.1732: NWB 2.3.0, file created 2021-06-23, position timestamps 1595354548.0 to 1595359982.5 s, home beam timestamps 1595352625.1 to 1595370218.9 s
  draft: NWB 2.4.0, file created 2022-01-14, position timestamps 6101168.1 to 6106602.7 s, home beam timestamps 1595352625.1 to 1595370218.9 s
  largest home beam timestamp difference (s): 9.5367431640625e-07
  position timestamp difference, draft minus pinned (s): median -1589253379.9117513 ; position values identical: True

Position is stated in metres and spans about 1.1 to 1.3 m on each axis, which fits an eight-arm maze; it is sampled at about 33 Hz, not the 30 Hz of the Methods. 110 of 116 epochs end with 1 to 4 NaN timestamps (in all 110 the NaN timestamps are the last samples of the series, and there are none elsewhere), and two have non-increasing ones; these samples are dropped here. No two run epochs share a StateScript log, so no recording was deposited twice. The raw broadband has 30,000 samples per second of summed epoch time, as the Methods state. In the draft, 55 of the 57 assets differ in content (SHA-256) from the pinned version; the position timestamps of the file compared are shifted by about -1.59e9 s from the DIO clock, with the same position values; the pinned version is used throughout.

Sessions 1 and 3 of subject 1. The Methods exclude "sessions 1 and 3 of subject 1" for decoding problems: the first had fewer than 75% of samples decoded on the same segment, and in the second "not all arms were visited". The files do not mark these sessions, and the answered question says the paper does not number them. The criterion allows two readings. (a) The first and third run sessions in order of recording, day 6 epochs 2 and 5 (all eight arms are visited in both). (b) The two sessions the Methods describe. The table below shows that the only jaq session with fewer than eight arms visited is day 6 epoch 4, so it is the second excluded session under (b). The first cannot be identified here: it needs the decoder, which is blocked (see the claims not tested). Reading (b) is therefore run with day 6 epoch 4 and each of the other 26 jaq sessions in turn as the first; "b: day 6 epochs 2 and 4" below takes the earliest. With no exclusion, (c) is shown as a variant, not a reading, since the criterion excludes two sessions.

In [7]:
jaq = runs[runs.subject == "jaq"][["session", "day", "epoch", "arms_visited", "valid", "rewards_log"]]
print(jaq.head(6).to_string(index=False))
print("jaq sessions with fewer than eight arms visited:",
      jaq.loc[jaq.arms_visited < 8, ["day", "epoch", "arms_visited"]].to_dict("records"))
NOT_ALL_ARMS = tuple(jaq.loc[jaq.arms_visited < 8, ["day", "epoch"]].iloc[0])
B_FIRST_CHOICES = [(d, e) for d, e in zip(jaq.day, jaq.epoch) if (d, e) != NOT_ALL_ARMS]
EXCLUDE = {"a: sessions 1 and 3 in order": [(6, 2), (6, 5)],
           "b: day 6 epochs 2 and 4": [B_FIRST_CHOICES[0], NOT_ALL_ARMS],
           "c, variant: none": []}
print("Reading (b): second session", NOT_ALL_ARMS, ";", len(B_FIRST_CHOICES), "candidates for the first")

def session_set(reading=None, exclude=None):
    ex = EXCLUDE[reading] if exclude is None else exclude
    keep = ~((runs.subject == "jaq") & runs.apply(lambda r: (r.day, r.epoch) in ex, axis=1))
    return runs[keep]

# Streaming cost of the raw broadband, measured
url = assets.url[assets.path.str.contains("jaq-10")].iloc[0]
secs, nbytes = rt.time_raw_read(url)
rate = nbytes / secs
total = files.GB.sum() * 1e9
print(f"\nRead {nbytes / 1e6:.0f} MB of raw broadband (300000 samples x 128 channels) in {secs:.1f} s, {rate / 1e6:.1f} MB/s")
print(f"At that rate the dandiset's {total / 1e12:.1f} TB would take {total / rate / 3600:.0f} h; "
      f"one 90-min run epoch ({90 * 60 * 30000 * 128 * 2 / 1e9:.0f} GB) {90 * 60 * 30000 * 128 * 2 / rate / 60:.0f} min")
 session  day  epoch  arms_visited  valid  rewards_log
       1    6      2             8    107           46
       2    6      4             7     66           30
       3    6      5             8    110           65
       4    7      2             8     74            6
       5    7      4             8    107           49
       6    8      2             8    101           45
jaq sessions with fewer than eight arms visited: [{'day': 6, 'epoch': 4, 'arms_visited': 7}]
Reading (b): second session (6, 4) ; 26 candidates for the first
Read 77 MB of raw broadband (300000 samples x 128 channels) in 13.5 s, 5.7 MB/s
At that rate the dandiset's 9.1 TB would take 444 h; one 90-min run epoch (41 GB) 121 min

The raw broadband is stored one channel per chunk of 212,978 to 329,259 samples (7 to 11 s), so any time window must fetch every channel's chunk. The rate measured above puts streaming the run epochs alone (116 epochs of about 41 GB) far beyond the registry's 30-minute limit, before any filtering, spike detection or decoding. This is why the 31 replay and ripple claims are blocked as too_large.

Per-session check¶

Added after the first verification round. The table lists every run epoch with its log header, forage-assist lines, blocks, rewards per block, and the arms entered in the log's valid trials and in the DIO beam breaks.

In [8]:
# Per-session table: header, forage assist, blocks and rewards per block, arms visited in the log and in the DIO
sess = []
for _, row in runs.iterrows():
    r = row.run
    lab = rt.label_task_phase(r["trials"])
    per_block = [int(lab.rewarded[(lab.block == k) & ~lab.final].sum()) for k in sorted(lab.block.unique())]
    closed = [k for k in sorted(lab.block.unique()) if lab.final[lab.block == k].any()]
    sess.append({"subject": row.subject, "day": row.day, "epoch": row.epoch, "session": row.session,
                 "minutes": row.minutes, "header": r["forageNum"] is not None, "forageNum": r["forageNum"],
                 "multi_arm_goal_lines": r["n_multi_goal_lines"], "outerreps_printed": r["outerreps_printed"],
                 "valid": row.valid, "rewards": row.rewards_log, "full_blocks": len(rt.full_blocks(lab)),
                 "rewards_per_block": " ".join(str(x) + ("" if k in closed else "o") for k, x in zip(sorted(lab.block.unique()), per_block)),
                 "arms_log": row.arms_visited, "arms_dio": len(np.unique(r["dio_beam_arms"]))})
sess = pd.DataFrame(sess)
print("Per run epoch ('o' marks the open last block of the epoch):")
print(sess.to_string(index=False))
print("\nEpochs whose log has no Python header:", sess.loc[~sess.header, ["subject", "day", "epoch"]].to_dict("records"))
print("Epochs with a CURRENTGOAL line naming more than one arm (forage assist):", int((sess.multi_arm_goal_lines > 0).sum()),
      "of", len(sess))
print("Epochs shorter than 45 min:", sess.loc[sess.minutes < 45, ["subject", "day", "epoch", "minutes", "full_blocks"]].to_dict("records"))
print("Epochs where the DIO beam breaks reach a different number of arms than the log:",
      sess.loc[sess.arms_log != sess.arms_dio, ["subject", "day", "epoch", "arms_log", "arms_dio"]].to_dict("records"))

# Completed blocks whose reward count is not a programmed value: is the missing reward on the closing trial of the block before?
odd = []
for _, row in runs.iterrows():
    lab = rt.label_task_phase(row.run["trials"])
    for k in sorted(lab.block.unique()):
        b = lab[lab.block == k]
        n = int(b.rewarded[~b.final].sum())
        programmed = {15, 10} if row.subject in ("jaq", "roquefort") else set(range(4, 13)) | {15}
        if b.final.any() and n not in programmed:
            prev_close = lab[(lab.block == k - 1) & lab.final]
            odd.append({"subject": row.subject, "day": row.day, "epoch": row.epoch, "block": k, "goal": b.block_goal.iloc[0],
                        "rewards_in_block": n, "closing_trial_of_previous_block": f"arm {prev_close.outer.iloc[0]}, rewarded {bool(prev_close.rewarded.iloc[0])}"
                        if len(prev_close) else "none", "outerreps_printed": row.run["outerreps_printed"]})
print("\nCompleted blocks with a reward count outside the programmed values:")
print(pd.DataFrame(odd).to_string(index=False))

# jaq day 6 epoch 4: arms entered according to the DIO, before and after the last logged trial
r = runs[(runs.subject == "jaq") & (runs.day == NOT_ALL_ARMS[0]) & (runs.epoch == NOT_ALL_ARMS[1])].run.iloc[0]
a, b = rt.statescript_to_nwb_clock(r)[:2]
t_last = a * r["trials"].t_ms.max() / 1000 + b
before = r["dio_beam_t"] <= t_last + 1
print(f"\njaq day {NOT_ALL_ARMS[0]} epoch {NOT_ALL_ARMS[1]}: last logged trial at {t_last - r['start']:.0f} s of {r['stop'] - r['start']:.0f} s")
print("  arms visited in the log:", sorted(r["trials"][~r["trials"].lockout].outer.unique().tolist()))
print("  arms with a DIO beam break up to the last logged trial:", sorted(np.unique(r["dio_beam_arms"][before]).tolist()))
print("  DIO beam breaks after it, by arm:", pd.Series(r["dio_beam_arms"][~before]).value_counts().sort_index().to_dict())
t_last_rew = a * r["trials"][r["trials"].rewarded & ~r["trials"].lockout].t_ms.max() / 1000 + b
print(f"  last logged reward at {t_last_rew - r['start']:.0f} s")
print("  DIO pumps after it (s into the epoch, arm):", [(round(t - r["start"]), int(x)) for t, x in zip(r["dio_pump_t"], r["dio_pump_arms"]) if t > t_last + 1])

extra = [t for t in r["dio_pump_t"] if t > t_last + 1]
print("  extra pump after the last logged trial by (s):", [round(t - t_last) for t in extra],
      "; after the last logged reward by (s):", [round(t - t_last_rew) for t in extra])
Per run epoch ('o' marks the open last block of the epoch):
   subject  day  epoch  session  minutes  header forageNum  multi_arm_goal_lines        outerreps_printed  valid  rewards  full_blocks        rewards_per_block  arms_log  arms_dio
despereaux    3      2        1     65.6    True         1                     0                   [4, 6]     69       30            2                 15 15 0o         8         8
despereaux    3      4        2     92.5    True         1                     0           [8, 9, 11, 12]    122       75            5           15 15 15 15 15         8         8
despereaux    4      2        3     91.4   False       NaN                     0                  [8, 12]    132       54            6        10 10 10 10 10 4o         8         8
despereaux    4      4        4     39.2    True         1                     0                   [6, 8]     48       29            3                 10 10 9o         8         8
despereaux    4      6        5     90.2    True         1                     0             [4, 6, 7, 8]    104       45            5           10 10 10 10 5o         8         8
despereaux    5      2        6     85.1    True         1                     0            [4, 8, 9, 12]    100       40            4           10 10 10 10 0o         8         8
despereaux    5      4        7     60.5    True         1                     0           [5, 6, 10, 12]     77       40            4           10 10 10 10 0o         8         8
despereaux    6      2        8     90.2    True         1                     0     [5, 6, 8, 9, 11, 12]    130       50            7         7 7 7 7 7 7 7 1o         8         8
despereaux    6      4        9     90.2    True         1                     0           [6, 9, 11, 12]     97       25            4               6 6 6 6 1o         8         8
despereaux    7      2       10     92.1    True         1                     0           [4, 9, 10, 11]    115       54            8         7 7 7 7 7 7 7 5o         8         8
despereaux    8      2       11     90.3    True         1                     0         [4, 5, 7, 8, 12]    117       48            7           7 7 7 7 7 7 6o         8         8
despereaux    9      2       12     90.5    True         1                     0 [4, 5, 8, 9, 10, 11, 12]    105       36            9     4 4 4 4 4 4 4 4 4 0o         8         8
despereaux    9      4       13     71.0    True         1                     0            [4, 8, 9, 10]     91       36            4               9 9 9 9 0o         8         8
despereaux   10      2       14     80.8    True         1                     0        [5, 6, 7, 10, 12]     93       40            8       5 4 5 5 5 5 5 5 0o         8         8
despereaux   10      4       15     81.8    True         1                     0               [7, 9, 12]     65       41            4           10 10 10 10 0o         8         8
despereaux   11      2       16     79.5    True         1                     0                   [6, 9]     56       27            2                 12 12 3o         8         8
despereaux   11      4       17     78.4    True         1                     0              [6, 10, 11]     68       29            4               7 7 7 7 1o         8         8
despereaux   12      2       18     90.1    True         1                     0                  [6, 12]     77       27            3                 11 11 5o         8         8
despereaux   12      4       19     57.5    True         1                     0                      [8]     35       16            2                   8 8 0o         7         8
despereaux   13      2       20     90.2    True         1                     0              [8, 10, 11]     76       40            4              11 11 11 7o         8         8
despereaux   13      4       21     86.3    True         1                     0                [4, 8, 9]     59       36            3              12 12 12 0o         8         8
despereaux   14      2       22     90.0    True         1                     0              [5, 10, 12]     58       32            4                  8 8 8 8         7         8
despereaux   14      4       23     54.5    True         1                     0                      [4]     24       10            1                    10 0o         7         8
despereaux   14      6       24     91.9    True         1                     0           [5, 6, 10, 12]     85       39            6             7 7 7 7 7 4o         8         8
       jaq    6      2        1     90.9   False       NaN                     0                     [15]    107       46            3              15 15 15 1o         8         8
       jaq    6      4        2     44.0    True         1                     0                     [15]     66       30            2                 15 15 0o         7         7
       jaq    6      5        3     91.8    True         1                     0                     [15]    110       65            5           15 15 15 15 5o         8         8
       jaq    7      2        4     90.1    True         1                     0                       []     74        6            1                       6o         8         8
       jaq    7      4        5     90.2    True         1                     0                     [15]    107       49            4              15 15 15 4o         8         8
       jaq    8      2        6     90.5    True         1                     0                     [15]    101       45            3              15 15 15 0o         8         8
       jaq    8      4        7     90.4    True         1                     0                     [15]     94       50            4              15 15 15 5o         8         8
       jaq    9      2        8     91.4    True         1                     0                     [15]     82       44            3                15 15 14o         8         8
       jaq    9      4        9     64.6    True         1                     0                     [15]     73       45            3              15 15 15 0o         8         8
       jaq    9      6       10     33.9    True         1                     0                     [15]     36       16            1                    15 1o         8         8
       jaq   10      2       11     90.1    True         1                     0                     [10]     86       40            4           10 10 10 10 0o         8         8
       jaq   11      2       12     91.3    True         1                     0                     [10]    105       54            6        10 10 10 10 10 4o         8         8
       jaq   11      4       13     79.9    True         1                     0                     [10]     77       40            4           10 10 10 10 0o         8         8
       jaq   12      2       14     90.1    True         1                     0                     [10]    105       57            6         10 10 10 9 10 7o         8         8
       jaq   12      4       15     90.2    True         1                     0                     [10]     91       24            3                 10 10 4o         8         8
       jaq   13      2       16     90.4   False       NaN                     0                     [10]     88       47            5           10 10 10 10 7o         8         8
       jaq   13      4       17     90.1    True         1                     0                     [10]     67       31            3              10 10 10 1o         8         8
       jaq   14      2       18     90.0   False       NaN                     0                     [10]     77       35            4              10 10 10 5o         8         8
       jaq   14      4       19     90.2    True         1                     0                     [10]     94       42            4           10 10 10 10 2o         8         8
       jaq   15      2       20     90.1   False       NaN                     0                     [10]     98       51            5        10 10 10 10 10 1o         8         8
       jaq   15      4       21     92.4    True         1                     0                     [10]    101       40            4           10 10 10 10 0o         8         8
       jaq   16      2       22     90.6    True         1                     0                     [10]     69       31            3              10 10 10 1o         8         8
       jaq   16      4       23     92.3    True         1                     0                     [10]     70       36            4              10 10 10 6o         8         8
       jaq   17      2       24     90.3    True         1                     0                     [10]    106       30            3              10 10 10 0o         8         8
       jaq   17      4       25     90.5    True         1                     0                     [10]     71       20            2                   10 10o         8         8
       jaq   18      2       26     59.1    True         1                     0                     [10]     47       22            2                 10 10 2o         8         8
       jaq   18      4       27     92.9    True         1                     0                     [10]     92       48            5           10 10 10 10 8o         8         8
  montague    3      2        1     90.1    True         1                     0                     [15]     71       37            3                 15 15 7o         7         8
  montague    3      4        2     75.9    True         1                     0                     [15]     59       30            2                 15 15 0o         8         8
  montague    3      6        3     31.8    True         1                     0                     [15]     26       15            1                    15 0o         6         8
  montague    4      2        4     90.6    True         1                     0                     [15]     68       34            3                 15 15 4o         8         8
  montague    4      4        5     70.2    True         1                     0                     [15]     47       35            3                 15 15 5o         7         8
  montague    5      2        6     94.1    True         1                     0                     [10]     99       50            5        10 10 10 10 10 0o         8         8
  montague    5      4        7     90.0    True         1                     0                     [10]    111       66            7     10 10 10 10 10 10 6o         8         8
  montague    6      2        8     90.1    True         1                     0                     [10]     83       30            3              10 10 10 0o         8         8
  montague    6      4        9     90.6    True         1                     0                     [10]     82       40            4              10 10 10 10         8         8
  montague    7      2       10     91.4    True         1                     0                     [10]     95       51            5        10 10 10 10 10 1o         8         8
  montague    7      4       11     90.2    True         1                     0                     [10]     94       40            4              10 10 10 10         8         8
  montague    8      2       12     90.5    True         1                     0                     [10]     97       43            4           10 10 10 10 3o         8         8
  montague    8      4       13     90.1    True         1                     0                     [10]     98       35            4              10 10 10 5o         8         8
  montague    9      2       14     90.8    True         1                     0                      [7]    100       52            7         7 7 7 7 7 7 7 3o         8         8
  montague    9      4       15     81.8    True         1                     0                      [6]     78       30            5             6 6 6 6 6 0o         8         8
  montague   10      2       16     90.2    True         1                     0                     [11]     55       32            3                11 11 10o         7         8
  montague   10      4       17     92.7    True         1                     0                      [7]     86       35            5             7 7 7 7 7 0o         8         8
  montague   11      2       18     90.3    True         1                     0                      [9]    100       56            6           9 9 9 9 9 9 2o         8         8
  montague   11      4       19     90.1    True         1                     0                      [6]    115       42            7         6 6 6 6 6 6 6 0o         8         8
  montague   12      2       20     90.3    True         1                     0                      [7]     93       49            7         7 7 7 7 7 7 7 0o         8         8
  montague   12      4       21     91.1    True         1                     0                      [9]    105       54            6           9 9 9 9 9 9 0o         8         8
  montague   13      2       22     91.9    True         1                     0                      [5]    104       55           11 5 5 5 5 5 5 5 5 5 5 4 0o         8         8
  montague   13      4       23     93.4    True         1                     0                     [10]    110       61            6     10 10 10 10 10 10 1o         8         8
  montague   14      2       24     90.1    True         1                     0                      [7]    108       49            7         7 7 7 7 7 7 7 0o         8         8
  montague   14      4       25     90.4    True         1                     0                      [4]    115       40            9   4 4 4 4 4 4 3 4 4 4 0o         8         8
  montague   15      2       26     90.1    True         1                     0                     [12]     97       67            6        12 12 12 12 12 7o         8         8
  montague   15      4       27     90.7    True         1                     0                      [6]     89       48            8          6 6 6 6 6 6 6 6         8         8
  montague   16      2       28     91.4    True         1                     0                     [11]     87       44            4           11 11 11 11 0o         8         8
  montague   16      4       29     92.8    True         1                     0                      [7]     93       35            5             7 7 7 7 7 0o         8         8
  montague   17      2       30     91.1    True         1                     0                      [8]     72       35            4               8 8 8 8 3o         8         8
  montague   17      4       31     90.4    True         1                     0                     [11]     89       55            5        11 11 11 11 11 0o         6         8
  montague   18      2       32     90.3    True         1                     0                      [6]     72       32            5             6 6 6 6 6 2o         8         8
  montague   18      4       33     90.6    True         1                     0                     [10]     59       16            2                    10 6o         7         8
 roquefort    7      2        1     90.1    True         1                     0                  [6, 11]    120       34            3                 15 15 4o         8         8
 roquefort    7      4        2     90.7    True         1                     0                      [7]    104       30            2                 15 15 0o         8         8
 roquefort    8      2        3     91.2    True         1                     0              [6, 11, 12]     98       45            3              15 15 15 0o         8         8
 roquefort    8      4        4     90.3    True         1                     0               [4, 5, 12]    105       46            3              15 15 15 1o         8         8
 roquefort    9      2        5     90.2    True         1                     0                 [11, 12]    114       45            3              15 15 15 0o         8         8
 roquefort    9      4        6     90.6    True         1                     0                 [10, 12]     94       30            2                 15 15 0o         8         8
 roquefort   10      2        7     91.0    True         1                     0                  [9, 11]     81       30            3              10 10 10 0o         8         8
 roquefort   10      4        8     91.1    True         1                     0              [8, 11, 12]     96       46            3              15 15 15 1o         8         8
 roquefort   11      2        9     90.4    True         1                     0                   [6, 9]     89       33            2                 15 15 3o         8         8
 roquefort   11      4       10     90.5    True         1                     0                  [8, 11]     87       46            3              15 15 15 1o         8         8
 roquefort   12      2       11     90.0    True         1                     0                  [8, 10]     91       30            2                 15 15 0o         8         8
 roquefort   12      4       12     90.9    True         1                     0                   [7, 9]     86       31            2                 15 15 1o         8         8
 roquefort   13      2       13     90.2    True         1                     0                   [8, 9]     91       46            3              15 15 15 1o         8         8
 roquefort   13      4       14     91.1    True         1                     0                     [12]     79       15            1                    15 0o         8         8
 roquefort   14      2       15     90.5    True         1                     0              [4, 11, 12]     82       45            3              15 15 15 0o         8         8
 roquefort   14      4       16     89.6    True         1                     0                      [5]     66       32            2                 15 15 2o         8         8
 roquefort   15      2       17     93.3    True         1                     0              [4, 10, 12]     83       45            3              15 15 15 0o         8         8
 roquefort   15      4       18     90.7    True         1                     0                   [4, 5]     73       20            2                 10 10 0o         8         8
 roquefort   16      2       19     90.1    True         1                     0               [4, 5, 11]     77       36            4              10 10 10 6o         8         8
 roquefort   16      4       20     90.5    True         1                     0                  [7, 12]     65       20            2                    10 10         8         8
 roquefort   17      2       21     90.1    True         1                     0              [9, 10, 11]     75       31            3              10 10 10 1o         8         8
 roquefort   17      4       22    103.1    True         1                     0            [4, 8, 9, 11]     68       40            4           10 10 10 10 0o         7         8
 roquefort   18      2       23     90.4    True         1                     0                [4, 5, 9]     75       31            3              10 10 10 1o         8         8
 roquefort   18      4       24     90.5    True         1                     0                [4, 6, 7]     78       38            4              10 10 10 8o         8         8
 roquefort   19      2       25     92.2    True         1                     0               [7, 9, 11]     83       30            3              10 10 10 0o         8         8
 roquefort   19      4       26     91.1    True         1                     0                  [5, 11]     72       20            2                 10 10 0o         8         8
 roquefort   20      2       27     90.0    True         1                     0                  [8, 10]     71       30            3              10 10 10 0o         8         8
 roquefort   20      4       28     90.1    True         1                     0                  [8, 12]     71       30            3              10 10 10 0o         8         8
 roquefort   21      2       29     90.0    True         1                     0                  [8, 11]     45       26            3                 10 10 6o         7         8
 roquefort   21      4       30     90.0    True         1                     0                   [6, 8]     42       20            2                 10 10 0o         7         8
 roquefort   22      2       31     91.5    True         1                     0                      [4]     53       11            1                    10 1o         8         8
 roquefort   22      4       32     91.2    True         1                     0                   [4, 7]     43       26            3                 10 10 6o         8         8

Epochs whose log has no Python header: [{'subject': 'despereaux', 'day': 4, 'epoch': 2}, {'subject': 'jaq', 'day': 6, 'epoch': 2}, {'subject': 'jaq', 'day': 13, 'epoch': 2}, {'subject': 'jaq', 'day': 14, 'epoch': 2}, {'subject': 'jaq', 'day': 15, 'epoch': 2}]
Epochs with a CURRENTGOAL line naming more than one arm (forage assist): 0 of 116
Epochs shorter than 45 min: [{'subject': 'despereaux', 'day': 4, 'epoch': 4, 'minutes': 39.2, 'full_blocks': 3}, {'subject': 'jaq', 'day': 6, 'epoch': 4, 'minutes': 44.0, 'full_blocks': 2}, {'subject': 'jaq', 'day': 9, 'epoch': 6, 'minutes': 33.9, 'full_blocks': 1}, {'subject': 'montague', 'day': 3, 'epoch': 6, 'minutes': 31.8, 'full_blocks': 1}]
Epochs where the DIO beam breaks reach a different number of arms than the log: [{'subject': 'despereaux', 'day': 12, 'epoch': 4, 'arms_log': 7, 'arms_dio': 8}, {'subject': 'despereaux', 'day': 14, 'epoch': 2, 'arms_log': 7, 'arms_dio': 8}, {'subject': 'despereaux', 'day': 14, 'epoch': 4, 'arms_log': 7, 'arms_dio': 8}, {'subject': 'montague', 'day': 3, 'epoch': 2, 'arms_log': 7, 'arms_dio': 8}, {'subject': 'montague', 'day': 3, 'epoch': 6, 'arms_log': 6, 'arms_dio': 8}, {'subject': 'montague', 'day': 4, 'epoch': 4, 'arms_log': 7, 'arms_dio': 8}, {'subject': 'montague', 'day': 10, 'epoch': 2, 'arms_log': 7, 'arms_dio': 8}, {'subject': 'montague', 'day': 17, 'epoch': 4, 'arms_log': 6, 'arms_dio': 8}, {'subject': 'montague', 'day': 18, 'epoch': 4, 'arms_log': 7, 'arms_dio': 8}, {'subject': 'roquefort', 'day': 17, 'epoch': 4, 'arms_log': 7, 'arms_dio': 8}, {'subject': 'roquefort', 'day': 21, 'epoch': 2, 'arms_log': 7, 'arms_dio': 8}, {'subject': 'roquefort', 'day': 21, 'epoch': 4, 'arms_log': 7, 'arms_dio': 8}]
Completed blocks with a reward count outside the programmed values:
 subject  day  epoch  block  goal  rewards_in_block closing_trial_of_previous_block outerreps_printed
     jaq   12      2      4     6                 9            arm 6, rewarded True              [10]
montague   14      4      7     6                 3            arm 6, rewarded True               [4]

jaq day 6 epoch 4: last logged trial at 2592 s of 2642 s
  arms visited in the log: [1, 2, 3, 4, 5, 7, 8]
  arms with a DIO beam break up to the last logged trial: [1, 2, 3, 4, 5, 7, 8]
  DIO beam breaks after it, by arm: {8: 36}
  last logged reward at 2406 s
  DIO pumps after it (s into the epoch, arm): [(2632, 8)]
  extra pump after the last logged trial by (s): [40] ; after the last logged reward by (s): [226]

With forageNum above 1 the observer code in the log headers puts several arms in the goal until one is found, and prints them all in the CURRENTGOAL IS [...] line. No log, including the five without a header, has such a line, so no epoch uses forage assist. The two completed blocks whose reward count is not a programmed value (jaq day 12 epoch 2 with 9, montague day 14 epoch 4 with 3) both follow a block whose closing trial was a rewarded visit to the new goal. Under the closing-trial rule that reward stays in the old block, so the new block shows one reward fewer than the outerreps printed (10 and 4). The DIO confirms that in jaq day 6 epoch 4 arm 6 was never entered, including after the last logged trial, where there are only arm 8 entries and the extra pump, 40 s after the last logged trial and 226 s after the last logged reward. It is the only jaq session with fewer than eight arms, in the log and in the DIO. In 12 epochs of the other subjects the DIO reaches an arm that no valid trial of the log visits.

Which run epochs the paper did not count cannot be settled from the files: jaq and despereaux have one more each. Possible ones are jaq day 7 epoch 2 (6 rewards in 74 valid trials, one open block, no outerreps printed) and the epochs shorter than the Methods' 45 minutes, listed above. fig1d-sessions-blocks shows the counts with each jaq and despereaux epoch left out in turn.

In [9]:
# Trial counts per subject against the counts in the figure legends (not a claim; for comparison only)
LEGEND = pd.DataFrame({"search_GLM_3D": [711, 848, 725, 1065], "search_5A": [534, 617, 570, 879],
                       "repeat_5A": [924, 1019, 894, 1302], "correct_5B": [923, 1007, 847, 1340],
                       "error_5B": [424, 654, 307, 390]}, index=rt.SUBJECTS)
cnt = []
for s in rt.SUBJECTS:
    L = pd.concat([rt.label_task_phase(r["trials"]) for r in session_set("a: sessions 1 and 3 in order").query("subject == @s").run])
    frac = np.round(L.phase % 1, 1)
    rep = L.phase > 1
    cnt.append({"subject": s, "valid": len(L), "search": int((L.phase <= 1).sum()),
                "search_after_block1": int(((L.phase <= 1) & (L.block > 1)).sum()),
                "repeat": int(rep.sum()), "repeat_after_block1": int((rep & (L.block > 1)).sum()),
                "correct_repeat": int((rep & ((frac == 0) | (frac == 0.9))).sum()),
                "error_repeat": int((rep & frac.isin([0.3, 0.5, 0.8])).sum())})
cnt = pd.DataFrame(cnt).set_index("subject")
print("Trial counts under session reading (a), against the legend counts:")
print(pd.concat([cnt, LEGEND], axis=1).to_string())
pairs = {"search / search_GLM_3D": ("search", "search_GLM_3D"), "search_after_block1 / search_5A": ("search_after_block1", "search_5A"),
         "repeat_after_block1 / repeat_5A": ("repeat_after_block1", "repeat_5A"), "correct_repeat / correct_5B": ("correct_repeat", "correct_5B"),
         "error_repeat / error_5B": ("error_repeat", "error_5B")}
both = pd.concat([cnt, LEGEND], axis=1)
print("\nRatio of the count here to the legend's:")
print(pd.DataFrame({k: (both[a] / both[b]).round(3) for k, (a, b) in pairs.items()}).to_string())
Trial counts under session reading (a), against the legend counts:
            valid  search  search_after_block1  repeat  repeat_after_block1  correct_repeat  error_repeat  search_GLM_3D  search_5A  repeat_5A  correct_5B  error_5B
jaq          2077     695                  509    1382                  896             908           474            711        534        924         923       424
roquefort    2557     808                  572    1749                 1051            1018           731            848        617       1019        1007       654
despereaux   2003     749                  583    1254                  946             873           381            725        570        894         847       307
montague     2857    1065                  886    1792                 1310            1360           432           1065        879       1302        1340       390

Ratio of the count here to the legend's:
            search / search_GLM_3D  search_after_block1 / search_5A  repeat_after_block1 / repeat_5A  correct_repeat / correct_5B  error_repeat / error_5B
jaq                          0.977                            0.953                            0.970                        0.984                    1.118
roquefort                    0.953                            0.927                            1.031                        1.011                    1.118
despereaux                   1.033                            1.023                            1.058                        1.031                    1.241
montague                     1.000                            1.008                            1.006                        1.015                    1.108

These counts are a comparison, not a claim: the legends do not say exactly which trials each count covers. All search trials are within 5% of the Figure 3D counts (montague equal), search and repeat trials after the first block within 8% of Figure 5A's, and correct repeat trials within 4% of Figure 5B's. Error trials are 11 to 24% more than Figure 5B's, so the error labelling, or the selection behind it, is not the paper's. Only the replay claims on error trials use it, and all are blocked.

fig1d-sessions-blocks¶

The analysis includes 24, 32, 23 and 33 behavioural sessions and 89, 85, 105 and 166 trial blocks for the four subjects.

Criterion: sessions are the full-task sessions less sessions 1 and 3 of subject 1, under reading (a) or (b) (above), with (b) deciding when they differ; blocks are those with a trial of task phase >= 4 (any(ctphase>=4), dfs_ripcontent.m part 2), with the first valid trial after each goal change in the old block (replaytask.FINAL_TRIAL). Reproduced when all eight counts are within tolerance. The other closing-trial rule ("old_goal_visit", a reading before the answer) is shown only to say what the answer changed.

In [10]:
EXPECTED_SESSIONS = {"jaq": 24, "roquefort": 32, "despereaux": 23, "montague": 33}
EXPECTED_BLOCKS = {"jaq": 89, "roquefort": 85, "despereaux": 105, "montague": 166}
for final in rt.FINAL_TRIAL_READINGS:
    runs["blocks_" + final] = [len(rt.full_blocks(rt.label_task_phase(r["trials"], final))) for r in runs.run]

def count_1d(ss, final):
    out = []
    for s in rt.SUBJECTS:
        nb = ss.loc[ss.subject == s, "blocks_" + final].to_numpy()
        out.append({"subject": s, "sessions": len(nb), "expected_sessions": EXPECTED_SESSIONS[s],
                    "blocks": int(nb.sum()), "expected_blocks": EXPECTED_BLOCKS[s],
                    "blocks_per_session_median": np.median(nb), "blocks_per_session_range": f"{nb.min()}-{nb.max()}"})
    out = pd.DataFrame(out)
    out["sessions_ok"] = (out.sessions - out.expected_sessions).abs() <= 0.1 * out.expected_sessions
    out["blocks_ok"] = (out.blocks - out.expected_blocks).abs() <= 0.1 * out.expected_blocks
    return out

rows = []
for reading in EXCLUDE:
    for final in rt.FINAL_TRIAL_READINGS:
        rows.append(count_1d(session_set(reading), final).assign(sessions_reading=reading, final_trial=final))
res1d = pd.concat(rows)[["sessions_reading", "final_trial", "subject", "sessions", "expected_sessions", "blocks",
                         "expected_blocks", "blocks_per_session_median", "blocks_per_session_range", "sessions_ok", "blocks_ok"]]
print(res1d.to_string(index=False))
print("\nAll eight counts within tolerance, per reading:")
print(res1d.groupby(["sessions_reading", "final_trial"]).apply(lambda g: bool(g.sessions_ok.all() and g.blocks_ok.all())).to_string())

# Reading (b) with every candidate for the session decoded on the same segment less than 75% of the time
b_all = []
for first in B_FIRST_CHOICES:
    g = count_1d(session_set(exclude=[first, NOT_ALL_ARMS]), rt.FINAL_TRIAL)
    jq = g[g.subject == "jaq"].iloc[0]
    b_all.append({"first": first, "jaq_sessions": jq.sessions, "jaq_blocks": jq.blocks,
                  "all_eight_ok": bool(g.sessions_ok.all() and g.blocks_ok.all())})
b_all = pd.DataFrame(b_all)
print(f"\nReading (b), {rt.FINAL_TRIAL}, over the {len(b_all)} candidates for the first excluded jaq session:")
print("  jaq sessions:", sorted(b_all.jaq_sessions.unique().tolist()), "; jaq blocks", b_all.jaq_blocks.min(), "to",
      b_all.jaq_blocks.max(), f"(tolerance {EXPECTED_BLOCKS['jaq'] * 0.9:.1f} to {EXPECTED_BLOCKS['jaq'] * 1.1:.1f})")
print("  candidates with all eight counts within tolerance:", int(b_all.all_eight_ok.sum()), "of", len(b_all))

# What the closing-trial rule does at each goal change
close = []
for _, row in runs.iterrows():
    lab = rt.label_task_phase(row.run["trials"], rt.FINAL_TRIAL)
    for i in np.where(lab.final)[0]:
        kind = ("old goal" if lab.outer[i] == lab.block_goal[i]
                else "new goal, rewarded" if lab.rewarded[i] else "other arm")
        close.append({"subject": row.subject, "closing trial visits": kind})
close = pd.DataFrame(close)
print("\nClosing trials of the blocks (first valid trial after each goal change), by arm visited:")
print(pd.crosstab(close.subject, close["closing trial visits"]).loc[rt.SUBJECTS].to_string())
diff = res1d.pivot_table(index=["sessions_reading", "subject"], columns="final_trial", values="blocks")
print("\nBlocks under the two closing-trial rules (old_goal_visit is the reading before the answer):")
print(diff.loc[[k for k in EXCLUDE if not k.startswith("c")]].to_string())
# Variant: one more jaq or despereaux epoch left out (the files hold one more than the paper for each)
loo = []
for subj in ["jaq", "despereaux"]:
    base = session_set("a: sessions 1 and 3 in order")
    for _, row in base[base.subject == subj].iterrows():
        g = count_1d(base.drop(index=row.name), rt.FINAL_TRIAL)
        sg = g[g.subject == subj].iloc[0]
        loo.append({"subject": subj, "left_out": (row.day, row.epoch), "sessions": sg.sessions, "blocks": sg.blocks,
                    "all_eight_ok": bool(g.sessions_ok.all() and g.blocks_ok.all())})
loo = pd.DataFrame(loo)
print("\nReading (a) with one more epoch left out, per subject:")
print(loo.groupby("subject").agg(sessions=("sessions", "first"), blocks_min=("blocks", "min"), blocks_max=("blocks", "max"),
                                 all_eight_ok=("all_eight_ok", "sum"), candidates=("all_eight_ok", "size")).to_string())
            sessions_reading        final_trial    subject  sessions  expected_sessions  blocks  expected_blocks  blocks_per_session_median blocks_per_session_range  sessions_ok  blocks_ok
a: sessions 1 and 3 in order first_after_switch        jaq        25                 24      88               89                        4.0                      1-6         True       True
a: sessions 1 and 3 in order first_after_switch  roquefort        32                 32      85               85                        3.0                      1-4         True       True
a: sessions 1 and 3 in order first_after_switch despereaux        24                 23     109              105                        4.0                      1-9         True       True
a: sessions 1 and 3 in order first_after_switch   montague        33                 33     166              166                        5.0                     1-11         True       True
a: sessions 1 and 3 in order     old_goal_visit        jaq        25                 24      88               89                        4.0                      1-6         True       True
a: sessions 1 and 3 in order     old_goal_visit  roquefort        32                 32      85               85                        3.0                      1-4         True       True
a: sessions 1 and 3 in order     old_goal_visit despereaux        24                 23     109              105                        4.0                      1-9         True       True
a: sessions 1 and 3 in order     old_goal_visit   montague        33                 33     167              166                        5.0                     1-11         True       True
     b: day 6 epochs 2 and 4 first_after_switch        jaq        25                 24      91               89                        4.0                      1-6         True       True
     b: day 6 epochs 2 and 4 first_after_switch  roquefort        32                 32      85               85                        3.0                      1-4         True       True
     b: day 6 epochs 2 and 4 first_after_switch despereaux        24                 23     109              105                        4.0                      1-9         True       True
     b: day 6 epochs 2 and 4 first_after_switch   montague        33                 33     166              166                        5.0                     1-11         True       True
     b: day 6 epochs 2 and 4     old_goal_visit        jaq        25                 24      91               89                        4.0                      1-6         True       True
     b: day 6 epochs 2 and 4     old_goal_visit  roquefort        32                 32      85               85                        3.0                      1-4         True       True
     b: day 6 epochs 2 and 4     old_goal_visit despereaux        24                 23     109              105                        4.0                      1-9         True       True
     b: day 6 epochs 2 and 4     old_goal_visit   montague        33                 33     167              166                        5.0                     1-11         True       True
            c, variant: none first_after_switch        jaq        27                 24      96               89                        4.0                      1-6        False       True
            c, variant: none first_after_switch  roquefort        32                 32      85               85                        3.0                      1-4         True       True
            c, variant: none first_after_switch despereaux        24                 23     109              105                        4.0                      1-9         True       True
            c, variant: none first_after_switch   montague        33                 33     166              166                        5.0                     1-11         True       True
            c, variant: none     old_goal_visit        jaq        27                 24      96               89                        4.0                      1-6        False       True
            c, variant: none     old_goal_visit  roquefort        32                 32      85               85                        3.0                      1-4         True       True
            c, variant: none     old_goal_visit despereaux        24                 23     109              105                        4.0                      1-9         True       True
            c, variant: none     old_goal_visit   montague        33                 33     167              166                        5.0                     1-11         True       True

All eight counts within tolerance, per reading:
sessions_reading              final_trial       
a: sessions 1 and 3 in order  first_after_switch     True
                              old_goal_visit         True
b: day 6 epochs 2 and 4       first_after_switch     True
                              old_goal_visit         True
c, variant: none              first_after_switch    False
                              old_goal_visit        False

Reading (b), first_after_switch, over the 26 candidates for the first excluded jaq session:
  jaq sessions: [25] ; jaq blocks 88 to 93 (tolerance 80.1 to 97.9)
  candidates with all eight counts within tolerance: 26 of 26
Closing trials of the blocks (first valid trial after each goal change), by arm visited:
closing trial visits  new goal, rewarded  old goal  other arm
subject                                                      
jaq                                    1        76          6
roquefort                              0        75          5
despereaux                             2        89         10
montague                               2       143         14

Blocks under the two closing-trial rules (old_goal_visit is the reading before the answer):
final_trial                              first_after_switch  old_goal_visit
sessions_reading             subject                                       
a: sessions 1 and 3 in order despereaux               109.0           109.0
                             jaq                       88.0            88.0
                             montague                 166.0           167.0
                             roquefort                 85.0            85.0
b: day 6 epochs 2 and 4      despereaux               109.0           109.0
                             jaq                       91.0            91.0
                             montague                 166.0           167.0
                             roquefort                 85.0            85.0

Reading (a) with one more epoch left out, per subject:
            sessions  blocks_min  blocks_max  all_eight_ok  candidates
subject                                                               
despereaux        23         100         108            24          24
jaq               24          82          87            25          25

Result: reproduced. With the first trial after each goal change closing the old block, all eight counts are within 10% under reading (a) and under reading (b) for every candidate first session. Roquefort and montague match the paper's session counts exactly (32 and 33), and their block counts too (85 and 166). Jaq has 25 sessions against 24, and 88 blocks under reading (a) against 89. Under reading (b), with day 6 epoch 4 as the session where not all arms were visited, jaq has 88 to 93 blocks over the 26 candidates for the other session (91 with day 6 epoch 2). Despereaux has 24 sessions against 23 and 109 blocks against 105. The closing-trial rule settled by the answer changes only montague, from 167 blocks under the earlier old-goal-visit reading to 166. With no session excluded (variant c), jaq has 27 sessions, outside the tolerance of 24, and 96 blocks, inside that of 89. One run epoch each of jaq and despereaux is in the files but not in the paper's count, and which one cannot be told; leaving out any one more epoch gives the paper's session counts (24 and 23), and the block counts stay within tolerance for every choice (see the variant above).

fig1ef-reward-rate¶

Aligned to the goal change, the outer-arm reward rate starts at chance (0.125) and rises; aligned to the first reward at the new goal, it is well above chance, so all subjects keep visiting a goal once found.

Criterion: per subject over the blocks with at least four rewards, the final unrewarded trial dropped; a trial scores 1 when rewarded; binomial S.E.M.; trials 1 to 15. Reproduced when, in all four subjects, the band on trial 1 of Figure 1E reaches 0.125 or lies below it, the rate rises over trials 1 to 15, and every point of Figure 1F has its band above 0.125. "Rises" is shown two ways: trial 15 against trial 1 (non-overlapping bands), and the Spearman correlation of the rate with trial number. Blocks are those of fig1d-sessions-blocks, closed by the first trial after each goal change (replaytask.FINAL_TRIAL); that closing trial is the one dropped. Sessions follow readings (a) and (b), and for (b) every candidate first session of jaq is run. The old-goal-visit rule is shown only to say what the answer changed.

In [11]:
def curves(reading=None, final=rt.FINAL_TRIAL, exclude=None, subjects=rt.SUBJECTS):
    ss = session_set(reading, exclude)
    out = {}
    for s in subjects:
        S, R = [], []
        for r in ss[ss.subject == s].run:
            a, b = rt.reward_curves(rt.label_task_phase(r["trials"], final))
            S.append(a); R.append(b)
        out[s] = (np.vstack(S), np.vstack(R))
    return out

def summarise_1ef(cv):
    rows = []
    for s, (E, F) in cv.items():
        p, se, n = rt.binomial_curve(E)
        p2, se2, n2 = rt.binomial_curve(F)
        rho, prho = stats.spearmanr(rt.CURVE_TRIALS, p)
        rows.append({"subject": s, "blocks": len(E),
                     "E_trial1": round(p[0], 3), "E_trial1_lower": round(p[0] - se[0], 3),
                     "E_trial15": round(p[14], 3), "E_trial15_lower": round(p[14] - se[14], 3),
                     "E_rho": round(rho, 3), "E_rho_p": prho,
                     "F_min": round(p2.min(), 3), "F_min_lower": round((p2 - se2).min(), 3),
                     "F_n_trial15": int(n2[14])})
    out = pd.DataFrame(rows)
    out["E_starts_at_chance"] = out.E_trial1_lower <= rt.CHANCE
    out["E_rises"] = (out.E_trial15_lower > out.E_trial1 + (out.E_trial1 - out.E_trial1_lower)) & (out.E_rho > 0) & (out.E_rho_p < 0.05)
    out["E_rises_plain"] = out.E_trial15 > out.E_trial1
    out["F_above_chance"] = out.F_min_lower > rt.CHANCE
    return out

ok = lambda g: bool(g.E_starts_at_chance.all() and g.E_rises.all() and g.F_above_chance.all())
res1ef = pd.concat([summarise_1ef(curves(reading, final)).assign(sessions_reading=reading, final_trial=final)
                    for reading in EXCLUDE for final in rt.FINAL_TRIAL_READINGS])
print(res1ef.to_string(index=False))
print("\nAll three conditions in all four subjects, per reading:")
print(res1ef.groupby(["sessions_reading", "final_trial"]).apply(ok).to_string())

# Reading (b): jaq with every candidate for the first excluded session (other subjects do not depend on it)
jb = pd.concat([summarise_1ef(curves(exclude=[first, NOT_ALL_ARMS], subjects=["jaq"])).assign(first=str(first))
                for first in B_FIRST_CHOICES])
print(f"\nReading (b), {rt.FINAL_TRIAL}, jaq over the {len(jb)} candidates for the first excluded session:")
print("  all three conditions hold in", int(sum(ok(jb.iloc[[i]]) for i in range(len(jb)))), "of", len(jb))
for c in ["blocks", "E_trial1", "E_trial1_lower", "E_trial15", "E_trial15_lower", "E_rho", "F_min_lower"]:
    print(f"  {c}: {jb[c].min()} to {jb[c].max()}")
print("  largest Spearman p:", f"{jb.E_rho_p.max():.1e}")
# Per-trial values, reading (a)
cva = curves("a: sessions 1 and 3 in order", rt.FINAL_TRIAL)
per = []
for s, mats in cva.items():
    for fig, mat in zip(["1E", "1F"], mats):
        p, se, n = rt.binomial_curve(mat)
        per += [{"subject": s, "figure": fig, "trial": t, "p": round(p[j], 3), "sem": round(se[j], 3), "n": int(n[j])}
                for j, t in enumerate(rt.CURVE_TRIALS)]
per = pd.DataFrame(per)
print("\nPer-trial reward rate, S.E.M. and blocks, reading (a):")
print(per.pivot(index="trial", columns=["figure", "subject"], values=["p", "sem", "n"]).to_string())
   subject  blocks  E_trial1  E_trial1_lower  E_trial15  E_trial15_lower  E_rho      E_rho_p  F_min  F_min_lower  F_n_trial15  E_starts_at_chance  E_rises  E_rises_plain  F_above_chance             sessions_reading        final_trial
       jaq      88     0.068           0.041      0.682            0.624  0.993 2.168121e-13  0.523        0.469           31                True     True           True            True a: sessions 1 and 3 in order first_after_switch
 roquefort      85     0.094           0.062      0.584            0.528  0.979 2.702101e-10  0.282        0.234           52                True     True           True            True a: sessions 1 and 3 in order first_after_switch
despereaux     109     0.128           0.096      0.639            0.578  0.979 2.645456e-10  0.477        0.429           21                True     True           True            True a: sessions 1 and 3 in order first_after_switch
  montague     166     0.133           0.106      0.696            0.644  0.943 1.424768e-07  0.619        0.558           27                True     True           True            True a: sessions 1 and 3 in order first_after_switch
       jaq      88     0.068           0.041      0.682            0.624  0.992 4.677605e-13  0.523        0.469           31                True     True           True            True a: sessions 1 and 3 in order     old_goal_visit
 roquefort      85     0.094           0.062      0.597            0.542  0.985 2.926161e-11  0.282        0.234           52                True     True           True            True a: sessions 1 and 3 in order     old_goal_visit
despereaux     109     0.128           0.096      0.639            0.578  0.996 2.415979e-15  0.468        0.420           21                True     True           True            True a: sessions 1 and 3 in order     old_goal_visit
  montague     167     0.132           0.106      0.696            0.644  0.950 6.086258e-08  0.619        0.558           27                True     True           True            True a: sessions 1 and 3 in order     old_goal_visit
       jaq      91     0.077           0.049      0.681            0.625  0.975 7.143706e-10  0.505        0.453           34                True     True           True            True      b: day 6 epochs 2 and 4 first_after_switch
 roquefort      85     0.094           0.062      0.584            0.528  0.979 2.702101e-10  0.282        0.234           52                True     True           True            True      b: day 6 epochs 2 and 4 first_after_switch
despereaux     109     0.128           0.096      0.639            0.578  0.979 2.645456e-10  0.477        0.429           21                True     True           True            True      b: day 6 epochs 2 and 4 first_after_switch
  montague     166     0.133           0.106      0.696            0.644  0.943 1.424768e-07  0.619        0.558           27                True     True           True            True      b: day 6 epochs 2 and 4 first_after_switch
       jaq      91     0.077           0.049      0.696            0.640  0.993 2.168121e-13  0.505        0.453           34                True     True           True            True      b: day 6 epochs 2 and 4     old_goal_visit
 roquefort      85     0.094           0.062      0.597            0.542  0.985 2.926161e-11  0.282        0.234           52                True     True           True            True      b: day 6 epochs 2 and 4     old_goal_visit
despereaux     109     0.128           0.096      0.639            0.578  0.996 2.415979e-15  0.468        0.420           21                True     True           True            True      b: day 6 epochs 2 and 4     old_goal_visit
  montague     167     0.132           0.106      0.696            0.644  0.950 6.086258e-08  0.619        0.558           27                True     True           True            True      b: day 6 epochs 2 and 4     old_goal_visit
       jaq      96     0.073           0.046      0.676            0.621  0.975 7.143706e-10  0.490        0.439           38                True     True           True            True             c, variant: none first_after_switch
 roquefort      85     0.094           0.062      0.584            0.528  0.979 2.702101e-10  0.282        0.234           52                True     True           True            True             c, variant: none first_after_switch
despereaux     109     0.128           0.096      0.639            0.578  0.979 2.645456e-10  0.477        0.429           21                True     True           True            True             c, variant: none first_after_switch
  montague     166     0.133           0.106      0.696            0.644  0.943 1.424768e-07  0.619        0.558           27                True     True           True            True             c, variant: none first_after_switch
       jaq      96     0.073           0.046      0.689            0.635  0.993 2.168121e-13  0.490        0.439           38                True     True           True            True             c, variant: none     old_goal_visit
 roquefort      85     0.094           0.062      0.597            0.542  0.985 2.926161e-11  0.282        0.234           52                True     True           True            True             c, variant: none     old_goal_visit
despereaux     109     0.128           0.096      0.639            0.578  0.996 2.415979e-15  0.468        0.420           21                True     True           True            True             c, variant: none     old_goal_visit
  montague     167     0.132           0.106      0.696            0.644  0.950 6.086258e-08  0.619        0.558           27                True     True           True            True             c, variant: none     old_goal_visit

All three conditions in all four subjects, per reading:
sessions_reading              final_trial       
a: sessions 1 and 3 in order  first_after_switch    True
                              old_goal_visit        True
b: day 6 epochs 2 and 4       first_after_switch    True
                              old_goal_visit        True
c, variant: none              first_after_switch    True
                              old_goal_visit        True
Reading (b), first_after_switch, jaq over the 26 candidates for the first excluded session:
  all three conditions hold in 26 of 26
  blocks: 88 to 93
  E_trial1: 0.065 to 0.08
  E_trial1_lower: 0.039 to 0.051
  E_trial15: 0.662 to 0.71
  E_trial15_lower: 0.604 to 0.656
  E_rho: 0.971 to 0.993
  F_min_lower: 0.42 to 0.453
  largest Spearman p: 1.7e-09
Per-trial reward rate, S.E.M. and blocks, reading (a):
             p                                                                       sem                                                                        n                                                                  
figure      1E     1F        1E        1F         1E         1F       1E       1F     1E     1F        1E        1F         1E         1F       1E       1F    1E    1F        1E        1F         1E         1F       1E       1F
subject    jaq    jaq roquefort roquefort despereaux despereaux montague montague    jaq    jaq roquefort roquefort despereaux despereaux montague montague   jaq   jaq roquefort roquefort despereaux despereaux montague montague
trial                                                                                                                                                                                                                              
1        0.068  0.523     0.094     0.282      0.128      0.477    0.133    0.699  0.027  0.053     0.032     0.049      0.032      0.048    0.026    0.036  88.0  88.0      85.0      85.0      109.0      109.0    166.0    166.0
2        0.091  0.557     0.153     0.447      0.193      0.624    0.169    0.753  0.031  0.053     0.039     0.054      0.038      0.046    0.029    0.033  88.0  88.0      85.0      85.0      109.0      109.0    166.0    166.0
3        0.170  0.591     0.153     0.435      0.248      0.697    0.295    0.789  0.040  0.052     0.039     0.054      0.041      0.044    0.035    0.032  88.0  88.0      85.0      85.0      109.0      109.0    166.0    166.0
4        0.227  0.659     0.153     0.518      0.321      0.712    0.392    0.812  0.045  0.051     0.039     0.054      0.045      0.044    0.038    0.031  88.0  88.0      85.0      85.0      109.0      104.0    166.0    160.0
5        0.273  0.701     0.200     0.541      0.312      0.732    0.448    0.809  0.047  0.049     0.043     0.054      0.044      0.045    0.039    0.032  88.0  87.0      85.0      85.0      109.0       97.0    165.0    152.0
6        0.432  0.776     0.306     0.643      0.439      0.720    0.515    0.809  0.053  0.045     0.050     0.052      0.048      0.047    0.039    0.034  88.0  85.0      85.0      84.0      107.0       93.0    163.0    136.0
7        0.443  0.714     0.388     0.554      0.437      0.728    0.625    0.708  0.053  0.049     0.053     0.055      0.049      0.049    0.038    0.044  88.0  84.0      85.0      83.0      103.0       81.0    160.0    106.0
8        0.489  0.780     0.353     0.598      0.474      0.730    0.669    0.719  0.053  0.046     0.052     0.054      0.051      0.052    0.038    0.046  88.0  82.0      85.0      82.0       97.0       74.0    151.0     96.0
9        0.580  0.762     0.429     0.634      0.516      0.758    0.621    0.759  0.053  0.048     0.054     0.053      0.051      0.053    0.041    0.047  88.0  80.0      84.0      82.0       95.0       66.0    140.0     83.0
10       0.632  0.754     0.452     0.662      0.548      0.709    0.657    0.619  0.052  0.055     0.054     0.056      0.052      0.061    0.041    0.061  87.0  61.0      84.0      71.0       93.0       55.0    137.0     63.0
11       0.609  0.804     0.451     0.582      0.588      0.727    0.656    0.667  0.052  0.058     0.055     0.060      0.053      0.067    0.041    0.066  87.0  46.0      82.0      67.0       85.0       44.0    131.0     51.0
12       0.671  0.762     0.524     0.697      0.585      0.833    0.664    0.744  0.052  0.066     0.055     0.057      0.054      0.062    0.044    0.067  82.0  42.0      82.0      66.0       82.0       36.0    116.0     43.0
13       0.675  0.732     0.481     0.672      0.640      0.750    0.722    0.730  0.053  0.069     0.056     0.060      0.055      0.082    0.043    0.073  77.0  41.0      81.0      61.0       75.0       28.0    108.0     37.0
14       0.714  0.703     0.519     0.649      0.735      0.783    0.734    0.667  0.054  0.075     0.056     0.063      0.054      0.086    0.046    0.086  70.0  37.0      79.0      57.0       68.0       23.0     94.0     30.0
15       0.682  0.677     0.584     0.692      0.639      0.810    0.696    0.741  0.057  0.084     0.056     0.064      0.061      0.086    0.052    0.084  66.0  31.0      77.0      52.0       61.0       21.0     79.0     27.0
In [12]:
cv = curves("a: sessions 1 and 3 in order", rt.FINAL_TRIAL)
fig, axes = plt.subplots(1, 2, figsize=(10, 3.8), sharey=True)
cols = ["#1b5c29", "#197b64", "#219fa9", "#7be1bf"]
for s, c in zip(rt.SUBJECTS, cols):
    for ax, mat in zip(axes, cv[s]):
        p, se, n = rt.binomial_curve(mat)
        ax.fill_between(rt.CURVE_TRIALS, p - se, p + se, color=c, alpha=0.3, lw=0)
        ax.plot(rt.CURVE_TRIALS, p, ".-", color=c, label=f"{s} ({len(mat)} blocks)")
for ax, t in zip(axes, ["trials since goal change (1E)", "trials since first reward at new goal (1F)"]):
    ax.axhline(rt.CHANCE, color="k", ls=":")
    ax.set_xlabel(t)
    ax.set_ylim(0, 1)
axes[0].set_ylabel("reward rate")
axes[1].legend(fontsize=8)
plt.tight_layout()
plt.show()
lo = min(np.nanmin(rt.binomial_curve(m)[0] - rt.binomial_curve(m)[1]) for s in rt.SUBJECTS for m in cv[s])
hi = max(np.nanmax(rt.binomial_curve(m)[0] + rt.binomial_curve(m)[1]) for s in rt.SUBJECTS for m in cv[s])
print(f"Plotted values (mean +- S.E.M.) span {lo:.3f} to {hi:.3f}; none fall outside the axes (0 to 1).")
No description has been provided for this image
Plotted values (mean +- S.E.M.) span 0.041 to 0.895; none fall outside the axes (0 to 1).

Result: reproduced. With the first trial after each goal change closing the old block, under reading (a) and under reading (b) for every candidate first session of jaq, all three conditions hold in all four subjects. The trial 1 mean of Figure 1E is 0.065 to 0.133, with its lower band at 0.106 or below; jaq (0.068) and roquefort (0.094) start below chance, not at it, which the criterion's "or lies below" allows. The rate rises to 0.584 to 0.710 by trial 15, with bands clear of trial 1's, and the Spearman correlation with trial number is 0.943 to 0.993. This test of "rises" is stricter than the criterion, which only says the rate rises; the plain reading (trial 15 above trial 1) also holds in every subject. After the first reward at the new goal, every point of the band is above 0.125, and the lowest lower bound is 0.234 (roquefort). The closing-trial rule settled by the answer moves no condition. Under the earlier old-goal-visit reading the same three conditions also hold.

fig6b-visits-decay (behavioural half only)¶

The behavioural bias to the previously rewarded arm decays very quickly after the switch, returning to baseline within a few trials.

Criterion: as fig6a-pg-replay-persists for visits (1 if the arm was visited on that trial), unsmoothed. Per session, for blocks 1 to 8, the goal arm's visits from 40 trials before to 40 after the block's last rewarded trial (trial 0), NaN beyond the session, against the same window for every arm never a goal in the session; per trial a Wilcoxon rank-sum test of goal against non-goal, Bonferroni corrected (0.05/80 in the legend, 0.05/81 in the code). Reproduced when, in all four subjects, the last trial after 0 with a significant goal over non-goal difference is no later than the bound, (a) +3 or (b) +5, and the replay enrichment of fig6a extends beyond it. The second part needs replay and is blocked; this section computes the first, which the verifier asked for. The test is scipy's Mann-Whitney U with the normal approximation and tie correction; scipy's ranksums, without tie correction, is shown as a variant, and so are completed blocks only. The paper's code is in Matlab, whose ranksum corrects for ties in its normal approximation for large samples, so the tie-corrected form is likely the code's; the claims file names only a "Wilcoxon rank-sum test", and the question asked on this is still open, so both forms are kept.

In [13]:
OFFS = np.arange(-rt.VISIT_WINDOW, rt.VISIT_WINDOW + 1)
N_TESTS = {"0.05/80 (legend)": 80, "0.05/81 (code)": 81}
BOUNDS = {"a: +3": 3, "b: +5": 5}

def visit_sets(ss, completed_only=False):
    out = {}
    for s in rt.SUBJECTS:
        G, N = zip(*[rt.visit_traces(rt.label_task_phase(r["trials"]), completed_only) for r in ss[ss.subject == s].run])
        out[s] = (np.vstack(G), np.vstack(N))
    return out

def trialwise(G, N, test="mannwhitneyu"):
    p = np.full(len(OFFS), np.nan)
    for j in range(len(OFFS)):
        g, n = G[:, j][~np.isnan(G[:, j])], N[:, j][~np.isnan(N[:, j])]
        if len(g) and len(n):
            p[j] = (stats.mannwhitneyu(g, n, alternative="two-sided", method="asymptotic").pvalue if test == "mannwhitneyu"
                    else stats.ranksums(g, n).pvalue)
    return np.nanmean(G, axis=0), np.nanmean(N, axis=0), p

def summarise_6b(vs, test="mannwhitneyu"):
    rows = []
    for s, (G, N) in vs.items():
        gm, nm, p = trialwise(G, N, test)
        for lab, k in N_TESTS.items():
            sig = p < 0.05 / k
            above = OFFS[sig & (gm > nm) & (OFFS > 0)]
            below = OFFS[sig & (gm < nm) & (OFFS > 0)]
            rows.append({"subject": s, "alpha": lab, "goal_traces": len(G), "nongoal_traces": len(N),
                         "last_sig_above_after_0": int(above.max()) if len(above) else None,
                         "sig_above_after_0": " ".join(map(str, above)),
                         "sig_below_after_0": " ".join(map(str, below)),
                         "sig_above_before_0": int(np.sum(sig & (gm > nm) & (OFFS < 0)))})
    out = pd.DataFrame(rows)
    for b, v in BOUNDS.items():
        out["within_" + b] = out.last_sig_above_after_0.fillna(0) <= v
    return out

res6b = []
for reading in EXCLUDE:
    for comp in (False, True):
        res6b.append(summarise_6b(visit_sets(session_set(reading), comp)).assign(
            sessions_reading=reading, blocks="completed only (variant)" if comp else "blocks 1 to 8"))
res6b.append(summarise_6b(visit_sets(session_set("a: sessions 1 and 3 in order")), "ranksums").assign(
    sessions_reading="a: sessions 1 and 3 in order", blocks="blocks 1 to 8, ranksums without tie correction (variant)"))
res6b = pd.concat(res6b)
print(res6b.drop(columns=["sig_above_before_0"]).to_string(index=False))
print("\nBehavioural half holds in all four subjects (last significant goal-above trial after 0 within the bound):")
print(res6b.groupby(["sessions_reading", "blocks", "alpha"])[["within_a: +3", "within_b: +5"]].all().to_string())

# Reading (b): jaq with every candidate for the first excluded session
jb6 = pd.concat([summarise_6b({"jaq": visit_sets(session_set(exclude=[f, NOT_ALL_ARMS]))["jaq"]}).assign(first=str(f))
                 for f in B_FIRST_CHOICES])
print(f"\nReading (b), jaq over the {len(B_FIRST_CHOICES)} candidates: last significant goal-above trial after 0 from",
      jb6.last_sig_above_after_0.min(), "to", jb6.last_sig_above_after_0.max(), "; goal traces",
      jb6.goal_traces.min(), "to", jb6.goal_traces.max())

# Mean visit rates around trial 0, reading (a), blocks 1 to 8
vs = visit_sets(session_set("a: sessions 1 and 3 in order"))
tab = []
for s, (G, N) in vs.items():
    gm, nm, p = trialwise(G, N)
    for t in range(-3, 11):
        j = rt.VISIT_WINDOW + t
        tab.append({"subject": s, "trial": t, "goal": round(gm[j], 3), "nongoal": round(nm[j], 3), "p": f"{p[j]:.1e}",
                    "n_goal": int(np.sum(~np.isnan(G[:, j]))), "n_nongoal": int(np.sum(~np.isnan(N[:, j])))})
tab = pd.DataFrame(tab)
print("\nVisit probability of the goal arm and of never-goal arms, trials -3 to +10, reading (a):")
print(tab.pivot(index="trial", columns="subject", values=["goal", "nongoal", "p"]).reindex(columns=rt.SUBJECTS, level=1).to_string())
print("\nGoal traces per subject (legend of Figure 6A: 89, 85, 104 and 161 goal arms; 347, 437, 268 and 397 unrewarded arms):",
      {s: (len(G), len(N)) for s, (G, N) in vs.items()})

# Late significant trials: counts behind them, under both forms of the test
for s, (G, N) in vs.items():
    gm, nm, p = trialwise(G, N)
    for t in OFFS[(OFFS > 5) & (p < 0.05 / 81) & (gm > nm)]:
        j = rt.VISIT_WINDOW + t
        g, n = G[:, j][~np.isnan(G[:, j])], N[:, j][~np.isnan(N[:, j])]
        print(f"\n{s}, trial +{t}: goal visited in {int(g.sum())} of {len(g)} traces, never-goal arms in {int(n.sum())} of {len(n)}; "
              f"p = {p[j]:.1e} with tie correction, {stats.ranksums(g, n).pvalue:.3f} without")


# Roquefort's late significant trial: what the goal-arm visits behind it are
ss = session_set("a: sessions 1 and 3 in order")
t = 29
hits = []
for _, row in ss[ss.subject == "roquefort"].iterrows():
    v = rt.label_task_phase(row.run["trials"]).reset_index(drop=True)
    for k in range(1, rt.VISIT_BLOCKS + 1):
        rows = np.where(v.block == k)[0]
        rew = rows[v.rewarded[rows] & ~v.final[rows]]
        if len(rew) == 0:
            continue
        i, g = rew[-1] + t, v.block_goal[rows[0]]
        if i < len(v) and v.outer[i] == g:
            hits.append({"day": row.day, "epoch": row.epoch, "block": k, "goal": g, "block_completed": bool(v.final[rows].any()),
                         "block_at_trial": int(v.block[i]), "goal_at_trial": int(v.block_goal[i]), "rewarded": bool(v.rewarded[i]),
                         "arm_is_goal_at_trial": bool(v.block_goal[i] == g)})
hits = pd.DataFrame(hits)
print(f"\nroquefort, trial +{t}, reading (a): the goal-trace visits behind the significant trial")
print(hits.to_string(index=False))
print("  visits made while the same arm is the goal again (a later block):", int(hits.arm_is_goal_at_trial.sum()), "of", len(hits),
      "; rewarded:", int(hits.rewarded.sum()))
# Goal visits and p (tie-corrected) on trials +20 to +40, roquefort
G, N = vs["roquefort"]
gm, nm, p = trialwise(G, N)
late = pd.DataFrame({"trial": OFFS, "goal": np.round(gm, 3), "nongoal": np.round(nm, 3), "p": [f"{x:.1e}" for x in p],
                     "n_goal": np.sum(~np.isnan(G), axis=0), "n_nongoal": np.sum(~np.isnan(N), axis=0)})
print("\nroquefort, trials +20 to +40, reading (a):")
print(late[late.trial >= 20].set_index("trial").T.to_string())
   subject            alpha  goal_traces  nongoal_traces  last_sig_above_after_0 sig_above_after_0 sig_below_after_0  within_a: +3  within_b: +5             sessions_reading                                                   blocks
       jaq 0.05/80 (legend)           94             335                       2               1 2                            True          True a: sessions 1 and 3 in order                                            blocks 1 to 8
       jaq   0.05/81 (code)           94             335                       2               1 2                            True          True a: sessions 1 and 3 in order                                            blocks 1 to 8
 roquefort 0.05/80 (legend)           95             416                      29          1 2 3 29                           False         False a: sessions 1 and 3 in order                                            blocks 1 to 8
 roquefort   0.05/81 (code)           95             416                      29          1 2 3 29                           False         False a: sessions 1 and 3 in order                                            blocks 1 to 8
despereaux 0.05/80 (legend)          112             254                       3             1 2 3                            True          True a: sessions 1 and 3 in order                                            blocks 1 to 8
despereaux   0.05/81 (code)          112             254                       3             1 2 3                            True          True a: sessions 1 and 3 in order                                            blocks 1 to 8
  montague 0.05/80 (legend)          169             303                       2               1 2                            True          True a: sessions 1 and 3 in order                                            blocks 1 to 8
  montague   0.05/81 (code)          169             303                       2               1 2                            True          True a: sessions 1 and 3 in order                                            blocks 1 to 8
       jaq 0.05/80 (legend)           76             262                       2               1 2                            True          True a: sessions 1 and 3 in order                                 completed only (variant)
       jaq   0.05/81 (code)           76             262                       2               1 2                            True          True a: sessions 1 and 3 in order                                 completed only (variant)
 roquefort 0.05/80 (legend)           80             348                      29          1 2 3 29                           False         False a: sessions 1 and 3 in order                                 completed only (variant)
 roquefort   0.05/81 (code)           80             348                      29          1 2 3 29                           False         False a: sessions 1 and 3 in order                                 completed only (variant)
despereaux 0.05/80 (legend)          100             221                       3             1 2 3                            True          True a: sessions 1 and 3 in order                                 completed only (variant)
despereaux   0.05/81 (code)          100             221                       3             1 2 3                            True          True a: sessions 1 and 3 in order                                 completed only (variant)
  montague 0.05/80 (legend)          154             258                       2               1 2                            True          True a: sessions 1 and 3 in order                                 completed only (variant)
  montague   0.05/81 (code)          154             258                       2               1 2                            True          True a: sessions 1 and 3 in order                                 completed only (variant)
       jaq 0.05/80 (legend)           97             340                       3             1 2 3                            True          True      b: day 6 epochs 2 and 4                                            blocks 1 to 8
       jaq   0.05/81 (code)           97             340                       3             1 2 3                            True          True      b: day 6 epochs 2 and 4                                            blocks 1 to 8
 roquefort 0.05/80 (legend)           95             416                      29          1 2 3 29                           False         False      b: day 6 epochs 2 and 4                                            blocks 1 to 8
 roquefort   0.05/81 (code)           95             416                      29          1 2 3 29                           False         False      b: day 6 epochs 2 and 4                                            blocks 1 to 8
despereaux 0.05/80 (legend)          112             254                       3             1 2 3                            True          True      b: day 6 epochs 2 and 4                                            blocks 1 to 8
despereaux   0.05/81 (code)          112             254                       3             1 2 3                            True          True      b: day 6 epochs 2 and 4                                            blocks 1 to 8
  montague 0.05/80 (legend)          169             303                       2               1 2                            True          True      b: day 6 epochs 2 and 4                                            blocks 1 to 8
  montague   0.05/81 (code)          169             303                       2               1 2                            True          True      b: day 6 epochs 2 and 4                                            blocks 1 to 8
       jaq 0.05/80 (legend)           78             264                       3             1 2 3                            True          True      b: day 6 epochs 2 and 4                                 completed only (variant)
       jaq   0.05/81 (code)           78             264                       3             1 2 3                            True          True      b: day 6 epochs 2 and 4                                 completed only (variant)
 roquefort 0.05/80 (legend)           80             348                      29          1 2 3 29                           False         False      b: day 6 epochs 2 and 4                                 completed only (variant)
 roquefort   0.05/81 (code)           80             348                      29          1 2 3 29                           False         False      b: day 6 epochs 2 and 4                                 completed only (variant)
despereaux 0.05/80 (legend)          100             221                       3             1 2 3                            True          True      b: day 6 epochs 2 and 4                                 completed only (variant)
despereaux   0.05/81 (code)          100             221                       3             1 2 3                            True          True      b: day 6 epochs 2 and 4                                 completed only (variant)
  montague 0.05/80 (legend)          154             258                       2               1 2                            True          True      b: day 6 epochs 2 and 4                                 completed only (variant)
  montague   0.05/81 (code)          154             258                       2               1 2                            True          True      b: day 6 epochs 2 and 4                                 completed only (variant)
       jaq 0.05/80 (legend)          103             366                       3             1 2 3                            True          True             c, variant: none                                            blocks 1 to 8
       jaq   0.05/81 (code)          103             366                       3             1 2 3                            True          True             c, variant: none                                            blocks 1 to 8
 roquefort 0.05/80 (legend)           95             416                      29          1 2 3 29                           False         False             c, variant: none                                            blocks 1 to 8
 roquefort   0.05/81 (code)           95             416                      29          1 2 3 29                           False         False             c, variant: none                                            blocks 1 to 8
despereaux 0.05/80 (legend)          112             254                       3             1 2 3                            True          True             c, variant: none                                            blocks 1 to 8
despereaux   0.05/81 (code)          112             254                       3             1 2 3                            True          True             c, variant: none                                            blocks 1 to 8
  montague 0.05/80 (legend)          169             303                       2               1 2                            True          True             c, variant: none                                            blocks 1 to 8
  montague   0.05/81 (code)          169             303                       2               1 2                            True          True             c, variant: none                                            blocks 1 to 8
       jaq 0.05/80 (legend)           83             286                       3             1 2 3                            True          True             c, variant: none                                 completed only (variant)
       jaq   0.05/81 (code)           83             286                       3             1 2 3                            True          True             c, variant: none                                 completed only (variant)
 roquefort 0.05/80 (legend)           80             348                      29          1 2 3 29                           False         False             c, variant: none                                 completed only (variant)
 roquefort   0.05/81 (code)           80             348                      29          1 2 3 29                           False         False             c, variant: none                                 completed only (variant)
despereaux 0.05/80 (legend)          100             221                       3             1 2 3                            True          True             c, variant: none                                 completed only (variant)
despereaux   0.05/81 (code)          100             221                       3             1 2 3                            True          True             c, variant: none                                 completed only (variant)
  montague 0.05/80 (legend)          154             258                       2               1 2                            True          True             c, variant: none                                 completed only (variant)
  montague   0.05/81 (code)          154             258                       2               1 2                            True          True             c, variant: none                                 completed only (variant)
       jaq 0.05/80 (legend)           94             335                       2               1 2                            True          True a: sessions 1 and 3 in order blocks 1 to 8, ranksums without tie correction (variant)
       jaq   0.05/81 (code)           94             335                       2               1 2                            True          True a: sessions 1 and 3 in order blocks 1 to 8, ranksums without tie correction (variant)
 roquefort 0.05/80 (legend)           95             416                       2               1 2                            True          True a: sessions 1 and 3 in order blocks 1 to 8, ranksums without tie correction (variant)
 roquefort   0.05/81 (code)           95             416                       2               1 2                            True          True a: sessions 1 and 3 in order blocks 1 to 8, ranksums without tie correction (variant)
despereaux 0.05/80 (legend)          112             254                       2               1 2                            True          True a: sessions 1 and 3 in order blocks 1 to 8, ranksums without tie correction (variant)
despereaux   0.05/81 (code)          112             254                       2               1 2                            True          True a: sessions 1 and 3 in order blocks 1 to 8, ranksums without tie correction (variant)
  montague 0.05/80 (legend)          169             303                       2               1 2                            True          True a: sessions 1 and 3 in order blocks 1 to 8, ranksums without tie correction (variant)
  montague   0.05/81 (code)          169             303                       2               1 2                            True          True a: sessions 1 and 3 in order blocks 1 to 8, ranksums without tie correction (variant)

Behavioural half holds in all four subjects (last significant goal-above trial after 0 within the bound):
                                                                                                        within_a: +3  within_b: +5
sessions_reading             blocks                                                   alpha                                       
a: sessions 1 and 3 in order blocks 1 to 8                                            0.05/80 (legend)         False         False
                                                                                      0.05/81 (code)           False         False
                             blocks 1 to 8, ranksums without tie correction (variant) 0.05/80 (legend)          True          True
                                                                                      0.05/81 (code)            True          True
                             completed only (variant)                                 0.05/80 (legend)         False         False
                                                                                      0.05/81 (code)           False         False
b: day 6 epochs 2 and 4      blocks 1 to 8                                            0.05/80 (legend)         False         False
                                                                                      0.05/81 (code)           False         False
                             completed only (variant)                                 0.05/80 (legend)         False         False
                                                                                      0.05/81 (code)           False         False
c, variant: none             blocks 1 to 8                                            0.05/80 (legend)         False         False
                                                                                      0.05/81 (code)           False         False
                             completed only (variant)                                 0.05/80 (legend)         False         False
                                                                                      0.05/81 (code)           False         False
Reading (b), jaq over the 26 candidates: last significant goal-above trial after 0 from 2 to 3 ; goal traces 95 to 100
Visit probability of the goal arm and of never-goal arms, trials -3 to +10, reading (a):
          goal                               nongoal                                      p                               
subject    jaq roquefort despereaux montague     jaq roquefort despereaux montague      jaq roquefort despereaux  montague
trial                                                                                                                     
-3       0.851     0.853      0.839    0.864   0.024     0.012      0.016     0.03  8.5e-69   9.9e-87    2.9e-60   2.9e-76
-2       0.862     0.863       0.83    0.893   0.015      0.01      0.016    0.013  3.2e-73   2.3e-89    2.3e-59   1.0e-84
-1        0.83     0.811       0.92    0.899    0.03     0.026      0.012     0.01  1.9e-64   2.3e-74    1.7e-69   1.9e-86
 0         1.0       1.0        1.0      1.0     0.0       0.0        0.0      0.0  4.5e-95  6.4e-113    2.3e-81  2.0e-104
 1       0.854     0.843      0.856    0.898   0.021      0.01      0.017    0.015  6.0e-61   6.3e-81    1.5e-57   2.7e-77
 2       0.444     0.476      0.392    0.333   0.099     0.077      0.061    0.077  5.6e-13   3.7e-20    4.9e-14   2.4e-11
 3       0.247     0.256       0.25    0.233   0.112     0.087      0.067    0.122  2.9e-03   1.8e-05    4.2e-06   3.3e-03
 4       0.091      0.15      0.152    0.162   0.134     0.132      0.091    0.102  3.1e-01   6.7e-01    1.1e-01   7.8e-02
 5       0.173     0.169      0.133    0.144   0.107     0.119      0.097    0.072  1.2e-01   2.4e-01    3.4e-01   2.1e-02
 6       0.189      0.23      0.115    0.083   0.098     0.102        0.1    0.081  3.2e-02   2.7e-03    7.1e-01   9.4e-01
 7       0.055     0.125      0.118    0.085   0.083     0.086       0.06    0.045  4.2e-01   3.0e-01    8.3e-02   1.2e-01
 8       0.123     0.127      0.067    0.079   0.071     0.084      0.083    0.046  1.6e-01   2.6e-01    6.4e-01   2.0e-01
 9       0.111     0.029      0.101    0.074   0.048     0.108      0.078    0.045  5.3e-02   4.0e-02    5.2e-01   2.4e-01
 10      0.056     0.074      0.079    0.053   0.049     0.091      0.073    0.051  8.1e-01   6.5e-01    8.7e-01   9.6e-01

Goal traces per subject (legend of Figure 6A: 89, 85, 104 and 161 goal arms; 347, 437, 268 and 397 unrewarded arms): {'jaq': (94, 335), 'roquefort': (95, 416), 'despereaux': (112, 254), 'montague': (169, 303)}

roquefort, trial +29: goal visited in 9 of 39 traces, never-goal arms in 8 of 170; p = 1.6e-04 with tie correction, 0.074 without
roquefort, trial +29, reading (a): the goal-trace visits behind the significant trial
 day  epoch  block  goal  block_completed  block_at_trial  goal_at_trial  rewarded  arm_is_goal_at_trial
   9      4      1     3             True               2              2     False                 False
  10      2      2     8             True               4              3     False                 False
  12      4      1     7             True               2              3     False                 False
  13      4      1     2             True               2              5     False                 False
  14      4      1     3             True               3              2     False                 False
  17      4      2     7             True               4              6     False                 False
  18      4      2     3             True               4              6     False                 False
  19      2      2     5             True               4              6     False                 False
  21      2      1     6             True               3              8     False                 False
  visits made while the same arm is the goal again (a later block): 0 of 9 ; rewarded: 0

roquefort, trials +20 to +40, reading (a):
trial           20       21       22       23       24       25       26       27       28       29       30       31       32       33       34       35       36       37       38       39       40
goal         0.093    0.038    0.038    0.038    0.118    0.085    0.068    0.098    0.075    0.231    0.051    0.053    0.132    0.108    0.216    0.028    0.056      0.0    0.086    0.094    0.103
nongoal      0.072    0.056    0.079    0.057    0.086    0.084    0.094    0.096    0.092    0.047    0.088    0.079    0.079    0.075    0.069    0.071    0.077    0.101     0.04    0.044    0.048
p          6.1e-01  5.9e-01  3.1e-01  5.9e-01  4.8e-01  9.8e-01  5.9e-01  9.7e-01  7.4e-01  1.6e-04  4.5e-01  5.8e-01  3.1e-01  5.2e-01  6.7e-03  3.4e-01  6.5e-01  5.1e-02  2.7e-01  2.6e-01  2.6e-01
n_goal          54       53       52       52       51       47       44       41       40       39       39       38       38       37       37       36       36       35       35       32       29
n_nongoal      235      231      227      227      222      203      191      178      174      170      170      164      164      159      159      155      155      149      149      137      124

Result: blocked (too_large). The criterion also needs the replay enrichment of fig6a-pg-replay-persists, which needs ripples and decoding; only the behavioural half is computed here, and it holds in three subjects of four. On trial +1 (the closing trial for a completed block, the next trial of the same block for the open last block of a session) the goal arm is visited in 0.84 to 0.90 of blocks, then in 0.33 to 0.48 on +2 and 0.23 to 0.26 on +3, against 0.06 to 0.12 for the never-goal arms. In jaq, despereaux and montague the last trial after 0 with the goal significantly above the never-goal arms is +2 or +3, within both bounds, at 0.05/80 and 0.05/81, under every session reading, with completed blocks only, and for jaq over all 26 reading (b) candidates (+2 to +3). In roquefort trials +1 to +3 are significant, and so is the single trial +29 (goal visited in 9 of 39 traces, never-goal arms in 8 of 170, p = 1.6e-4), so its last significant trial is +29 and the behavioural half fails under both bounds. Trial +29 stands alone: trials +20 to +40 other than +29 have p of 6.7e-3 or more, against 6.3e-4 and 6.2e-4 for 0.05/80 and 0.05/81, and its neighbours +28 and +30 have p = 0.74 and 0.45. Its 9 goal visits come from 9 different sessions, all in a later block, none rewarded and none made while the arm was the goal again. Without tie correction (scipy's ranksums), +29 is not significant (p = 0.074) and every subject ends at +2, within both bounds. The claims file says only "Wilcoxon rank-sum test", so the behavioural half's result depends on this choice, and a question is asked. No subject has a trial after 0 with the goal significantly below the never-goal arms. The goal traces are 94, 95, 112 and 169 under reading (a), against the 89, 85, 104 and 161 goal arms of the legend.

Claims not tested¶

The 31 other claims (fig6b-visits-decay among them, for its replay half) rest on sharp-wave ripples, multiunit events or the clusterless state space decoder. The dandiset holds neither these nor the spikes or LFP they are computed from, only the raw 30 kHz broadband, about 9.1 TB in total and stored one channel per chunk. The data check above measures the streaming rate and shows that reading the run epochs once would take far longer than the 30-minute limit, before any spike detection, ripple filtering or decoding. They are blocked as too_large. Ripple detection would also need the CA1 cell-layer tetrodes and the corpus callosum reference tetrode, which the electrode table does not identify (every location is "None"). fig6b-visits-decay is behavioural in part: its behavioural half is computed in the section above, but its criterion compares the visit decay with the replay enrichment of fig6a-pg-replay-persists, so it is blocked with it.

Summary¶

claim outcome
fig1d-sessions-blocks reproduced
fig1ef-reward-rate reproduced
fig6b-visits-decay blocked, too_large (behavioural half: holds in jaq, despereaux and montague; fails in roquefort at trial +29 with tie correction, holds without)
the 30 other replay, ripple and decoding claims blocked, too_large

How the analysis differs from the paper's. Trials are rebuilt from the StateScript logs in the files, not from the paper's preprocessed trial structures. Task phases follow the claims file's account of label_trial_interval.m, with the first valid trial after each goal change in the old block, as a reader's answer settled from the code. Which jaq sessions are "sessions 1 and 3" is not fixed by the paper. Both readings the criterion allows are run: (a) in order of recording, and (b) the sessions the Methods describe. Under (b), day 6 epoch 4 is the one session where not all arms were visited, and the session with poor decoding cannot be found without the decoder, so every candidate is run. All readings give the same outcomes. Sessions are not selected by decode quality (the code's gooddecode), which needs the decoder. The rank-sum test of fig6b-visits-decay is run with and without tie correction, since the claims file does not say which.

What was found about the dataset.

  • The files hold raw broadband, behavioural events, position and task logs, but no spikes, LFP, ripple times, linearised position or decoding results. Every replay finding of the paper has to be recomputed from about 9.1 TB of raw data, which this registry cannot do.
  • The electrode table gives no location for any of the 128 channels, so the CA1 tetrodes and the reference tetrode cannot be identified.
  • The files do not mark which run sessions the paper analysed. They hold 27 and 24 run epochs for jaq and despereaux, where the paper used 26 (before excluding two) and 23. Which epoch is extra cannot be told; leaving out any one keeps the block counts within tolerance.
  • No log uses forage assist, including the five without a header. Two blocks have one reward fewer than programmed because the first trial after the switch, a rewarded visit to the new goal, belongs to the old block.
  • Trial counts are close to the legends' for search and correct repeat trials, but error trials are 11 to 24% more than Figure 5B's.
  • The behaviour in the logs matches the hardware: rewards equal the pump onsets in 115 of 116 epochs. The block counts are within 5% of the paper's for jaq (88 to 93 against 89) and despereaux (109 against 105), and equal for roquefort (85) and montague (166).
  • The draft version's files were rewritten in 2022, and in the file compared its position timestamps are off the DIO clock by about -1.59e9 s; the published version is consistent.
  • Position is sampled at about 33 Hz (Methods: 30 Hz); most epochs end with NaN timestamps.
  • In one epoch (montague day 16 epoch 2) the log's clock steps by about 3.4 s against the DIO, and in one (jaq day 6 epoch 4) the log stops before a final pump.