-
Notifications
You must be signed in to change notification settings - Fork 532
changing arguments names to default values for traits (closes #2532) #2533
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
Conversation
nipype/interfaces/afni/utils.py
Outdated
@@ -1696,13 +1697,14 @@ class NwarpCatInputSpec(AFNICommandInputSpec): | |||
inv_warp = traits.Bool( | |||
desc='invert the final warp before output', argstr='-iwarp') | |||
interp = traits.Enum( | |||
'wsinc5', | |||
'linear', | |||
'quintic', | |||
'wsinc5', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this needs to be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what do you mean? this element needs to be removed (so "linear" will be default) or usedefault=True
should be removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have two more traits as this one as interp
or ainterp
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'wsinc5'
is listed twice - only once is necessary - for enum's the first element automatically becomes default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, you are right, I forgot to remove the second one here. I've changed the order because Enum
takes the first element as a default, and in the previous version it was default='wsinc5'
.
Since the previous way of setting default was not working doctests were ignoring these elements, so I'd have to change a few doctests, unless you believe that these traits shouldn't have default
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can create a list of all doctests I'd have to change to pass now the tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sounds good - just don't do make specs
yet. that should happen after everything has been reviewed.
also |
@satra - what do you mean that |
@djarecka - just like |
@satra - ok, so you mean warnings. Indeed |
Ok, so in the last commit I changes tests in order to pass them, so would ask for extra checking:
Check quickly doctest of other interfaces that I changed and it seems that they either don't change |
As I mentioned at the beginning there are traits that have specified default values and do not have |
@djarecka - are you going to add warning for |
other than that this looks good. |
@satra - oh, yes, I can add warning. I thought that I can just remove them too. I was thinking whether to search other traits that don't have |
you can add some checks in |
@satra - If I add more warnings now, I will just increase the list that no one reads anymore... Should I just remove all |
@djarecka - we do remove them whenever we ask people to run |
we have many warnings for |
this is being cleaned up in #2514 |
@satra - so you don't want me to clean Also, I'm still not sure when |
@djarecka - don't clean dtitk. |
ok, reverted my changes to dtitk I added a simple check for default values, but it's not perfect. I wasn't sure what is a good way to check if an author of an interface defines any default, so I'm checking Because the way how traits treats default for various trait types, I also had to make several exceptions:
@satra you can check the list of warnings, if my rules and the list make sense, I can correct the interfaces |
ok, I merged and updated the code to remove most warnings. We had many places without I also exclude traits that have One trait that is still in warnings that I wasn't sure about is this output name: https://github.com/nipy/nipype/blob/master/nipype/interfaces/ants/segmentation.py#L1263 |
so unfortunately I have to again change some tests, I changed hash in one of them, but I'm not sure what to do with:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! A few comments, but overall it looks good. I would just make sure that things that are now being set as usedefault
actually have correct default values, with respect to the commands. I caught a couple that looked funny to me on first glance, but did not attempt a systematic check.
nipype/algorithms/confounds.py
Outdated
@@ -391,12 +391,13 @@ class CompCorInputSpec(BaseInterfaceInputSpec): | |||
'extraction') | |||
use_regress_poly = traits.Bool( | |||
True, | |||
usedefault=True, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is deprecated, it would probably be better to remove the default than to turn it on by default. (I think the main effect of adding usedefault=True
will be to cause a DeprecationWarning
to display, but I'm not sure of this.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, will remove it. Actually DeprecationWarning
is not displayed after my changes, only when you're changing later, so it's better to remove the default
nipype/interfaces/afni/utils.py
Outdated
desc='specify a different interpolation method than might ' | ||
'be used for the warp', | ||
argstr='-ainterp %s', | ||
default='wsinc5') | ||
usedefault=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like a change in semantics. From the docs:
-interp iii = 'iii' is the interpolation mode
++ Default interpolation mode is 'wsinc5' (slowest, bestest)
++ Available modes are the same as in 3dAllineate:
NN linear cubic quintic wsinc5
++ The same interpolation mode is used for the warp
itself (if needed) and then for the data being warped.
++ The warp will be interpolated if the output dataset is
not on the same 3D grid as the warp itself, or if a warp
expression is used in the '-nwarp' option. Otherwise,
it won't need to be interpolated.
-ainterp jjj = This option lets you specify a different interpolation mode
for the data than might be used for the warp. In particular,
'-ainterp NN' would be most logical for atlas datasets, where
the data values being mapped are labels
If I set -interp NN
, then -ainterp
would implicitly become NN
, but we're setting it to wsinc5
by default.
I think it makes sense to remove the default form -ainterp
entirely.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, will remove
nipype/interfaces/afni/utils.py
Outdated
@@ -1841,7 +1842,6 @@ class OneDToolPyInputSpec(AFNIPythonCommandInputSpec): | |||
show_cormat_warnings = traits.File( | |||
desc='Write cormat warnings to a file', | |||
argstr="-show_cormat_warnings |& tee %s", | |||
default="out.cormat_warn.txt", | |||
usedefault=False, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should probably remove usedefault=False
, too, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, should add warnings
nipype/interfaces/fsl/aroma.py
Outdated
@@ -28,7 +28,8 @@ class ICA_AROMAInputSpec(CommandLineInputSpec): | |||
xor=['feat_dir'], | |||
desc='volume to be denoised') | |||
out_dir = Directory( | |||
'out', genfile=True, argstr='-o %s', desc='output directory') | |||
'out', usedefault=True, genfile=True, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Judging by _gen_filename
, this wasn't intended to be a default value. @jdkent can you clarify your intent here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bump @jdkent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
haha, my intent when I made this was to get it to work, I kluged the out_dir definition from melodic and your comment from when I first tried making the wrapper. what a blast from the past!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so should out_dir
have a default value? or should i remove 'out', usedefault=True,
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, so in practice, it's been setting out_dir=os.getcwd()
, as opposed to 'out'
. Which is the preferable default?
out_dir = Directory('out', usedefault=True, mandatory=True, argstr='-o %s', desc='output directory')
out_dir = Directory(genfile=True, argstr='-o %s', desc='output directory')
I have a slight preference to the former, just to avoid cluttering the local directory (though maybe 'aroma_output' would be a better default). In which case we should also drop _gen_filename()
method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, sounds good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@effigies - just an extra question, do we use mandatory=True
if we already have a default value and usedefault=True
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's a good idea. The reason I suggest it is because somebody could set it as Undefined
manually or (god knows why) pipe in a value that fails to be defined from a previous node.
In [1]: from nipype.interfaces.base import *
In [2]: class A(BaseInterface):
...: class input_spec(TraitedSpec):
...: a = traits.Str('test', usedefault=True)
...: def _run_interface(self, runtime):
...: print(self.inputs.a)
...: return runtime
...:
In [3]: a = A()
In [4]: a.inputs
Out[4]:
a = test
In [5]: a.inputs.a = Undefined
In [6]: _ = a.run()
<undefined>
So unless it really is optional, I would recommend flagging it mandatory
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure, I can add it. I was just asking because in many places that we use usedefault=True
we don't have mandatory=True
(and I believe some of them are mandatory).
But that was just general question, adding mandatory=True
won't hurt for sure, so will do it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah. Yeah, I think we should probably add mandatory=True
to those cases, when we see them. Alas, nipype interface metadata will remain inaccurate for a while longer.
nipype/interfaces/fsl/model.py
Outdated
@@ -56,7 +56,7 @@ class Level1DesignInputSpec(BaseInterfaceInputSpec): | |||
desc=("which regressors to make orthogonal e.g., " | |||
"{1: {0:0,1:0,2:0}, 2: {0:1,1:1,2:0}} to make the second " | |||
"regressor in a 2-regressor model orthogonal to the first."), | |||
default={}) | |||
value={}, usedefault=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{}
is already the default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's true, sometimes I just kept it if author wanted to be explicit, but can remove it
@@ -262,7 +262,8 @@ class Tractography(MRTrix3Base): | |||
>>> tk.inputs.roi_mask = 'mask.nii.gz' | |||
>>> tk.inputs.seed_sphere = (80, 100, 70, 10) | |||
>>> tk.cmdline # doctest: +ELLIPSIS | |||
'tckgen -algorithm iFOD2 -mask mask.nii.gz -seed_sphere \ | |||
'tckgen -algorithm iFOD2 -samples 4 -output_seeds out_seeds.nii.gz \ | |||
-mask mask.nii.gz -seed_sphere \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a note you can drop the backslashes from this output string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it doesn't work without
nipype/interfaces/mrtrix3/utils.py
Outdated
@@ -183,6 +183,7 @@ class TensorMetricsInputSpec(CommandLineInputSpec): | |||
argstr='-value %s', desc='output selected eigenvalue(s) file') | |||
component = traits.List( | |||
[1, 2, 3], | |||
usedefault=True, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the docs:
-num sequence specify the desired eigenvalue/eigenvector(s). Note that several eigenvalues can be specified as a number sequence. For example, ‘1,3’ specifies the principal (1) and minor (3) eigenvalues/eigenvectors (default = 1).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, can keep just the first one
nipype/interfaces/mrtrix3/utils.py
Outdated
@@ -266,7 +267,7 @@ class ComputeTDIInputSpec(CommandLineInputSpec): | |||
desc='specify output image data type') | |||
use_dec = traits.Bool(argstr='-dec', desc='perform mapping in DEC space') | |||
dixel = File( | |||
'dixels.txt', | |||
'dixels.txt', usedefault=True, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not clear to me from the docs that this is set by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can remove usedefault=True
, but I'd also remove the filename, imo it might me misleading
nipype/interfaces/niftyseg/em.py
Outdated
argstr='-min_iter %s', | ||
default_value=0, | ||
usedefault=True, | ||
desc='Minimun number of iterations') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minimum
@effigies thanks for review, I indeed have problem with judging if the default value are correct and if the interfaces works "better" now... Still have 2 tests that are giving me assert error because they're comparing to specific arrays, and not sure what to do with them. Will check your specific comments. |
…t i also remove this value)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Still not really sure about the ICA-AROMA trait, so making a little more noise.
nipype/interfaces/fsl/aroma.py
Outdated
@@ -28,7 +28,8 @@ class ICA_AROMAInputSpec(CommandLineInputSpec): | |||
xor=['feat_dir'], | |||
desc='volume to be denoised') | |||
out_dir = Directory( | |||
'out', genfile=True, argstr='-o %s', desc='output directory') | |||
'out', usedefault=True, genfile=True, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bump @jdkent.
@effigies - can you also suggest something regarding |
It explicitly says optional. I would drop it and add it to out_intensity_fusion_name_format = traits.Str(
argstr="",
desc='Optional intensity fusion image file name format. '
'(e.g. "antsJointFusionIntensity_%d.nii.gz")') |
@effigies ok, so I'll assume that |
Hello @djarecka @satra, @effigies, I think there might be an issue here. My lab mate noticed a considerable change in the output of FSL topup, and found the culprit to be the Previously, command for the popup with minimum required input was; 'topup --config=b02b0.cnf --datain=topup_encoding.txt But because of the 'topup --config=b02b0.cnf --datain=topup_encoding.txt All the additional arguments (e.g. --fwhm, --miter, --warpres..) are optional, yet set by default in the new version of nipype (>1.0.3). While FSL provides default values for these args, some of these are default values IF these options are chosen (e.g. 8mm smoothing IF --fwhm is set). Some of these values may be default used regardless of whether the optional arg was included or not, but otherwise it's introducing a whole set of arguments the user did not intend to use with the command. We found this to be the case for topup at least, but I think the options should be reviewed to make sure unintended options are not added to the command... |
@atsuch - thank you for reporting this issue. I added I understand that you main concern is that at least some of these additional arguments should not be used as default for cc: @oesteban - since you are the author of this interface, please let me know if you have any comments. |
I'm not expert in this command either. We just noticed the difference in the output when using the newer nipype in our pipeline. I read the FSL topup user guide quickly here (https://fsl.fmrib.ox.ac.uk/fsl/fslwiki/topup/TopupUsersGuide), and found it a bit ambiguous with regard to the default values for --fwhm, --miter, and --warpres. Even though calling the The fact that we get different results with or without setting these values suggest to me that these are not true default values, but we need to test it a bit more. We are running the command with and without some of these options to check the log and output. By the way, I just noticed that --miter argument repeat itself (5 and then 1) in the generated topup command. Do you have any idea why and which value is actually being used?? |
Hi again, @djarecka , @oesteban, We did some tests and checked the topup log file and found that default values related to subsampling scheme are actually different from what is described in the documentation, and that's why when you explicitly specify these (wrong) values as default, it gives a different result. For example, if we run the topup command with minimal arguments like this;
This is what the log tells you what it's doing. Notice the discrepancy in what it says is the default values, and what are actually used...
I flagged this in FSL mailing list, so we'll see if they can tell us if this is the bug in the documentation...https://www.jiscmail.ac.uk/cgi-bin/webadmin?A2=ind1807&L=fsl&F=&S=&P=136210 |
@atsuch - thank you for testing this more! Indeed the log is interesting, and it doesn't look like the default values are always used. I'd be happy to know what FSL team thinks about it. From And answering your question about |
Hi all, I also noticed this new behaviour when updating to a newer version of nipype. In comparison, the fsl-default values are overwritten by the config file, and the config file can be overwritten by the values given in the command. So I would suggest deactivating the nipype default values again. |
I tried to fix the names of the arguments, so the default values are set properly, changed:
default
inRange
,List
,Dict
,File
tovalue
default
inBool
,Int
,Float
todefault_value
default
inEnum
and put the value fromdefault
as the first one (so it will be treated as default)Also:
usedefault=True
, so I added for traits that were missing this, but I think there are much more traits that have a default value set (just don't usedefault
name argument) and they don't ask forusedefault=True
usedefault=False
I just removeddefault