Earlier findings checked on CRCNS:fcx-1 (unversioned)¶

This notebook belongs to the reconciliation of attempt watson-2016-03 with attempt watson-2016-02 (docs/protocol.md, "Repeat attempts"). watson-2016-02 tested the paper on CRCNS:fcx-1 alone and recorded ten findings; watson-2016-03 tested it on DANDI:000041 version 0.261104.0300 and CRCNS:fcx-1. watson-2016-03 reports the same problem as earlier findings 2, 4, 7 and 10 (its findings 7, 6, 8 and 11). The other six, 1, 3, 5, 6, 8 and 9, all about the CRCNS files, are checked here, and so are the parts of findings 2 and 4 that watson-2016-03 does not report. All of them concern CRCNS:fcx-1, which is unversioned and is pinned by the MD5 sums of its checksums.md5, printed below. Each of the 27 session tar.gz files is streamed once from the public bucket with the entry's helper watson.py (its PrefetchReader), and only the member list and the _WSRestrictedIntervals.mat, _BasicMetaData.mat and _Motion.mat files are kept. Nothing is written to disk. Each section opens with the earlier statement. The conclusions are in the reconciliation block of attempts/watson-2016-03.yaml.

In [1]:
import io
import re
import tarfile
import time
import zipfile
from concurrent.futures import ThreadPoolExecutor

import numpy as np
import requests

import watson

DOCS = watson.CRCNS_BASE + "docs/"
sums = dict((n, m) for m, n in re.findall(r"(\w{32})\s+(\S+)", requests.get(watson.CRCNS_BASE + "checksums.md5", timeout=60).text))
print(f"CRCNS:{watson.CRCNS_ID} ({watson.CRCNS_VERSION}), doi:{watson.CRCNS_DOI}; MD5 sums of checksums.md5:")
for n in sorted(sums):
    if n.startswith(("data/", "docs/")):
        print(f"  {sums[n]}  {n}")

KEEP = ("_WSRestrictedIntervals.mat", "_BasicMetaData.mat", "_Motion.mat")


def scan(name):
    """Stream one session tar from start to end; keep the member list and three small files."""
    t0 = time.time()
    rdr = watson.PrefetchReader(watson.CRCNS_BASE + f"data/{name}.tar.gz")
    size = rdr.size
    tf = tarfile.open(fileobj=io.BufferedReader(rdr, buffer_size=2**22), mode="r|gz")
    members, files = [], {}
    for m in tf:
        if not m.isfile():
            continue
        base = m.name.split("/")[-1]
        members.append((base, m.size))
        for k in KEEP:
            if base.endswith(k):
                files[k] = tf.extractfile(m).read()
    rdr.close()
    return dict(name=name, gz_bytes=size, members=members, files=files, seconds=time.time() - t0)


t_all = time.time()
with ThreadPoolExecutor(4) as ex:
    S = list(ex.map(scan, watson.CRCNS_SESSIONS))
t_all = time.time() - t_all
CRCNS:fcx-1 (unversioned), doi:10.6080/K02N506Q; MD5 sums of checksums.md5:
  3455b9f2b5bb8d49716df2da0710971a  data/0_data_file_list.txt
  76a3a51748d22a4b8f822b59c5367c62  data/20140526_277um.tar.gz
  c9ad3be105258bc5e70b34d50c7964cd  data/20140527_421um.tar.gz
  0342fc85311c394b52a8d29a1290a39f  data/20140528_565um.tar.gz
  5bae671bcfd9f76524b08b9dcbcf3d0e  data/BWRat17_121712.tar.gz
  c744f4a16327b474563f0f615b05e343  data/BWRat17_121912.tar.gz
  f2c6a9a725eb929f1482c48ca0f816ab  data/BWRat18_020513.tar.gz
  908398356c84000b7dce814c3c408dd2  data/BWRat19_032413.tar.gz
  4169ce26875aaaec4ef42c3ab8de402c  data/BWRat19_032513.tar.gz
  65e3bc3f961c6a9b3725e96a2682ed1d  data/BWRat20_101013.tar.gz
  5f1dcb5cc0d2972b6bff9b020a4f26aa  data/BWRat20_101513.tar.gz
  0fc5726ba2ce996996c085f37b02597e  data/BWRat21_121113.tar.gz
  8e2c5d14ee822aaf876cff3b8dff5510  data/BWRat21_121613.tar.gz
  021b1a96327fcc82c8b81d31cd086873  data/BWRat21_121813.tar.gz
  9a65bdc269ec5df500236b4e4b3e79d4  data/Bogey_012615.tar.gz
  4ac889b2421e4c32ccd80c67d96df793  data/Dino_061814_mPFC.tar.gz
  b916aef6b88f570cf91533e4d70c29ed  data/Dino_061914_ACC.tar.gz
  098ce2e0340ef414fad7d56a75fbc946  data/Dino_061914_mPFC.tar.gz
  9225d5b807be4c2b7a0634dab53cc64f  data/Dino_062014_ACC.tar.gz
  3f6d06564687a5be5f53be4f8ec8dbff  data/Dino_062014_mPFC.tar.gz
  9d1bf8b88852e2e7f1e8ea749d2b9199  data/Dino_072114_mPFC.tar.gz
  3bccdfe803cd415593ce8519b6e000dd  data/Dino_072314_mPFC.tar.gz
  d0b8faaa90589c10bebe47492b66b676  data/Dino_072414_mPFC.tar.gz
  4deca5619586d6f7b21110005894e125  data/Rizzo_022615.tar.gz
  acc3d4a3bc2f40172d11aa0f4c344df7  data/Rizzo_022715.tar.gz
  b6b5c4629f528edd74f14af178b32ca8  data/Splinter_020515.tar.gz
  e62faa965caadabedebd6af8beda6b0e  data/Splinter_020915.tar.gz
  9c1e4255a4437a9fe68c3b9e44b221a8  data/Templeton_032415.tar.gz
  52f501affe137a3f55ef1ab95dfe85c2  docs/WatsonSleepHomestasis2016Table.xlsx
  17bff1e71f5628f481b67fb29fc06f5a  docs/crcns_fcx-1_data_description.docx
  625a756190e29553cf5d678914e52b04  docs/crcns_fcx-1_data_description.pdf
In [2]:
# What was loaded.
print(f"{len(S)} sessions streamed, {sum(s['gz_bytes'] for s in S) / 1e9:.1f} GB compressed, in {t_all:.0f} s with four at a time")
for s in S:
    print(f"  {s['name']}: {s['gz_bytes'] / 1e9:.2f} GB, {len(s['members'])} files, kept {sorted(s['files'])}, {s['seconds']:.0f} s")
assert all(len(s["files"]) == 3 for s in S)
27 sessions streamed, 88.9 GB compressed, in 620 s with four at a time
  20140526_277um: 2.86 GB, 19 files, kept ['_BasicMetaData.mat', '_Motion.mat', '_WSRestrictedIntervals.mat'], 79 s
  20140527_421um: 3.58 GB, 20 files, kept ['_BasicMetaData.mat', '_Motion.mat', '_WSRestrictedIntervals.mat'], 99 s
  20140528_565um: 2.57 GB, 20 files, kept ['_BasicMetaData.mat', '_Motion.mat', '_WSRestrictedIntervals.mat'], 72 s
  BWRat17_121712: 0.94 GB, 20 files, kept ['_BasicMetaData.mat', '_Motion.mat', '_WSRestrictedIntervals.mat'], 29 s
  BWRat17_121912: 1.02 GB, 20 files, kept ['_BasicMetaData.mat', '_Motion.mat', '_WSRestrictedIntervals.mat'], 28 s
  BWRat18_020513: 2.01 GB, 20 files, kept ['_BasicMetaData.mat', '_Motion.mat', '_WSRestrictedIntervals.mat'], 57 s
  BWRat19_032413: 1.48 GB, 20 files, kept ['_BasicMetaData.mat', '_Motion.mat', '_WSRestrictedIntervals.mat'], 38 s
  BWRat19_032513: 1.17 GB, 20 files, kept ['_BasicMetaData.mat', '_Motion.mat', '_WSRestrictedIntervals.mat'], 30 s
  BWRat20_101013: 1.92 GB, 20 files, kept ['_BasicMetaData.mat', '_Motion.mat', '_WSRestrictedIntervals.mat'], 53 s
  BWRat20_101513: 3.79 GB, 20 files, kept ['_BasicMetaData.mat', '_Motion.mat', '_WSRestrictedIntervals.mat'], 98 s
  BWRat21_121113: 2.75 GB, 20 files, kept ['_BasicMetaData.mat', '_Motion.mat', '_WSRestrictedIntervals.mat'], 78 s
  BWRat21_121613: 2.63 GB, 20 files, kept ['_BasicMetaData.mat', '_Motion.mat', '_WSRestrictedIntervals.mat'], 72 s
  BWRat21_121813: 2.64 GB, 20 files, kept ['_BasicMetaData.mat', '_Motion.mat', '_WSRestrictedIntervals.mat'], 72 s
  Bogey_012615: 4.27 GB, 20 files, kept ['_BasicMetaData.mat', '_Motion.mat', '_WSRestrictedIntervals.mat'], 116 s
  Dino_061814_mPFC: 5.45 GB, 18 files, kept ['_BasicMetaData.mat', '_Motion.mat', '_WSRestrictedIntervals.mat'], 159 s
  Dino_061914_ACC: 4.70 GB, 18 files, kept ['_BasicMetaData.mat', '_Motion.mat', '_WSRestrictedIntervals.mat'], 128 s
  Dino_061914_mPFC: 4.75 GB, 18 files, kept ['_BasicMetaData.mat', '_Motion.mat', '_WSRestrictedIntervals.mat'], 132 s
  Dino_062014_ACC: 6.04 GB, 18 files, kept ['_BasicMetaData.mat', '_Motion.mat', '_WSRestrictedIntervals.mat'], 168 s
  Dino_062014_mPFC: 6.12 GB, 18 files, kept ['_BasicMetaData.mat', '_Motion.mat', '_WSRestrictedIntervals.mat'], 172 s
  Dino_072114_mPFC: 2.16 GB, 18 files, kept ['_BasicMetaData.mat', '_Motion.mat', '_WSRestrictedIntervals.mat'], 61 s
  Dino_072314_mPFC: 2.84 GB, 18 files, kept ['_BasicMetaData.mat', '_Motion.mat', '_WSRestrictedIntervals.mat'], 80 s
  Dino_072414_mPFC: 3.71 GB, 18 files, kept ['_BasicMetaData.mat', '_Motion.mat', '_WSRestrictedIntervals.mat'], 104 s
  Rizzo_022615: 5.94 GB, 20 files, kept ['_BasicMetaData.mat', '_Motion.mat', '_WSRestrictedIntervals.mat'], 156 s
  Rizzo_022715: 3.94 GB, 20 files, kept ['_BasicMetaData.mat', '_Motion.mat', '_WSRestrictedIntervals.mat'], 105 s
  Splinter_020515: 3.20 GB, 20 files, kept ['_BasicMetaData.mat', '_Motion.mat', '_WSRestrictedIntervals.mat'], 86 s
  Splinter_020915: 2.72 GB, 20 files, kept ['_BasicMetaData.mat', '_Motion.mat', '_WSRestrictedIntervals.mat'], 74 s
  Templeton_032415: 3.69 GB, 20 files, kept ['_BasicMetaData.mat', '_Motion.mat', '_WSRestrictedIntervals.mat'], 47 s
In [3]:
def intervals(s):
    w = watson._loadmat(s["files"]["_WSRestrictedIntervals.mat"])
    d = {}
    for k in ["REM", "SWSPacket", "MA", "WakeInterruption", "Wake", "Sleep"]:
        v = watson._tp(w[k + "TimePairFormat"])
        d[k] = np.vstack(v) if isinstance(v, list) else v
    ws = w["WakeSleepTimePairFormat"]
    cyc = [np.asarray(c, float) for c in ws] if (isinstance(ws, np.ndarray) and ws.dtype == object) else [np.asarray(ws, float)]
    d["cycles"] = sorted([(c[0], c[1]) for c in cyc], key=lambda c: c[0][0])  # (WAKE [start, stop], SLEEP [start, stop])
    return d


def within(iv, a, b):
    iv = np.asarray(iv, float).reshape(-1, 2)
    return iv[(iv[:, 0] >= a) & (iv[:, 1] <= b)]


for s in S:
    s["I"] = intervals(s)

Earlier finding 1 (metadata_error)¶

The files hold 51 WAKE-SLEEP cycles (WakeSleepTimePairFormat over the 27 sessions), where the paper reports 54; the Wake and Sleep intervals are the same 51 pairs, with none unpaired. All other counts (995 pE, 126 pI, 27 sessions, 11 rats, 43230 UP and 86839 DOWN states, 5203 spindles) match the paper exactly.

The WakeSleep pairs of each session, and the Wake and Sleep intervals that are not one of them.

In [4]:
tot = dict(cycles=0, Wake=0, Sleep=0, unpaired_Wake=0, unpaired_Sleep=0)
for s in S:
    I = s["I"]
    W = {tuple(c[0]) for c in I["cycles"]}
    Sl = {tuple(c[1]) for c in I["cycles"]}
    tot["cycles"] += len(I["cycles"])
    tot["Wake"] += len(I["Wake"])
    tot["Sleep"] += len(I["Sleep"])
    tot["unpaired_Wake"] += sum(tuple(x) not in W for x in I["Wake"])
    tot["unpaired_Sleep"] += sum(tuple(x) not in Sl for x in I["Sleep"])
print(tot, "; paper 54 WAKE-SLEEP episodes")
print("cycles per session:", {s["name"]: len(s["I"]["cycles"]) for s in S})
{'cycles': 51, 'Wake': 51, 'Sleep': 51, 'unpaired_Wake': 0, 'unpaired_Sleep': 0} ; paper 54 WAKE-SLEEP episodes
cycles per session: {'20140526_277um': 2, '20140527_421um': 1, '20140528_565um': 1, 'BWRat17_121712': 1, 'BWRat17_121912': 1, 'BWRat18_020513': 2, 'BWRat19_032413': 1, 'BWRat19_032513': 1, 'BWRat20_101013': 1, 'BWRat20_101513': 2, 'BWRat21_121113': 2, 'BWRat21_121613': 1, 'BWRat21_121813': 3, 'Bogey_012615': 3, 'Dino_061814_mPFC': 2, 'Dino_061914_ACC': 1, 'Dino_061914_mPFC': 1, 'Dino_062014_ACC': 3, 'Dino_062014_mPFC': 3, 'Dino_072114_mPFC': 1, 'Dino_072314_mPFC': 2, 'Dino_072414_mPFC': 1, 'Rizzo_022615': 5, 'Rizzo_022715': 2, 'Splinter_020515': 3, 'Splinter_020915': 2, 'Templeton_032415': 3}

Earlier finding 2 (metadata_error), the parts watson-2016-03 does not report¶

The paper reports 790 microarousals; 434 MA intervals lie inside SLEEP (2130 MA intervals in the files, most outside SLEEP). 345 WakeInterruption intervals inside SLEEP are shorter than the 40 s minimum the data description gives for them; none lies between two packets (123 between two REM intervals, 80 between REM and a packet), so they are not MAs by the paper's definition either, though counted with the MAs they give 779 events. One nonREM packet (14 s) is shorter than the 20 s minimum of Table S1.

watson-2016-03 reports the MA count (its finding 7). Checked here: the WakeInterruptions shorter than 40 s inside the SLEEP of the cycles, with the states on either side of each (within 2 s, the earlier attempt's rule: P packet, R REM, M MA, W WakeInterruption, - none), the data description's definition of WakeInterruption, and the packets shorter than 20 s.

In [5]:
nb, n_short, n_ma = {}, 0, 0
for s in S:
    I = s["I"]
    for _, sl in I["cycles"]:
        n_ma += len(within(I["MA"], *sl))
        seq = sorted([(k, *x) for key, k in (("SWSPacket", "P"), ("REM", "R"), ("MA", "M"), ("WakeInterruption", "W"))
                      for x in within(I[key], *sl)], key=lambda z: z[1])
        for j, (k, a, b) in enumerate(seq):
            if k == "W" and b - a < 40:
                n_short += 1
                prev = seq[j - 1][0] if j > 0 and a - seq[j - 1][2] <= 2 else "-"
                nxt = seq[j + 1][0] if j + 1 < len(seq) and seq[j + 1][1] - b <= 2 else "-"
                nb[prev + "W" + nxt] = nb.get(prev + "W" + nxt, 0) + 1
print(f"MA intervals in the SLEEP of cycles: {n_ma} of {sum(len(s['I']['MA']) for s in S)}")
print(f"WakeInterruptions shorter than 40 s in SLEEP: {n_short}; by neighbours", dict(sorted(nb.items(), key=lambda x: -x[1])))
print(f"  between two packets: {nb.get('PWP', 0)}; between two REM: {nb.get('RWR', 0)}; REM then packet: {nb.get('RWP', 0)}; packet then REM: {nb.get('PWR', 0)}")
print("  counted with the MAs:", n_ma + n_short)
pk = [(s["name"], float(d)) for s in S for d in np.diff(s["I"]["SWSPacket"], axis=1).ravel() if d < 20]
print("packets shorter than 20 s:", pk)
desc = requests.get(DOCS + "crcns_fcx-1_data_description.docx", timeout=60).content
text = re.sub(r"<[^>]+>", "", re.sub(r"</w:p>", "\n", zipfile.ZipFile(io.BytesIO(desc)).read("word/document.xml").decode()))
print("data description:", " ".join(re.search(r"WakeInterruptionTimePairFormat.{0,200}?sleep\.", text, re.S).group(0).split()))
MA intervals in the SLEEP of cycles: 434 of 2130
WakeInterruptions shorter than 40 s in SLEEP: 345; by neighbours {'RWR': 123, 'RWP': 80, 'RW-': 50, '-WP': 49, 'PWR': 25, 'PW-': 7, '-WR': 6, '-W-': 5}
  between two packets: 0; between two REM: 123; REM then packet: 80; packet then REM: 25
  counted with the MAs: 779
packets shorter than 20 s: [('BWRat17_121912', 14.0)]
data description: WakeInterruptionTimePairFormat, WakeInterruptionIntervalSetFormat – Longer than MAs, 40-120second periods of WAKE-like activity during sleep.

Earlier finding 3 (metadata_error)¶

In Rizzo_022715 and Splinter_020515 a WAKE-SLEEP cycle's WAKE starts before the previous cycle's SLEEP ends (WAKE 9919-14394 s against SLEEP 5655-10010 s; WAKE 5335-7210 s against SLEEP 3543-5455 s), so the cycles overlap.

Consecutive cycles of each session, by WAKE start, where the next WAKE starts before the SLEEP before it ends.

In [6]:
n_ov = 0
for s in S:
    c = s["I"]["cycles"]
    for a, b in zip(c, c[1:]):
        if b[0][0] < a[1][1]:
            n_ov += 1
            print(f"{s['name']}: WAKE {b[0][0]:.0f}-{b[0][1]:.0f} s starts before SLEEP {a[1][0]:.0f}-{a[1][1]:.0f} s ends")
print("overlapping cycle pairs:", n_ov)
Rizzo_022715: WAKE 9919-14394 s starts before SLEEP 5655-10010 s ends
Splinter_020515: WAKE 5335-7210 s starts before SLEEP 3543-5455 s ends
overlapping cycle pairs: 2

Earlier finding 4 (other, data), the part watson-2016-03 does not report¶

Dino_061914 and Dino_062014 each appear as two sessions, ACC and mPFC probes recorded at the same time (the data set's WatsonSleepHomestasis2016Table.xlsx lists the same days), each with its own state files, and the two scorings of Dino_062014 differ (mean SLEEP per cycle 59.5 min in ACC and 27.1 min in mPFC; 41 and 17 packets). State- and LFP-level analyses over the 27 sessions count these days twice.

watson-2016-03 reports the two folders of each day (its finding 6). Checked here: the cycles and packets of the two scorings of each day.

In [7]:
for n in ["Dino_061914_ACC", "Dino_061914_mPFC", "Dino_062014_ACC", "Dino_062014_mPFC"]:
    I = next(s for s in S if s["name"] == n)["I"]
    sl = [c[1] for c in I["cycles"]]
    print(f"{n}: {len(sl)} cycles, SLEEP {[f'{a:.0f}-{b:.0f}' for a, b in sl]} s, mean SLEEP {np.mean([b - a for a, b in sl]) / 60:.1f} min, "
          f"{len(I['SWSPacket'])} packets ({sum(len(within(I['SWSPacket'], *x)) for x in sl)} in SLEEP)")
Dino_061914_ACC: 1 cycles, SLEEP ['10768-13003'] s, mean SLEEP 37.2 min, 11 packets (11 in SLEEP)
Dino_061914_mPFC: 1 cycles, SLEEP ['10767-13002'] s, mean SLEEP 37.2 min, 12 packets (12 in SLEEP)
Dino_062014_ACC: 3 cycles, SLEEP ['4124-6109', '6887-13946', '19969-21628'] s, mean SLEEP 59.5 min, 41 packets (41 in SLEEP)
Dino_062014_mPFC: 3 cycles, SLEEP ['4137-6107', '6888-8140', '19970-21627'] s, mean SLEEP 27.1 min, 17 packets (17 in SLEEP)

Earlier finding 5 (metadata_error)¶

The data description says the motion signal in _Motion.mat is z-scored; it is non-negative in every session, with per-session means from 0.55 to 4076, and BWRat19_032513 holds NaN values.

The motion field of each session's _Motion.mat, and the data description's text for it.

In [8]:
mo = {}
for s in S:
    m = np.atleast_1d(np.asarray(watson._loadmat(s["files"]["_Motion.mat"])["motiondata"].motion, float))
    mo[s["name"]] = m
print("data description:", re.search(r"\.motion[^\n]*", text).group(0))
print("sessions with a negative value:", [k for k, m in mo.items() if np.nanmin(m) < 0], "; smallest value:", min(np.nanmin(m) for m in mo.values()))
nan = {k: f"{int(np.isnan(m).sum())} of {len(m)}" for k, m in mo.items() if np.isnan(m).any()}
print("sessions with NaN:", nan)
means = {k: float(np.mean(m)) for k, m in mo.items() if not np.isnan(m).any()}
print(f"per-session mean, sessions without NaN: {min(means.values()):.3g} to {max(means.values()):.4g}; "
      f"per-session SD: {min(np.nanstd(m) for m in mo.values()):.3g} to {max(np.nanstd(m) for m in mo.values()):.4g}")
print("NaN sessions, mean over the other samples:", {k: round(float(np.nanmean(mo[k])), 3) for k in nan})
data description: .motion – one point per second of original data, zscored motion for that second
sessions with a negative value: [] ; smallest value: 0.0
sessions with NaN: {'BWRat19_032513': '158 of 3928'}
per-session mean, sessions without NaN: 0.553 to 4076; per-session SD: 0.00838 to 4259
NaN sessions, mean over the other samples: {'BWRat19_032513': 0.075}

Earlier finding 6 (metadata_error)¶

RecordingFileIntervals in _BasicMetaData.mat ends at infinity in the three sessions of rat JennBuzsaki22, and the UP/DOWN file is named _UPDOWNINtervals.mat, where the description says _UPDOWNInts.mat and _UPDOWNIntervals.mat.

RecordingFileIntervals of each session, the names of the UP/DOWN files in the tars, and the names the data description gives.

In [9]:
for s in S:
    r = np.atleast_2d(np.asarray(watson._loadmat(s["files"]["_BasicMetaData.mat"])["bmd"].RecordingFileIntervals, float))
    if not np.all(np.isfinite(r)):
        print(f"{s['name']}: RecordingFileIntervals {r.tolist()}")
print("sessions with every bound finite:", sum(np.all(np.isfinite(np.asarray(watson._loadmat(s['files']['_BasicMetaData.mat'])['bmd'].RecordingFileIntervals, float))) for s in S))
names = sorted({m.split(s["name"])[-1] for s in S for m, _ in s["members"] if "updown" in m.lower()})
print("UP/DOWN file names in the tars (after the session name):", names, "; sessions with one:",
      sum(any("updown" in m.lower() for m, _ in s["members"]) for s in S))
print("names in the data description:", sorted(set(re.findall(r"basename(_UPDOWN\w*\.mat)", text))))
20140526_277um: RecordingFileIntervals [[0.0, inf]]
20140527_421um: RecordingFileIntervals [[0.0, inf]]
20140528_565um: RecordingFileIntervals [[0.0, inf]]
sessions with every bound finite: 24
UP/DOWN file names in the tars (after the session name): ['_UPDOWNINtervals.mat'] ; sessions with one: 27
names in the data description: ['_UPDOWNIntervals.mat', '_UPDOWNInts.mat']

Earlier finding 8 (metadata_insufficient)¶

Scored WAKE exists only as the WAKE of a WAKE-SLEEP cycle, so the WAKE that follows a SLEEP is in most cycles absent or hours later (23 of 51 cycles have a later scored WAKE, 6 within 1 s). The 5 min post-sleep WAKE windows of the paper cannot be located for most cycles.

Whether every Wake interval is a cycle's WAKE (finding 1 above), and for each cycle the first scored WAKE of its session that starts at or after the end of its SLEEP (0.5 s slack for whole seconds).

In [10]:
gaps, n_cyc = [], 0
for s in S:
    I = s["I"]
    wakes = np.array([c[0] for c in I["cycles"]])
    for _, sl in I["cycles"]:
        n_cyc += 1
        nxt = wakes[wakes[:, 0] >= sl[1] - 0.5]
        if len(nxt):
            gaps.append(nxt[:, 0].min() - sl[1])
gaps = np.array(gaps)
print(f"cycles with a later scored WAKE: {len(gaps)} of {n_cyc}; within 1 s: {int(np.sum(gaps <= 1))}; "
      f"the others start {gaps[gaps > 1].min():.0f} to {gaps.max():.0f} s after SLEEP ends")
cycles with a later scored WAKE: 23 of 51; within 1 s: 6; the others start 166 to 10344 s after SLEEP ends

Earlier finding 9 (other, data)¶

Each session is one tar.gz of 0.9 to 6 GB, and the order of members differs between files (the LFP .eeg comes before the spike and state files in some), so reading any one small file needs the whole archive streamed. Reading all 27 takes 7 to 9 minutes from the bucket.

The tar sizes, the position of the .eeg among the members, and the time of the read above.

In [11]:
small = ("_WSRestrictedIntervals.mat", "_BasicMetaData.mat", "_SStable.mat", "_CellIDs.mat")
after = []
for s in S:
    order = [m for m, _ in s["members"]]
    e = next(i for i, m in enumerate(order) if m.endswith(".eeg"))
    late = [m.split(s["name"])[-1] for m in order[e + 1:] if m.endswith(small)]
    if late:
        after.append((s["name"], late))
print(f"tar.gz sizes {min(s['gz_bytes'] for s in S) / 1e9:.2f} to {max(s['gz_bytes'] for s in S) / 1e9:.2f} GB, "
      f"{sum(s['gz_bytes'] for s in S) / 1e9:.1f} GB in all; files per tar {min(len(s['members']) for s in S)} to {max(len(s['members']) for s in S)}")
print(f"sessions whose .eeg comes before a spike, cell or state file: {len(after)} of {len(S)}")
for n, late in after:
    print(f"  {n}: after the .eeg {late}")
print(f"sessions with the .eeg last: {sum(s['members'][-1][0].endswith('.eeg') for s in S)}")
print(f"the read above took {t_all:.0f} s ({t_all / 60:.1f} min) with four sessions at a time")
tar.gz sizes 0.94 to 6.12 GB, 88.9 GB in all; files per tar 18 to 20
sessions whose .eeg comes before a spike, cell or state file: 18 of 27
  20140526_277um: after the .eeg ['_BasicMetaData.mat']
  20140527_421um: after the .eeg ['_CellIDs.mat', '_BasicMetaData.mat', '_SStable.mat', '_WSRestrictedIntervals.mat']
  BWRat17_121912: after the .eeg ['_CellIDs.mat', '_BasicMetaData.mat', '_SStable.mat']
  BWRat18_020513: after the .eeg ['_SStable.mat']
  BWRat19_032413: after the .eeg ['_CellIDs.mat', '_WSRestrictedIntervals.mat', '_BasicMetaData.mat']
  BWRat19_032513: after the .eeg ['_CellIDs.mat', '_SStable.mat', '_BasicMetaData.mat']
  BWRat20_101013: after the .eeg ['_WSRestrictedIntervals.mat', '_CellIDs.mat', '_BasicMetaData.mat', '_SStable.mat']
  BWRat20_101513: after the .eeg ['_CellIDs.mat', '_WSRestrictedIntervals.mat', '_BasicMetaData.mat', '_SStable.mat']
  BWRat21_121613: after the .eeg ['_CellIDs.mat']
  BWRat21_121813: after the .eeg ['_SStable.mat', '_CellIDs.mat', '_BasicMetaData.mat', '_WSRestrictedIntervals.mat']
  Dino_061814_mPFC: after the .eeg ['_BasicMetaData.mat', '_WSRestrictedIntervals.mat', '_CellIDs.mat']
  Dino_061914_ACC: after the .eeg ['_WSRestrictedIntervals.mat', '_CellIDs.mat']
  Dino_062014_ACC: after the .eeg ['_SStable.mat', '_BasicMetaData.mat']
  Dino_072114_mPFC: after the .eeg ['_SStable.mat', '_CellIDs.mat', '_WSRestrictedIntervals.mat', '_BasicMetaData.mat']
  Dino_072414_mPFC: after the .eeg ['_BasicMetaData.mat', '_WSRestrictedIntervals.mat', '_CellIDs.mat']
  Rizzo_022615: after the .eeg ['_SStable.mat']
  Splinter_020515: after the .eeg ['_SStable.mat', '_WSRestrictedIntervals.mat', '_BasicMetaData.mat', '_CellIDs.mat']
  Splinter_020915: after the .eeg ['_BasicMetaData.mat', '_WSRestrictedIntervals.mat']
sessions with the .eeg last: 3
the read above took 620 s (10.3 min) with four sessions at a time