Skip to content

antsRegistrationSyNQuick (continuation of #1392 and #2347) #2453

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Feb 23, 2018

Conversation

djarecka
Copy link
Collaborator

Had to close #2347 after miscommunication with github...

@effigies effigies added this to the 1.0.1 milestone Feb 20, 2018
@djarecka
Copy link
Collaborator Author

djarecka commented Feb 20, 2018

@satra, I'm not sure if I used environmental variables as num_threads as you were thinking about. I actually don't understand the way it's done in base.py, since LOCAL_DEFAULT_NUMBER_OF_THREADS is a normal global variable defined here.

I decided to check if a user have LOCAL_DEFAULT_NUMBER_OF_THREADS and set to 1 if I can't find it.

@satra
Copy link
Member

satra commented Feb 20, 2018

@djarecka - that particular interface overwrites the environment variables, so setting them has no effect. you should just keep your implementation as before with creating a new num_threads field in the inputspec, effectively overwriting the base num_threads.

or, more elegantly, you can keep the base num_threads, but override the parse function and the num_threads sync function.

try:
LOCAL_DEFAULT_NUMBER_OF_THREADS = int(os.getenv("LOCAL_DEFAULT_NUMBER_OF_THREADS"))
except TypeError:
LOCAL_DEFAULT_NUMBER_OF_THREADS = 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's just import from .base import LOCAL_DEFAULT_NUMBER_OF_THREADS.

Also, I think in general this variable is kind of pointless, unless somebody's using a fork of nipype where it's defined as something other than 1. This isn't something that needs to be fixed in this PR, but just to flag it for others' attention.

@effigies
Copy link
Member

@satra If you override num_threads (as done here), the Sphinx documentation will include flag: -n %d, which seems more helpful than overriding parsing/syncing functions is elegant.

Copy link
Member

@effigies effigies left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Saw a few things (in addition to earlier comment about importing LOCAL_DEFAULT_NUMBER_OF_THREADS) that could use updating.

@satra Please chime in if I'm making suggestions that are out of line with your thoughts on the interface.

Also, please merge master to fix tests.

>>> reg.inputs.num_threads = 2
>>> reg.cmdline
'antsRegistrationSynQuick.sh -d 3 -f fixed1.nii -m moving1.nii -n 2 -o transform -p d -t s'
>>> reg.run() # doctest: +SKIP
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the help:

     NB:  Multiple image pairs can be specified for registration during the SyN stage.
          Specify additional images using the '-m' and '-f' options.  Note that image
          pair correspondence is given by the order specified on the command line.
          Only the first fixed and moving image pair is used for the linear resgitration
          stages.

We should add a doctest to make sure that if fixed_image and moving_image are lists, that we see -f fixed1.nii -f fixed2.nii -m moving1.nii -m moving2.nii (or similar).

It may be more trouble than it's worth to verify that the lists are of the same length.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it gives -f fixed1.nii fixed2.nii -m moving1.nii moving2.nii, but i haven't checked if it is properly propagated to the main Registration (couldn't find also examples that confirms that this is a proper command)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, then I think we want to change the argstrs for fixed_image and moving_image to -f %s... and -m %s..., respectively. (The ... will change -f A B to -f A -f B.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pushed before reading this comment.

But do you know this is correct syntax of command line? If yes, I can change it, but just wasn't sure what is the correct syntax

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. -f A B will fail, while -f A -f B will succeed.

self.inputs.output_prefix + 'InverseWarped.nii.gz')
outputs['out_matrix'] = os.path.abspath(self.inputs.output_prefix + '0GenericAffine.mat')

# todo in the case of linear transformation-only there won't be fields. is there a more elegant way to specify that?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What you have seems like a reasonable approach to me.

outputs = self.output_spec().get()
outputs['warped_image'] = os.path.abspath(self.inputs.output_prefix + 'Warped.nii.gz')
outputs['inverse_warped_image'] = os.path.abspath(
self.inputs.output_prefix + 'InverseWarped.nii.gz')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to be a little more concise, maybe we can do the following:

out_base = os.path.abspath(self.inputs.output_prefix)
outputs['warped_image'] = out_base + 'Warped.nii.gz'
outputs['inverse_warped_image'] = out_base + 'InverseWarped.nii.gz'

and so on...

Examples
--------

>>> import copy, pprint
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're not using these imports

--------

>>> import copy, pprint
>>> from nipype.interfaces.ants import Registration
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RegistrationSynQuick

_cmd = 'antsRegistrationSynQuick.sh'
input_spec = RegistrationSynQuickInputSpec
output_spec = RegistrationSynQuickOutputSpec

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to avoid being affected by upstream changes, we should override _num_threads_update() to do nothing.

def _num_threads_update(self):
    """antsRegistrationSynQuick.sh ignores environment variables, so override environment update"""


class RegistrationSynQuick(ANTSCommand):
"""
Reistration using a symmetric image normalization method (SyN).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Registration" (you're missing a "g").

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks :)

@effigies
Copy link
Member

@djarecka Can you "Rerun failed jobs" (in the "Rerun" drop down)? https://circleci.com/workflow-run/6fb99ca4-98b4-4585-92f2-03db3046b4ae

@effigies
Copy link
Member

Need to make specs.

@djarecka
Copy link
Collaborator Author

sorry, forgot to update. should be better now

@effigies effigies merged commit 0c6d3f8 into nipy:master Feb 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants