/ concept-collection / benchcompress
Sign in
concept-collection / benchcompress
add fmri
Jeremy Magland <jmagland@flatironinstitute.org> committed commit 22203e11b439 parent ddd6829 Browse files
4 changed files+92−1
benchcompress/pyproject.tomlmodified+2−1View file
@@ -24,7 +24,8 @@ dependencies = [
2424 "pybind11>=2.11.1",
2525 "segyio",
2626 "lz4",
27- "pyedflib"
27+ "pyedflib",
28+ "nibabel"
2829 ]
2930
3031 [tool.scikit-build]
benchcompress/src/benchcompress/datasets/__init__.pymodified+2−0View file
@@ -3,6 +3,7 @@ from .gaussian import datasets as gaussian_datasets
33 from .ecephys import datasets as ecephys_datasets
44 from .seismic import datasets as seismic_datasets
55 from .ieeg import datasets as ieeg_datasets
6+from .fmri import datasets as fmri_datasets
67
78 datasets_list = [
89 bernoulli_datasets,
@@ -10,6 +11,7 @@ datasets_list = [
1011 ecephys_datasets,
1112 seismic_datasets,
1213 ieeg_datasets,
14+ fmri_datasets,
1315 ]
1416
1517 datasets = []
benchcompress/src/benchcompress/datasets/fmri/__init__.pyadded+71−0View file
@@ -0,0 +1,71 @@
1+import numpy as np
2+import os
3+import nibabel as nib
4+from typing import cast, Optional, List
5+
6+SOURCE_FILE = "fmri/__init__.py"
7+
8+
9+def _load_long_description():
10+ current_dir = os.path.dirname(os.path.abspath(__file__))
11+ md_path = os.path.join(current_dir, "fmri.md")
12+ with open(md_path, "r", encoding="utf-8") as f:
13+ return f.read()
14+
15+
16+LONG_DESCRIPTION = _load_long_description()
17+
18+tags = ["real", "fmri", "timeseries", "1d", "integer", "bold", "continuous"]
19+
20+
21+def _load_bold_data(*, slice_indices: Optional[List[int]] = None) -> np.ndarray:
22+ """Load BOLD fMRI data from OpenNeuro dataset ds005880.
23+
24+ Args:
25+ slice_indices: Optional list of slice indices to load. If None, loads full volume.
26+ Use range(15, 30) for middle 15 slices.
27+
28+ Returns:
29+ Array of shape (X, Y, Z, T) where X,Y,Z are spatial dimensions and T is time points.
30+ Z dimension will be length 1 if a single slice index is provided.
31+ """
32+ url = "https://s3.amazonaws.com/openneuro.org/ds005880/sub-01/func/sub-01_task-rest_run-01_bold.nii.gz?versionId=0z5_YvqoLC4pXDVUVDt9Y1nrJBRxMqXb"
33+ # Download and load the data
34+ import requests
35+ from pathlib import Path
36+
37+ cache_dir = Path(os.path.expanduser("~/.cache/benchcompress/fmri"))
38+ cache_dir.mkdir(parents=True, exist_ok=True)
39+ local_file = cache_dir / "sub-01_task-rest_run-01_bold.nii.gz"
40+
41+ if not local_file.exists():
42+ response = requests.get(url)
43+ response.raise_for_status()
44+ local_file.write_bytes(response.content)
45+
46+ img = nib.load(str(local_file)) # type: ignore
47+ data = img.get_fdata() # type: ignore
48+
49+ # Convert to int16
50+ data = data.astype(np.int16)
51+
52+ if slice_indices is not None:
53+ data = data[:, :, :, slice_indices]
54+
55+ # Now we are going to convert to 1d array, and we make sure that the time dimension varies the fastest
56+ data = data.ravel()
57+
58+ return data
59+
60+
61+datasets = [
62+ {
63+ "name": "fmri-ds005880",
64+ "version": "1",
65+ "description": "Middle 15 slices from BOLD fMRI recording from ds005880 OpenNeuro dataset.",
66+ "create": lambda: _load_bold_data(slice_indices=list(range(15, 30))),
67+ "tags": tags,
68+ "source_file": SOURCE_FILE,
69+ "long_description": LONG_DESCRIPTION,
70+ }
71+]
benchcompress/src/benchcompress/datasets/fmri/fmri.mdadded+17−0View file
@@ -0,0 +1,17 @@
1+# Functional MRI Dataset
2+
3+This dataset contains functional MRI (fMRI) data from a study investigating neural activity elicited by the diminished seventh chord in listeners with refined music listening skills.
4+
5+## Data Source
6+
7+The data comes from OpenNeuro dataset [ds005880](https://openneuro.org/datasets/ds005880/versions/1.0.1) titled "BIDS Dataset for the Diminished Seventh Chord". The specific data used is a single functional run from subject 01.
8+
9+Data were acquired at Imaging Center for Integrated Body, Mind, and Culture Research at National Taiwan University using a 3T MR system (MAGNETOM Prisma, Siemens, Erlangen, Germany).
10+
11+## Dataset Details
12+
13+- Type: BOLD fMRI timeseries
14+- Format: 4D NIfTI file (3D volumes over time)
15+- Data type: 16-bit integers
16+- Content: Represents changes in blood oxygenation level dependent (BOLD) signal over time
17+- Structure: Each timepoint is a 3D brain volume showing neural activity patterns
moveopenescclose