sbollmann commited on
Commit
ffa0486
·
verified ·
1 Parent(s): 0d94f86

samsrf: X001 left-hemisphere example (OSF h92mr, CC BY 4.0)

Browse files
.gitattributes CHANGED
@@ -361,3 +361,8 @@ examples/reproin/xa60/8_func-bold_task-rest_acq-dualecho_run-1/8117_1.3.12.2.110
361
  examples/reproin/xa60/9_fmap-epi_dir-AP_run-1/0058_1.3.12.2.1107.5.2.50.177514.2026050812133198736025429.dcm filter=lfs diff=lfs merge=lfs -text
362
  examples/reproin/xa60/9_fmap-epi_dir-AP_run-1/0116_1.3.12.2.1107.5.2.50.177514.2026050812133950309025545.dcm filter=lfs diff=lfs merge=lfs -text
363
  examples/reproin/xa60/9_fmap-epi_dir-AP_run-1/0174_1.3.12.2.1107.5.2.50.177514.2026050812134720248325662.dcm filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
361
  examples/reproin/xa60/9_fmap-epi_dir-AP_run-1/0058_1.3.12.2.1107.5.2.50.177514.2026050812133198736025429.dcm filter=lfs diff=lfs merge=lfs -text
362
  examples/reproin/xa60/9_fmap-epi_dir-AP_run-1/0116_1.3.12.2.1107.5.2.50.177514.2026050812133950309025545.dcm filter=lfs diff=lfs merge=lfs -text
363
  examples/reproin/xa60/9_fmap-epi_dir-AP_run-1/0174_1.3.12.2.1107.5.2.50.177514.2026050812134720248325662.dcm filter=lfs diff=lfs merge=lfs -text
364
+ samsrf/example/aps_Bars.mat filter=lfs diff=lfs merge=lfs -text
365
+ samsrf/example/lh.area filter=lfs diff=lfs merge=lfs -text
366
+ samsrf/example/lh.curv filter=lfs diff=lfs merge=lfs -text
367
+ samsrf/example/lh.inflated filter=lfs diff=lfs merge=lfs -text
368
+ samsrf/example/lh.white filter=lfs diff=lfs merge=lfs -text
samsrf/example/README.md ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # SamSrf example (X001, left hemisphere)
2
+
3
+ Source: SamSrf X example data set, OSF project h92mr (https://osf.io/h92mr/),
4
+ Schwarzkopf lab, licensed CC BY 4.0. Six runs of sweeping-bar pRF mapping, Siemens
5
+ 3T Skyra, multiband TR 1 s, 2.3 mm voxels, projected to the FreeSurfer surface with
6
+ mri_vol2surf.
7
+
8
+ Changes: `make_example.py` zeroes every left-hemisphere vertex outside the author's
9
+ V1-V3 ROI (`prf/V123.label`, left-hemisphere rows) and recompresses each run, and writes
10
+ `lh.V123.label` and `lh.V1_seed.label` (Benson atlas V1 within that ROI). The
11
+ apertures (`aps_Bars.mat`), the Benson template (`lh_benson.gii`) and the FreeSurfer
12
+ files (`lh.inflated`, `lh.white`, `lh.area`, `lh.curv`) are copied unchanged.
samsrf/example/aps_Bars.mat ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:901749ddd3643c60a02ed620ecb8237955af94a54c86679d425f5a8d3ea2d638
3
+ size 1091391
samsrf/example/lh.V123.label ADDED
The diff for this file is too large to render. See raw diff
 
samsrf/example/lh.V1_seed.label ADDED
The diff for this file is too large to render. See raw diff
 
samsrf/example/lh.area ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d00d0bbb96d03e7b6e0811c9ae7f9c828cef9cb4ecc95171ef91a4b4e572b2cf
3
+ size 537055
samsrf/example/lh.curv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:48e8392d5de3a0c61e0b88dde6d4480b9c1608bc1a70be10090cc7a410e22b1e
3
+ size 537055
samsrf/example/lh.inflated ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b32b70c4274429e0e99f7b9a1452d758464df5e51015728e0e8c145ec32bcedb
3
+ size 4835530
samsrf/example/lh.white ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:366658ba58865c930f0f8d856cb81bbdff0081aaff008831d96a2fd7fd0dfb7d
3
+ size 4834713
samsrf/example/lh_benson.gii ADDED
The diff for this file is too large to render. See raw diff
 
samsrf/example/lh_uBars1.gii ADDED
The diff for this file is too large to render. See raw diff
 
samsrf/example/lh_uBars2.gii ADDED
The diff for this file is too large to render. See raw diff
 
samsrf/example/lh_uBars3.gii ADDED
The diff for this file is too large to render. See raw diff
 
samsrf/example/lh_uBars4.gii ADDED
The diff for this file is too large to render. See raw diff
 
samsrf/example/lh_uBars5.gii ADDED
The diff for this file is too large to render. See raw diff
 
samsrf/example/lh_uBars6.gii ADDED
The diff for this file is too large to render. See raw diff
 
samsrf/example/make_example.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Build the SamSrf webapp example from the X001 dataset (OSF h92mr, CC-BY 4.0).
2
+
3
+ Keeps the left-hemisphere vertices of the V1-V3 ROI and zeroes the rest, so the six
4
+ run GIFTIs compress to a size a browser can fetch. Writes the ROI and a connective
5
+ field seed (Benson's V1 within the ROI) as FreeSurfer labels.
6
+ """
7
+ import base64
8
+ import re
9
+ import sys
10
+ import zlib
11
+ from pathlib import Path
12
+
13
+ import numpy as np
14
+
15
+ LH_VERTICES = 134260
16
+ DATA = re.compile(rb"<Data>(.*?)</Data>", re.S)
17
+
18
+
19
+ def arrays(text):
20
+ return [np.frombuffer(zlib.decompress(base64.b64decode(m.group(1))), "<f4") for m in DATA.finditer(text)]
21
+
22
+
23
+ def write_label(path, source, rows):
24
+ with open(path, "w") as f:
25
+ f.write(f"#!ascii label from SamSrf X001 {source}\n")
26
+ f.write(f"{len(rows)}\n")
27
+ for row in rows:
28
+ f.write(f"{int(row[0])} {row[1]:.3f} {row[2]:.3f} {row[3]:.3f} {row[4]:.6f}\n")
29
+
30
+
31
+ def main(x001, out):
32
+ x001 = Path(x001)
33
+ out = Path(out)
34
+ out.mkdir(parents=True, exist_ok=True)
35
+ label = np.loadtxt(x001 / "prf/V123.label", skiprows=2)
36
+ lh_rows = label[label[:, 0] < LH_VERTICES]
37
+ benson = arrays((x001 / "benson/lh_benson.gii").read_bytes())
38
+ keep = np.zeros(LH_VERTICES, bool)
39
+ keep[lh_rows[:, 0].astype(int)] = True
40
+ seed = keep & (np.abs(benson[2]) == 1)
41
+ print(f"ROI vertices {keep.sum()}, V1 seed vertices {seed.sum()}")
42
+ write_label(out / "lh.V123.label", "V123.label, left hemisphere rows", lh_rows)
43
+ write_label(out / "lh.V1_seed.label", "Benson V1 within V123", lh_rows[seed[lh_rows[:, 0].astype(int)]])
44
+ for run in range(1, 7):
45
+ text = (x001 / f"func/lh_uBars{run}.gii").read_bytes()
46
+
47
+ def mask(m):
48
+ values = np.frombuffer(zlib.decompress(base64.b64decode(m.group(1))), "<f4").copy()
49
+ values[~keep] = 0
50
+ return b"<Data>" + base64.b64encode(zlib.compress(values.tobytes(), 9)) + b"</Data>"
51
+
52
+ masked = DATA.sub(mask, text)
53
+ (out / f"lh_uBars{run}.gii").write_bytes(masked)
54
+ print(f"run {run}: {len(text)} -> {len(masked)} bytes")
55
+
56
+
57
+ if __name__ == "__main__":
58
+ main(sys.argv[1], sys.argv[2])