Skip to content

Commit 6412805

Browse files
committed
🚚 Get test data from S3 instead of keeping in repo
1 parent 0686a8c commit 6412805

File tree

40 files changed

+61
-1760
lines changed

40 files changed

+61
-1760
lines changed

CPAC/utils/interfaces/datasink.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
# Prior to release 0.12, Nipype was licensed under a BSD license.
3232

33-
# Modifications Copyright (C) 2019-2024 C-PAC Developers
33+
# Modifications Copyright (C) 2019-2025 C-PAC Developers
3434

3535
# This file is part of C-PAC.
3636
"""Interface that allow interaction with data.
@@ -139,6 +139,7 @@ def _fetch_bucket(self, bucket_name):
139139
# Import packages
140140
try:
141141
import boto3
142+
import boto3.session
142143
import botocore
143144
except ImportError:
144145
err_msg = "Boto3 package is not installed - install boto3 and try again."

CPAC/utils/tests/test_bids_utils.py

Lines changed: 59 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,15 @@
1717
"""Tests for bids_utils."""
1818

1919
from importlib import resources
20+
from itertools import permutations
2021
import os
22+
from pathlib import Path
2123
from subprocess import run
22-
from typing import Optional
24+
from warnings import warn
2325

26+
import boto3
27+
from botocore import UNSIGNED
28+
from botocore.client import Config
2429
import pytest
2530
import yaml
2631

@@ -198,13 +203,10 @@ def test_sub_list_filter_by_labels(t1w_label, bold_label, participant_label):
198203
assert all(len(sub.get("func")) in [0, 5] for sub in sub_list)
199204

200205

201-
@pytest.mark.parametrize(
202-
"bids_dir,participant_labels", [("dev/circleci_data/test_data", ["NDARAB348EWR"])]
203-
)
204-
def test_scan_parameter_type(
205-
bids_dir: str, participant_labels: Optional[list[str]]
206-
) -> None:
206+
@pytest.mark.parametrize("participant_labels", [["NDARAB348EWR"]])
207+
def test_scan_parameter_type(tmp_path: Path, participant_labels: list[str]) -> None:
207208
"""Test that scan parameter types are correctly interpreted."""
209+
bids_dir = _gather_scan_parameter_test_data(tmp_path, participant_labels)
208210
data_config = create_cpac_data_config(bids_dir, participant_labels)
209211
assert len(data_config) == 1
210212
if "fmap" in data_config[0]:
@@ -214,3 +216,53 @@ def test_scan_parameter_type(
214216
]
215217
in PHASE_ENCODING_DIRECTIONS
216218
)
219+
220+
221+
def _gather_scan_parameter_test_data(
222+
root_dir: Path, participant_labels: list[str]
223+
) -> str:
224+
"""Create a test BIDS dataset with structure for the given subject.
225+
226+
Downloads JSON files from S3 and creates empty placeholder files for imaging data.
227+
"""
228+
s3_bucket = "fcp-indi"
229+
bids_dir = root_dir / "data"
230+
for _participant in participant_labels:
231+
participant = (
232+
f"sub-{_participant}"
233+
if not _participant.startswith("sub-")
234+
else _participant
235+
)
236+
s3_prefix = f"data/Projects/HBN/MRI/Site-CBIC/{participant}"
237+
s3_client = boto3.client("s3", config=Config(signature_version=UNSIGNED))
238+
files = {
239+
"anat": [
240+
f"{participant}_acq-HCP_run-01_T1w",
241+
],
242+
"fmap": [
243+
f"{participant}_dir-{direction}_acq-{acq}_epi"
244+
for direction in [
245+
"".join(direction) for direction in permutations(["A", "P"], 2)
246+
]
247+
for acq in ["dwi", "fMRI"]
248+
],
249+
"func": [
250+
f"{participant}_task-movieDM_bold",
251+
],
252+
}
253+
for modality, file_list in files.items():
254+
modality_dir = bids_dir / participant / modality
255+
modality_dir.mkdir(parents=True, exist_ok=True)
256+
for file_base in file_list:
257+
# Download JSON files from S3
258+
json_file = modality_dir / f"{file_base}.json"
259+
s3_key = f"{s3_prefix}/{modality}/{file_base}.json"
260+
try:
261+
s3_client.download_file(s3_bucket, s3_key, str(json_file))
262+
except Exception as e:
263+
# If download fails, create empty JSON
264+
warn("Failed to download %s: %s" % (s3_key, e))
265+
json_file.write_text("{}")
266+
nii_file = modality_dir / f"{file_base}.nii.gz"
267+
nii_file.touch()
268+
return str(bids_dir)

dev/circleci_data/test_data/sub-NDARAB348EWR/anat/sub-NDARAB348EWR_acq-HCP_run-01_T1w.json

Lines changed: 0 additions & 68 deletions
This file was deleted.

dev/circleci_data/test_data/sub-NDARAB348EWR/anat/sub-NDARAB348EWR_acq-HCP_run-01_T1w.nii.gz

Whitespace-only changes.

dev/circleci_data/test_data/sub-NDARAB348EWR/anat/sub-NDARAB348EWR_acq-HCP_run-02_T1w.json

Lines changed: 0 additions & 68 deletions
This file was deleted.

dev/circleci_data/test_data/sub-NDARAB348EWR/anat/sub-NDARAB348EWR_acq-HCP_run-02_T1w.nii.gz

Whitespace-only changes.

dev/circleci_data/test_data/sub-NDARAB348EWR/anat/sub-NDARAB348EWR_acq-VNavNorm_T2w.json

Lines changed: 0 additions & 68 deletions
This file was deleted.

dev/circleci_data/test_data/sub-NDARAB348EWR/anat/sub-NDARAB348EWR_acq-VNavNorm_T2w.nii.gz

Whitespace-only changes.

dev/circleci_data/test_data/sub-NDARAB348EWR/anat/sub-NDARAB348EWR_acq-VNavNorm_run-01_T1w.json

Lines changed: 0 additions & 68 deletions
This file was deleted.

dev/circleci_data/test_data/sub-NDARAB348EWR/anat/sub-NDARAB348EWR_acq-VNavNorm_run-01_T1w.nii.gz

Whitespace-only changes.

0 commit comments

Comments
 (0)