Skip to content

Commit c30589c

Browse files
🎨 DRY: raise scope of repeated inner function convert_pedir
Ref 80e9d98, c786486 Co-authored-by: Amy Gutierrez <[email protected]>
1 parent 3cf49bf commit c30589c

File tree

1 file changed

+19
-36
lines changed

1 file changed

+19
-36
lines changed

CPAC/registration/registration.py

Lines changed: 19 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,25 @@ def transform_derivative(wf_name, label, reg_tool, num_cpus, num_ants_cores,
278278
return wf
279279

280280

281+
def convert_pedir(pedir):
282+
'''FSL Flirt requires pedir input encoded as an int'''
283+
conv_dct = {'x': 1, 'y': 2, 'z': 3, 'x-': -1, 'y-': -2, 'z-': -3,
284+
'i': 1, 'j': 2, 'k': 3, 'i-': -1, 'j-': -2, 'k-': -3,
285+
'-x': -1, '-i': -1, '-y': -2,
286+
'-j': -2, '-z': -3, '-k': -3}
287+
288+
if isinstance(pedir, bytes):
289+
pedir = pedir.decode()
290+
if not isinstance(pedir, str):
291+
raise Exception("\n\nPhase-encoding direction must be a "
292+
"string value.\n\nValue: {0}"
293+
"\n\n".format(pedir))
294+
if pedir not in conv_dct.keys():
295+
raise Exception("\n\nInvalid phase-encoding direction "
296+
"entered: {0}\n\n".format(pedir))
297+
return conv_dct[pedir]
298+
299+
281300
def create_fsl_flirt_linear_reg(name='fsl_flirt_linear_reg'):
282301

283302
linear_register = pe.Workflow(name=name)
@@ -685,24 +704,6 @@ def create_register_func_to_anat(config, phase_diff_distcor=False,
685704

686705
# if fieldmap_distortion:
687706

688-
def convert_pedir(pedir):
689-
# FSL Flirt requires pedir input encoded as an int
690-
conv_dct = {'x': 1, 'y': 2, 'z': 3, 'x-': -1, 'y-': -2, 'z-': -3,
691-
'i': 1, 'j': 2, 'k': 3, 'i-': -1, 'j-': -2, 'k-': -3,
692-
'-x': -1, '-i': -1, '-y': -2,
693-
'-j': -2, '-z': -3, '-k': -3}
694-
695-
if isinstance(pedir, bytes):
696-
pedir = pedir.decode()
697-
if not isinstance(pedir, str):
698-
raise Exception("\n\nPhase-encoding direction must be a "
699-
"string value.\n\nValue: {0}"
700-
"\n\n".format(pedir))
701-
if pedir not in conv_dct.keys():
702-
raise Exception("\n\nInvalid phase-encoding direction "
703-
"entered: {0}\n\n".format(pedir))
704-
return conv_dct[pedir]
705-
706707
if phase_diff_distcor:
707708
register_func_to_anat.connect(
708709
inputNode_pedir, ('pedir', convert_pedir),
@@ -973,24 +974,6 @@ def bbreg_args(bbreg_target):
973974
inputspec, 'linear_reg_matrix',
974975
bbreg_func_to_anat, 'in_matrix_file')
975976

976-
def convert_pedir(pedir):
977-
# FSL Flirt requires pedir input encoded as an int
978-
conv_dct = {'x': 1, 'y': 2, 'z': 3, 'x-': -1, 'y-': -2, 'z-': -3,
979-
'i': 1, 'j': 2, 'k': 3, 'i-': -1, 'j-': -2, 'k-': -3,
980-
'-x': -1, '-i': -1, '-y': -2,
981-
'-j': -2, '-z': -3, '-k': -3}
982-
983-
if isinstance(pedir, bytes):
984-
pedir = pedir.decode()
985-
if not isinstance(pedir, str):
986-
raise Exception("\n\nPhase-encoding direction must be a "
987-
"string value.\n\nValue: {0}"
988-
"\n\n".format(pedir))
989-
if pedir not in conv_dct.keys():
990-
raise Exception("\n\nInvalid phase-encoding direction "
991-
"entered: {0}\n\n".format(pedir))
992-
return conv_dct[pedir]
993-
994977
if phase_diff_distcor:
995978
register_bbregister_func_to_anat.connect(
996979
inputNode_pedir, ('pedir', convert_pedir),

0 commit comments

Comments
 (0)