-
Notifications
You must be signed in to change notification settings - Fork 35
/
test_fixmeta.py
31 lines (25 loc) · 1.34 KB
/
test_fixmeta.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import json
import shutil
from pathlib import Path
from bidscoin import bcoin
from bidscoin.bidsapps.fixmeta import fixmeta
bcoin.setup_logging()
def test_fixmeta(tmp_path):
# Get the data
bidsdir = shutil.copytree(Path(__file__).parent/'test_data'/'7t_trt', tmp_path/'7t_trt')
jsonfile = Path(bidsdir)/'sub-01'/'ses-1'/'fmap'/'sub-01_ses-1_run-1_phasediff.json'
jsondata = {'EchoTime1': 0.006,
'EchoTime2': 0.00702,
'IntendedFor': 'bids::sub-01/ses-1/func/sub-01_ses-1_task-rest_acq-fullbrain_run-1_bold.nii.gz'}
# Test full replacement and partial substitution
fixmeta(bidsdir, '*run-1_phasediff*', {'IntendedFor': ['run-1','run-3', 'full','empty'], 'EchoTime2': 999}, [])
with jsonfile.open('r') as json_fid:
jsonfixed = json.load(json_fid)
assert jsonfixed['IntendedFor'] == 'bids::sub-01/ses-1/func/sub-01_ses-1_task-rest_acq-emptybrain_run-3_bold.nii.gz'
assert jsonfixed['EchoTime1'] == jsondata['EchoTime1']
assert jsonfixed['EchoTime2'] == 999
# Test IntendedFor dynamic value
fixmeta(bidsdir, '*run-1_phasediff*', {'IntendedFor': '<<func/*_run-2_bold>>'}, ['01'])
with jsonfile.open('r') as json_fid:
jsonfixed = json.load(json_fid)
assert jsonfixed['IntendedFor'] == ['bids::sub-01/ses-1/func/sub-01_ses-1_task-rest_acq-fullbrain_run-2_bold.nii.gz']