Skip to content

Commit

Permalink
Finalized code :)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcohenadad committed Dec 21, 2023
1 parent 1e46f3d commit b27fcad
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions bids_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@
# Create dictionary for shim type output
shimtype_dict = {'noRFshim': 'CP',
'Noshim': 'CP',
'CVred': 'CVred'}
'CVred': 'CVred',
'PatSpec': 'patient',
'PhaseOnly': 'phase',
'SAReff': 'SAReff',
'Target': 'target',
'VolSpec': 'volume'}

# Get subject name from path_out
subject = os.path.basename(path_out)
Expand All @@ -25,11 +30,18 @@
shutil.copy2(file, os.path.join(path_out, f'anat/sub-{subject}_acq-{shimtype_dict[shimtype]}_T1w.{ext}'))

# Convert files in GRE_B1 subfolder
# Get the absolute file name of the NIfTI and JSON files under each subfolder of the GRE_B1 subfolder that has the string corresponding to the name of the subfolder in it, and that has the string "gre2d" in it. Select the first pair in the list.
for shimtype in ['CVred', 'Noshim']:
# Get the absolute file name of the NIfTI and JSON files under each subfolder of the GRE_B1 subfolder that has the string corresponding to the name of the subfolder in it.
for shimtype in ['CVred', 'Noshim', 'PatSpec', 'PhaseOnly', 'SAReff', 'Target', 'VolSpec']:
for ext in ['nii.gz', 'json']:
# Convert GRE data
# Select the files with the string "gre2d" in it. Select the first pair in the list, which are not corrected for gradient distortion.
file = [os.path.join(path_in, 'GRE_B1', shimtype, f) for f in os.listdir(os.path.join(path_in, 'GRE_B1', shimtype)) if 'gre2d' in f and f.endswith(ext)][0]
shutil.copy2(file, os.path.join(path_out, f'anat/sub-{subject}_acq-{shimtype_dict[shimtype]}_T2starw.{ext}'))
# Convert RF map data
# Select the files with the string "tfl_b1map" in it. Select the first pair in the list, which is not corrected for gradient distortion, and which corresponds to the magnitude image. Select also the 3rd pair, which corresponds to the RF map.
file = [os.path.join(path_in, 'GRE_B1', shimtype, f) for f in os.listdir(os.path.join(path_in, 'GRE_B1', shimtype)) if 'tfl_b1map' in f and f.endswith(ext)][0]
shutil.copy2(file, os.path.join(path_out, f'fmap/sub-{subject}_acq-{shimtype_dict[shimtype]}_part-magnitude_TB1map.{ext}'))
file = [os.path.join(path_in, 'GRE_B1', shimtype, f) for f in os.listdir(os.path.join(path_in, 'GRE_B1', shimtype)) if 'tfl_b1map' in f and f.endswith(ext)][2]
shutil.copy2(file, os.path.join(path_out, f'fmap/sub-{subject}_acq-{shimtype_dict[shimtype]}_TB1map.{ext}'))


0 comments on commit b27fcad

Please sign in to comment.