-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add correctFieldMapCase4 to support pepolar fieldmaps #39
Changes from 18 commits
40b76fb
2c2cee5
4f114c4
6ce5f1d
d22dbbd
c5500dc
759d7d3
ff2e513
c485792
612d4a6
bf16c72
78cb19f
512bbe4
55d03e4
69b7eda
aa1c596
03e59b1
daf3e3a
e7594b9
7b77c89
eefd5d0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/bin/bash | ||
|
||
if [ "$#" -lt 1 ] | ||
then | ||
echo "Usage: $0 <in_bids> <subj ID> <session id (optional)>" | ||
exit 1 | ||
fi | ||
in_bids=$1 | ||
|
||
exec_path=`dirname $0` | ||
|
||
|
||
subj=$2 | ||
subj=${subj##sub-} #strip off sub- if it exists, to make consistent | ||
if [ "$#" -gt 2 ] | ||
then | ||
ses=$3 | ||
ses=${ses##ses-} #strip off sub- if it exists, to make consistent | ||
fi | ||
|
||
#correct field map json files | ||
|
||
if [ -n "$ses" ] | ||
then | ||
$exec_path/correctFieldMapJsonCase4.py $in_bids sub-$subj ses-$ses | ||
else | ||
$exec_path/correctFieldMapJsonCase4.py $in_bids sub-$subj | ||
fi | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#! /usr/bin/env python3 | ||
''' | ||
correct field map json | ||
''' | ||
|
||
import os | ||
import sys | ||
import json | ||
import glob | ||
import collections | ||
|
||
def correctFieldMapJson(bids_dir,sub,ses=None): | ||
|
||
if ses: #ses not None | ||
sub_prefix = '{}_{}'.format(sub,ses) | ||
sub_path_prefix=os.path.join(sub,ses) | ||
sub_root = '{}'.format(sub) | ||
else: | ||
sub_prefix = '{}'.format(sub) | ||
sub_path_prefix = sub_prefix | ||
sub_root = '{}'.format(sub) | ||
|
||
sub_dir=os.path.join(bids_dir,sub_path_prefix) | ||
sub_root_dir=os.path.join(bids_dir,sub_root) #without session | ||
|
||
for fmri_json_file in glob.glob(os.path.join(sub_dir,'fmap','{}_acq-EPI_dir-*_epi.json'.format(sub_prefix))): | ||
|
||
#debug | ||
print(fmri_json_file) | ||
|
||
#load json files | ||
with open(fmri_json_file, 'r') as f: | ||
fmri_json = json.load(f,object_pairs_hook=collections.OrderedDict) | ||
|
||
# apply to all bold images | ||
cwd=os.getcwd() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess we're changing the working directory to get the paths relative to the participant directory? I try to avoid changing directories if possible (can cause problems e.g. if the script fails or is cancelled part way through) but if this is the easiest way to do it, that's fine. |
||
os.chdir(sub_root_dir) | ||
if ses: | ||
all_bold = glob.glob(os.path.join('{}'.format(ses),'func','{}_*_bold.nii.gz'.format(sub_prefix))) | ||
else: | ||
all_bold = glob.glob(os.path.join('func','{}_*_bold.nii.gz'.format(sub_prefix))) | ||
|
||
os.chdir(cwd) | ||
|
||
fmri_json["IntendedFor"]=all_bold | ||
|
||
#update json file | ||
os.system("chmod a+w {}".format(fmri_json_file)) | ||
with open(fmri_json_file, 'w') as f: | ||
json.dump(fmri_json, f, indent=4, separators=(',', ': ')) | ||
os.system("chmod a-w {}".format(fmri_json_file)) | ||
|
||
|
||
if __name__=="__main__": | ||
if len(sys.argv)-1 < 2: | ||
print ("Usage: python " + os.path.basename(__file__)+ " 'bids_dir' 'sub' 'ses (optional)'") | ||
sys.exit() | ||
else: | ||
bids_dir = sys.argv[1] | ||
sub = sys.argv[2] | ||
if len(sys.argv)-1 > 2: | ||
ses=sys.argv[3] | ||
correctFieldMapJson(bids_dir,sub,ses) | ||
else: | ||
correctFieldMapJson(bids_dir,sub) | ||
|
||
#test | ||
#Usage: python correctFieldMapJson.py 'bids_dir' 'sub' | ||
#python correctFieldMapJson.py '/mnt/hgfs/test/correct_fieldmap_json/topsy_7T' 'sub-005' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this can just be
sub_root = sub
(or maybesub_root = str(sub)
ifsub
might not already be a string).Actually, you may just want to get rid of this variable entirely because it seems to be the same as
sub
in all cases.