Aceticia commited on
Commit
1e27cc0
·
verified ·
1 Parent(s): 45c03ef

Card: stream T1 and BOLD samples from a shard

Browse files
Files changed (1) hide show
  1. README.md +38 -0
README.md CHANGED
@@ -58,6 +58,44 @@ root = snapshot_download("medarc/ReadyNeuro", repo_type="dataset")
58
 
59
  To train with the [model code](https://github.com/SophontAI/CortexMAE-ReadyNeuro), set the data config's `urls` to `<root>/shards`.
60
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
  ## Full corpus
62
 
63
  The full corpus is on Cloudflare R2 at `s3://openneuro/v1/`, readable with a public read-only key
 
58
 
59
  To train with the [model code](https://github.com/SophontAI/CortexMAE-ReadyNeuro), set the data config's `urls` to `<root>/shards`.
60
 
61
+ ## Stream samples
62
+
63
+ Each shard is one subject. Its first sample holds the T1, the tissue masks and the grid
64
+ geometry. Every later sample is one BOLD run. Voxels are stored packed: `*_idx.npy` holds flat
65
+ C-order indices of the in-brain voxels, and `*_values.npy` holds one row per index. BOLD is
66
+ z-scored per voxel within the run, stored as int8 at one frame per second. This reads T1 and BOLD
67
+ with `pip install webdataset numpy`:
68
+
69
+ ```python
70
+ import io, json
71
+ import numpy as np
72
+ import webdataset as wds
73
+
74
+ def dense(idx, values, shape):
75
+ """Scatter packed in-brain rows back onto the grid."""
76
+ out = np.zeros((np.prod(shape), *values.shape[1:]), np.float32)
77
+ out[idx] = values
78
+ return out.reshape(*shape, *values.shape[1:])
79
+
80
+ url = "https://huggingface.co/datasets/medarc/ReadyNeuro/resolve/main/shards/ds003777__02.tar"
81
+ # Full corpus: "pipe:aws --profile openneuro-public s3 cp s3://openneuro/v1/<prefix>/train/native/<shard>.tar -"
82
+ for sample in wds.WebDataset(url, shardshuffle=False):
83
+ meta = json.loads(sample["json"])
84
+ arr = lambda name: np.load(io.BytesIO(sample[name]))
85
+ if meta["kind"] == "bundle": # first sample of each shard: T1, masks, geometry
86
+ bold_idx, bold_shape = arr("bold_idx.npy"), meta["bold_shape"]
87
+ bold_affine = arr("bold_affine.npy") # voxel -> world mm
88
+ cortex = dense(bold_idx, arr("bold_cortical_gm.npy"), bold_shape) # (97, 115, 97)
89
+ t1 = dense(arr("t1_idx.npy"), arr("t1_values.npy") * meta["T1_scale"], meta["T1_shape"])
90
+ else: # one sample per run: z-scored BOLD
91
+ z = arr("values.npy") * np.float32(meta["scale"]) # (in-brain voxels, frames)
92
+ clip = dense(bold_idx, z[:, :16], bold_shape) # first 16 s as (97, 115, 97, 16)
93
+ ```
94
+
95
+ The bundle also has `bold_gm`, `bold_seg` (SynthSeg labels) and their `t1_*` counterparts. Each
96
+ run has `mean.npy` and `std.npy` (multiply by `mean_scale`/`std_scale`), which undo the z-score.
97
+ The full format is in [`tools/codec.py`](https://github.com/SophontAI/ReadyNeuro/blob/main/src/readyneuro/tools/codec.py).
98
+
99
  ## Full corpus
100
 
101
  The full corpus is on Cloudflare R2 at `s3://openneuro/v1/`, readable with a public read-only key