Skip to content

Commit 3308d29

Browse files
authored
🎨 DRY: raise scope of repeated inner function convert_pedir (#1648)
2 parents ffac4a0 + 2e7f8b9 commit 3308d29

File tree

3 files changed

+19
-40
lines changed

3 files changed

+19
-40
lines changed

CPAC/info.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,5 @@ def get_cpac_gitversion():
161161
"simplejson==3.15.0",
162162
"traits==4.6.0",
163163
"PyBASC==0.4.5",
164-
"pathlib==1.0.1",
165164
"voluptuous>=0.12.0",
166165
]

CPAC/registration/registration.py

Lines changed: 19 additions & 38 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)
@@ -683,26 +702,6 @@ def create_register_func_to_anat(config, phase_diff_distcor=False,
683702
if config.registration_workflows['functional_registration']['coregistration']['arguments'] is not None:
684703
linear_reg.inputs.args = config.registration_workflows['functional_registration']['coregistration']['arguments']
685704

686-
# if fieldmap_distortion:
687-
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-
706705
if phase_diff_distcor:
707706
register_func_to_anat.connect(
708707
inputNode_pedir, ('pedir', convert_pedir),
@@ -973,24 +972,6 @@ def bbreg_args(bbreg_target):
973972
inputspec, 'linear_reg_matrix',
974973
bbreg_func_to_anat, 'in_matrix_file')
975974

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-
994975
if phase_diff_distcor:
995976
register_bbregister_func_to_anat.connect(
996977
inputNode_pedir, ('pedir', convert_pedir),

cpac_install.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ pip_packages=(
108108
"simplejson==3.15.0"
109109
"python-dateutil==2.7.3"
110110
"PyBASC==0.4.5"
111-
"pathlib==1.0.1"
112111
)
113112

114113
##### Helper functions for installing system dependencies.

0 commit comments

Comments
 (0)