Skip to content

[FIX] Mrtrix3 usedefault issue #3004

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

Closed

Conversation

matteomancini
Copy link
Contributor

Summary

Fixes #2822 .

List of changes proposed in this PR (pull-request)

  • Set useDefault=False for gm_odf and csf_odf in order to avoid issues with the csd algorithm;
  • Removed useDefault=True for the -lmax argument in order to avoid issues in case of multi-shell data.

Acknowledgment

I acknowledge that this contribution will be available under the Apache 2 license.

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.

This seems like it's going to break for any user that has been getting gm/csf_odf files for free up to now. Unless it's the case that this has been unusable up to now. so we won't be breaking things for anybody. I haven't used MRTrix, so I can't really tell.

Does it make sense to split the CSD algorithm into its own interface? Or perhaps we can figure out the cases under which csf_odf and gm_odf inputs should be ignored, and disable them.

@lucindasisk Would you care to look at this and give your thoughts? I assume you've been using this, given your recent edit.

And @oesteban, it looks like you added this interface in the first place. Your thoughts would be appreciated.

Suggested a couple cleanups related to default values.

@matteomancini
Copy link
Contributor Author

@effigies thank you for the suggestions, I will implement them later today. The issue is that in the current form the interface is broken for anyone who tries to use the csd algorithm. If the fix I proposed it is accepted, anyone who was using the msmt_csd algorithm and was not explicitly defining gm_odf and csd_odf will need to do so. The difference is that in the latter case it easy for an user to make things work again, while in the former and current scenario the only ways to fix things are either to set csf_odf and gm_odf to Undefined or to actually change the interface in Nipype (or not use it at all).

If you look at the step before the FOD computation, the response estimation, is implemented in ResponseSD in a similar manner to the proposed change: if you are using the msmt_5tt algorithm, you need to specify the gm_file and the csf_file.

Since it is just a matter of defining additional output names for one of the two algorithms, I think that two different interfaces are quite redundant and the result would be even more disruptive than the change here proposed. If you have any idea on how to automatically set gm_odf and csf_odf in case the algorithm is msmt_csd that would be great, and should be probably implemented also in ResponseSD.

@effigies effigies added this to the 1.2.2 milestone Aug 30, 2019
@effigies
Copy link
Member

If the fix I proposed it is accepted, anyone who was using the msmt_csd algorithm and was not explicitly defining gm_odf and csd_odf will need to do so.

Right. This is the problem. I agree that it's not a heavy fix for an actively maintained workflow, but the concern is for workflows that are not actively maintained and don't depend on a specific version of nipype. On the whole, we try not to break backwards compatibility under the current setup, unless it's clear that the feature never worked for anybody. Here it's apparently worked for people using msmt_csd. (In the future of nipype, interfaces will themselves be versioned, and design decisions can be made with at least a bit less regard for workflows in the wild.)

My suggestion for an alternative interface could be done with very little code:

class EstimateCSDInputSpec(EstimateFODInputSpec):
    algorithm = traits.Enum('csd', ...)
    gm_odf = Undefined
    csf_odf = Undefined

class EstimateCSD(EstimateFOD):
    input_spec = EstimateCSDInputSpec

I haven't tested this, in particular whether you can get away with the Undefined trick, but the idea is to leave the current interface as is, for people who use msmt_csd, and just override the bits that need overriding. (If Undefined doesn't work, you can just use File(desc='DO NOT SET') or something.

To redirect CSD users to this interface, I'd update the documentation of the original to indicate that algorithm='csd' doesn't work, and this alternative should be used. I would then switch the default algorithm to 'msmt_csd', since apparently everybody's been running that, and raise an error pointing users to the new interface if they want to try to use csd.

There's actually another alternative, which is that you can add an EstimateFOD._format_arg to disable these for csd:

def _format_arg(self, name, trait_spec, value):
    if name in ("gm_odf", "csf_odf") and self.inputs.algorithm == "csd":
        return None
    super(EstimateFOD, self)._format_arg(name, trait_spec, value)

And you'd also need to update _list_outputs:

 def _list_outputs(self):
         outputs = self.output_spec().get()
         outputs['wm_odf'] = op.abspath(self.inputs.wm_odf)
-        if self.inputs.gm_odf != Undefined:
+        if self.inputs.gm_odf != Undefined and self.inputs.algorithm != 'csd':
             outputs['gm_odf'] = op.abspath(self.inputs.gm_odf)
-        if self.inputs.csf_odf != Undefined:
+        if self.inputs.csf_odf != Undefined and self.inputs.algorithm != 'csd':
             outputs['csf_odf'] = op.abspath(self.inputs.csf_odf)
         return outputs

I don't know which is more appealing to you, but either would be fine with me. I think the former is a bit more explicit, but the latter would probably be less work.

In either case, it would be good to update the doctests to show the command lines produced for both algorithms.

@codecov
Copy link

codecov bot commented Sep 3, 2019

Codecov Report

Merging #3004 into master will decrease coverage by 0.53%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3004      +/-   ##
==========================================
- Coverage   67.49%   66.96%   -0.54%     
==========================================
  Files         344      343       -1     
  Lines       44038    44020      -18     
  Branches     5554     5551       -3     
==========================================
- Hits        29723    29477     -246     
- Misses      13571    13788     +217     
- Partials      744      755      +11
Flag Coverage Δ
#smoketests 50.36% <ø> (ø) ⬆️
#unittests 64.15% <100%> (-0.79%) ⬇️
Impacted Files Coverage Δ
nipype/interfaces/mrtrix3/reconst.py 79.59% <100%> (ø) ⬆️
nipype/interfaces/nilearn.py 40% <0%> (-56.67%) ⬇️
nipype/testing/fixtures.py 77.33% <0%> (-21.34%) ⬇️
nipype/interfaces/freesurfer/base.py 61.01% <0%> (-19.5%) ⬇️
nipype/workflows/smri/freesurfer/autorecon2.py 65.9% <0%> (-9.2%) ⬇️
nipype/workflows/smri/freesurfer/ba_maps.py 91.66% <0%> (-8.34%) ⬇️
nipype/workflows/smri/freesurfer/recon.py 66.66% <0%> (-7.81%) ⬇️
nipype/workflows/smri/freesurfer/autorecon3.py 68.4% <0%> (-6.95%) ⬇️
nipype/workflows/smri/freesurfer/autorecon1.py 41.66% <0%> (-5.1%) ⬇️
nipype/info.py 87.14% <0%> (-2.86%) ⬇️
... and 9 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3e794d4...ba66142. Read the comment docs.

1 similar comment
@codecov
Copy link

codecov bot commented Sep 3, 2019

Codecov Report

Merging #3004 into master will decrease coverage by 0.53%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3004      +/-   ##
==========================================
- Coverage   67.49%   66.96%   -0.54%     
==========================================
  Files         344      343       -1     
  Lines       44038    44020      -18     
  Branches     5554     5551       -3     
==========================================
- Hits        29723    29477     -246     
- Misses      13571    13788     +217     
- Partials      744      755      +11
Flag Coverage Δ
#smoketests 50.36% <ø> (ø) ⬆️
#unittests 64.15% <100%> (-0.79%) ⬇️
Impacted Files Coverage Δ
nipype/interfaces/mrtrix3/reconst.py 79.59% <100%> (ø) ⬆️
nipype/interfaces/nilearn.py 40% <0%> (-56.67%) ⬇️
nipype/testing/fixtures.py 77.33% <0%> (-21.34%) ⬇️
nipype/interfaces/freesurfer/base.py 61.01% <0%> (-19.5%) ⬇️
nipype/workflows/smri/freesurfer/autorecon2.py 65.9% <0%> (-9.2%) ⬇️
nipype/workflows/smri/freesurfer/ba_maps.py 91.66% <0%> (-8.34%) ⬇️
nipype/workflows/smri/freesurfer/recon.py 66.66% <0%> (-7.81%) ⬇️
nipype/workflows/smri/freesurfer/autorecon3.py 68.4% <0%> (-6.95%) ⬇️
nipype/workflows/smri/freesurfer/autorecon1.py 41.66% <0%> (-5.1%) ⬇️
nipype/info.py 87.14% <0%> (-2.86%) ⬇️
... and 9 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3e794d4...ba66142. Read the comment docs.

@codecov
Copy link

codecov bot commented Sep 3, 2019

Codecov Report

Merging #3004 into master will decrease coverage by 0.53%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3004      +/-   ##
==========================================
- Coverage   67.49%   66.96%   -0.54%     
==========================================
  Files         344      343       -1     
  Lines       44038    44020      -18     
  Branches     5554     5551       -3     
==========================================
- Hits        29723    29477     -246     
- Misses      13571    13788     +217     
- Partials      744      755      +11
Flag Coverage Δ
#smoketests 50.36% <ø> (ø) ⬆️
#unittests 64.15% <100%> (-0.79%) ⬇️
Impacted Files Coverage Δ
nipype/interfaces/mrtrix3/reconst.py 79.59% <100%> (ø) ⬆️
nipype/interfaces/nilearn.py 40% <0%> (-56.67%) ⬇️
nipype/testing/fixtures.py 77.33% <0%> (-21.34%) ⬇️
nipype/interfaces/freesurfer/base.py 61.01% <0%> (-19.5%) ⬇️
nipype/workflows/smri/freesurfer/autorecon2.py 65.9% <0%> (-9.2%) ⬇️
nipype/workflows/smri/freesurfer/ba_maps.py 91.66% <0%> (-8.34%) ⬇️
nipype/workflows/smri/freesurfer/recon.py 66.66% <0%> (-7.81%) ⬇️
nipype/workflows/smri/freesurfer/autorecon3.py 68.4% <0%> (-6.95%) ⬇️
nipype/workflows/smri/freesurfer/autorecon1.py 41.66% <0%> (-5.1%) ⬇️
nipype/info.py 87.14% <0%> (-2.86%) ⬇️
... and 9 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3e794d4...be919a5. Read the comment docs.

1 similar comment
@codecov
Copy link

codecov bot commented Sep 3, 2019

Codecov Report

Merging #3004 into master will decrease coverage by 0.53%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3004      +/-   ##
==========================================
- Coverage   67.49%   66.96%   -0.54%     
==========================================
  Files         344      343       -1     
  Lines       44038    44020      -18     
  Branches     5554     5551       -3     
==========================================
- Hits        29723    29477     -246     
- Misses      13571    13788     +217     
- Partials      744      755      +11
Flag Coverage Δ
#smoketests 50.36% <ø> (ø) ⬆️
#unittests 64.15% <100%> (-0.79%) ⬇️
Impacted Files Coverage Δ
nipype/interfaces/mrtrix3/reconst.py 79.59% <100%> (ø) ⬆️
nipype/interfaces/nilearn.py 40% <0%> (-56.67%) ⬇️
nipype/testing/fixtures.py 77.33% <0%> (-21.34%) ⬇️
nipype/interfaces/freesurfer/base.py 61.01% <0%> (-19.5%) ⬇️
nipype/workflows/smri/freesurfer/autorecon2.py 65.9% <0%> (-9.2%) ⬇️
nipype/workflows/smri/freesurfer/ba_maps.py 91.66% <0%> (-8.34%) ⬇️
nipype/workflows/smri/freesurfer/recon.py 66.66% <0%> (-7.81%) ⬇️
nipype/workflows/smri/freesurfer/autorecon3.py 68.4% <0%> (-6.95%) ⬇️
nipype/workflows/smri/freesurfer/autorecon1.py 41.66% <0%> (-5.1%) ⬇️
nipype/info.py 87.14% <0%> (-2.86%) ⬇️
... and 9 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3e794d4...be919a5. Read the comment docs.

@codecov
Copy link

codecov bot commented Sep 3, 2019

Codecov Report

Merging #3004 into master will decrease coverage by 0.53%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3004      +/-   ##
==========================================
- Coverage   67.49%   66.96%   -0.54%     
==========================================
  Files         344      343       -1     
  Lines       44038    44020      -18     
  Branches     5554     5551       -3     
==========================================
- Hits        29723    29477     -246     
- Misses      13571    13788     +217     
- Partials      744      755      +11
Flag Coverage Δ
#smoketests 50.36% <ø> (ø) ⬆️
#unittests 64.15% <100%> (-0.79%) ⬇️
Impacted Files Coverage Δ
nipype/interfaces/mrtrix3/reconst.py 79.59% <100%> (ø) ⬆️
nipype/interfaces/nilearn.py 40% <0%> (-56.67%) ⬇️
nipype/testing/fixtures.py 77.33% <0%> (-21.34%) ⬇️
nipype/interfaces/freesurfer/base.py 61.01% <0%> (-19.5%) ⬇️
nipype/workflows/smri/freesurfer/autorecon2.py 65.9% <0%> (-9.2%) ⬇️
nipype/workflows/smri/freesurfer/ba_maps.py 91.66% <0%> (-8.34%) ⬇️
nipype/workflows/smri/freesurfer/recon.py 66.66% <0%> (-7.81%) ⬇️
nipype/workflows/smri/freesurfer/autorecon3.py 68.4% <0%> (-6.95%) ⬇️
nipype/workflows/smri/freesurfer/autorecon1.py 41.66% <0%> (-5.1%) ⬇️
nipype/info.py 87.14% <0%> (-2.86%) ⬇️
... and 9 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3e794d4...ef40504. Read the comment docs.

@codecov
Copy link

codecov bot commented Sep 3, 2019

Codecov Report

Merging #3004 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #3004   +/-   ##
=======================================
  Coverage   67.22%   67.22%           
=======================================
  Files         343      343           
  Lines       44823    44823           
  Branches     5609     5609           
=======================================
  Hits        30131    30131           
  Misses      13936    13936           
  Partials      756      756
Flag Coverage Δ
#smoketests 50.36% <0%> (ø) ⬆️
#unittests 64.3% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update be919a5...2c46d9b. Read the comment docs.

@matteomancini
Copy link
Contributor Author

On the whole, we try not to break backwards compatibility under the current setup, unless it's clear that the feature never worked for anybody.

I can see your point here, but the issue is that at the moment for keeping backwards compatibility the interface to the csd algorithm is broken. I don't know if there are actual numbers on which of the algorithms is more used, but if people agree to separate the two algorithms (and if it doesn't break pipelines based on the csd algorithm), I'm happy to implement that. Undefined actually does the trick, I already tried it. I would be probably happier with the _format_arg solution (which I didn't know about), but I would like to have feedback from people who actually use this interface.

@effigies
Copy link
Member

effigies commented Sep 5, 2019

Right, I'm not saying we should preserve backwards compatibility for the broken part, just for the parts that are already working. If _format_arg appeals to you, let's go in that direction. It will allow those two options to be ignored for csd and not break them for msmt_csd.

@oesteban oesteban modified the milestones: 1.2.2, 1.3.0, 1.2.3 Sep 5, 2019
@effigies
Copy link
Member

Hi @matteomancini, we're going to be aiming for a release in about a week. Please let me know if I can be any help.

@effigies effigies modified the milestones: 1.2.3, future, 1.3.0 Sep 18, 2019
@matteomancini
Copy link
Contributor Author

Hi @effigies,
I have been travelling in the last two weeks so I missed the deadline for the release, but next week I'll be able to work on It.

@effigies effigies modified the milestones: 1.3.0, 1.4.0 Nov 11, 2019
@effigies
Copy link
Member

Hi @matteomancini, sorry to do this to you, but we just merged some pretty huge changes. Could you re-apply these changes on the latest master? You'll want to re-run make specs entirely, and we're now using the Black formatter. You can run it manually, or use pre-commit to have it automatically run every time you commit.

Please let me know if you need any help or clarifications.

@matteomancini
Copy link
Contributor Author

Hi @effigies thank you for the message. I have been swamped in the last days, but this is still on my to-do list. So should I pull the latest changes, then run make specs and push to the branch on my repo clone?

@effigies
Copy link
Member

Hi @matteomancini. Looks like your response got drowned in a flood of notifications...

Anyway, I would do the following:

git fetch upstream
# Merge, but pause for fixes
git merge upstream/master --no-commit
# Get this branch's version of the changed file
git checkout be919a5 nipype/interfaces/mrtrix3/reconst.py
black nipype/interfaces/mrtrix3/reconst.py
git add nipype/interfaces/mrtrix3/reconst.py
# Inspect the differences to make sure nothing else was reverted.
git diff --cached upstream/master
# Assuming everything's good
git commit
git push

If there are other issues, you can use git checkout -p upstream/master nipype/interfaces/mrtrix3/reconst.py to select specific chunks to revert.

If you need to install black, you can use pip install black.

@effigies effigies modified the milestones: 1.4.0, 1.4.1 Dec 18, 2019
@effigies effigies modified the milestones: 1.4.1, 1.5.0 Jan 26, 2020
@effigies effigies mentioned this pull request Feb 23, 2020
17 tasks
@effigies
Copy link
Member

@matteomancini I added a ConstrainedSphericalDeconvolution interface with your fixes. If you have further issues, let's fix those in that interface, and leave EstimateFOD.

@effigies effigies removed this from the 1.5.0 milestone May 27, 2020
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.

MRtrix 3.0 dwi2fod single output error
3 participants