I often make use of the inline processing function feature available for nipype workflows:
testsave.connect(bet2, ('mask_file', func), maths, "in_file2")
as - for instance - exemplified here: https://nipype.readthedocs.io/en/latest/users/saving_workflows.html
It would be even more convenient, if I could perform simple operator processig inline, e.g. instead of
def divideby_10(a):
return a/10.
testsave.connect(somenode, ('out_number', divideby_10), someothernode, "in_number")
doing:
testsave.connect(somenode, ('out_number', /10.), someothernode, "in_number")
Currently this fails with SyntaxError: invalid syntax
and
testsave.connect(somenode, ('out_number', +10.), someothernode, "in_number")
fails with TypeError: 10.0 is not a module, class, method, function, traceback, frame, or code object
.
The obvious solution at this point, a lambda function:
testsave.connect(somenode, ('out_number', lambda x: x/10.), someothernode, "in_number")
fails at runtime with:
RuntimeError:
Error executing function:
(f_percentile, f_threshold, [(('out_stat', lambda x: x/10.), 'thresh')]),
Functions in connection strings have to be standalone.
They cannot be declared either interactively or inside
another function or inline in the connect string. Any
imports should be done inside the function
Is there any way I can perform division inline with the connection specification, or do I have to wrap the operation in a defined function?