-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from switt4/master
Add correctFieldMapCase4 to support pepolar fieldmaps
- Loading branch information
Showing
4 changed files
with
180 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters