1717"""Tests for bids_utils."""
1818
1919from importlib import resources
20+ from itertools import permutations
2021import os
22+ from pathlib import Path
2123from 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
2429import pytest
2530import 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 )
0 commit comments