Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -161,18 +161,13 @@ jobs:
- name: install dependencies
run: |
sudo apt-get update
sudo apt-get install pylint pylint3 python3-sphinx sphinx-rtd-theme-common python3-recommonmark python3-sphinx-rtd-theme python3-pip
sudo apt-get install pylint3 python3-sphinx sphinx-rtd-theme-common python3-recommonmark python3-sphinx-rtd-theme python3-pip
pip3 install sphinx-notfound-page


- name: check syntax
run: ./check_syntax || { cat syntax.log; false; }

- name: pylint (Python 2)
run: |
echo "__version__ = 'pylint testing' #pylint: disable=unused-variable" > ./lib/mrtrix3/_version.py
PYTHON=python2 ./run_pylint || { cat pylint.log; false; }

- name: pylint (Python 3)
run: |
echo "__version__ = 'pylint testing' #pylint: disable=unused-variable" > ./lib/mrtrix3/_version.py
Expand Down
2 changes: 1 addition & 1 deletion bin/dwi2response
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def execute(): #pylint: disable=unused-variable
if app.ARGS.lmax:
try:
lmax = [ int(x) for x in app.ARGS.lmax.split(',') ]
if any([lmax_value%2 for lmax_value in lmax]):
if any(lmax_value%2 for lmax_value in lmax):
raise MRtrixError('Value of lmax must be even')
except:
raise MRtrixError('Parameter lmax must be a number')
Expand Down
6 changes: 3 additions & 3 deletions bin/dwifslpreproc
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def execute(): #pylint: disable=unused-variable
if eddyqc_path:
if os.path.exists(eddyqc_path):
if os.path.isdir(eddyqc_path):
if any([ os.path.exists(os.path.join(eddyqc_path, filename)) for filename in eddyqc_files ]):
if any(os.path.exists(os.path.join(eddyqc_path, filename)) for filename in eddyqc_files):
if app.FORCE_OVERWRITE:
app.warn('Output eddy QC directory already contains relevant files; these will be overwritten on completion')
else:
Expand Down Expand Up @@ -267,11 +267,11 @@ def execute(): #pylint: disable=unused-variable
raise MRtrixError('Cannot use slice timing information in image header for slice-to-volume correction: '
'unexpected data format')
if isinstance(slice_timing[0], list):
if not all( [ len(entry) == 1 for entry in slice_timing ] ):
if not all(len(entry) == 1 for entry in slice_timing):
raise MRtrixError('Cannot use slice timing information in image header for slice-to-volume correction: '
'data do not appear to be 1D')
slice_timing = [ entry[0] for entry in slice_timing ]
if not all( [ isinstance(entry, float) for entry in slice_timing ] ):
if not all(isinstance(entry, float) for entry in slice_timing):
try:
slice_timing = [ float(entry) for entry in slice_timing ]
except ValueError:
Expand Down
2 changes: 1 addition & 1 deletion bin/for_each
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ def execute(): #pylint: disable=unused-variable

progress.done()

assert all([ job.returncode is not None for job in jobs ])
assert all(job.returncode is not None for job in jobs)
fail_count = sum([ 1 if job.returncode else 0 for job in jobs ])
if fail_count:
app.warn(str(fail_count) + ' of ' + str(len(jobs)) + ' jobs did not complete successfully')
Expand Down
32 changes: 19 additions & 13 deletions bin/population_template
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,12 @@ def check_linear_transformation(transformation, cmd, max_scaling=0.5, max_shear=
data = utils.load_keyval(transformation + 'decomp')
run.function(os.remove, transformation + 'decomp')
scaling = [float(value) for value in data['scaling']]
if any([a < 0 for a in scaling]) or any([a > (1 + max_scaling) for a in scaling]) or any(
[a < (1 - max_scaling) for a in scaling]):
if any(a < 0 for a in scaling) or any(a > (1 + max_scaling) for a in scaling) or any(
a < (1 - max_scaling) for a in scaling):
app.warn("large scaling (" + str(scaling) + ") in " + transformation)
good = False
shear = [float(value) for value in data['shear']]
if any([abs(a) > max_shear for a in shear]):
if any(abs(a) > max_shear for a in shear):
app.warn("large shear (" + str(shear) + ") in " + transformation)
good = False
rot_angle = float(data['angle_axis'][0])
Expand Down Expand Up @@ -190,7 +190,7 @@ def aggregate(inputs, output, contrast_idx, mode, force=True):
run.command(['mrmath', images, 'median', '-keep_unary_axes', output], force=force)
elif mode == 'weighted_mean':
weights = [inp.aggregation_weight for inp in inputs]
assert not any([w is None for w in weights]), weights
assert not any(w is None for w in weights), weights
wsum = sum([float(w) for w in weights])
cmd = ['mrcalc']
if wsum <= 0:
Expand Down Expand Up @@ -508,7 +508,7 @@ def parse_input_files(in_files, mask_files, contrasts, f_agg_weight=None):
for cid, files in enumerate(in_files):
c_uids.append([re.sub(re.escape(common_postfix[cid])+'$', '',
re.sub('^'+re.escape(common_prefix[cid]), '', fname)) for fname in files])
if not all([len(_uid) for _uid in c_uids[-1]]):
if not all(len(_uid) for _uid in c_uids[-1]):
MRtrixError("No uniquely identifiable part of filename found in file :\n" + '""\n'.join(non_unique))

for uids in c_uids:
Expand Down Expand Up @@ -565,7 +565,7 @@ def parse_input_files(in_files, mask_files, contrasts, f_agg_weight=None):
weights = [float(inp.aggregation_weight) for inp in inputs if inp.aggregation_weight is not None]
if sum(weights) <= 0:
raise MRtrixError('Sum of aggregation weights is not positive: ' + str(weights))
if any([w < 0 for w in weights]):
if any(w < 0 for w in weights):
app.warn('Negative aggregation weights: ' + str(weights))

return inputs, xcontrast_xsubject_pre_postfix
Expand Down Expand Up @@ -761,7 +761,7 @@ def execute(): #pylint: disable=unused-variable
raise MRtrixError("rigid_lmax option set when no rigid registration is performed")
rigid_lmax = [int(x) for x in app.ARGS.rigid_lmax.split(',')]
if do_fod_registration and len(rigid_scales) != len(rigid_lmax):
raise MRtrixError('rigid_scales and rigid_lmax schedules are not equal in length')
raise MRtrixError('rigid_scales and rigid_lmax schedules are not equal in length: scales stages: %s, lmax stages: %s' % (len(rigid_scales), len(rigid_lmax)))
else:
rigid_lmax = DEFAULT_RIGID_LMAX

Expand All @@ -773,7 +773,7 @@ def execute(): #pylint: disable=unused-variable
if len(rigid_niter) == 1:
rigid_niter = rigid_niter * len(rigid_scales)
elif len(rigid_scales) != len(rigid_niter):
raise MRtrixError('rigid_scales and rigid_niter schedules are not equal in length')
raise MRtrixError('rigid_scales and rigid_niter schedules are not equal in length: scales stages: %s, niter stages: %s' % (len(rigid_scales), len(rigid_niter)))

# affine options
if app.ARGS.affine_scale:
Expand All @@ -787,7 +787,7 @@ def execute(): #pylint: disable=unused-variable
raise MRtrixError("affine_lmax option set when no affine registration is performed")
affine_lmax = [int(x) for x in app.ARGS.affine_lmax.split(',')]
if do_fod_registration and len(affine_scales) != len(affine_lmax):
raise MRtrixError('affine_scales and affine_lmax schedules are not equal in length')
raise MRtrixError('affine_scales and affine_lmax schedules are not equal in length: scales stages: %s, lmax stages: %s' % (len(affine_scales), len(affine_lmax)))
else:
affine_lmax = DEFAULT_AFFINE_LMAX

Expand All @@ -799,7 +799,7 @@ def execute(): #pylint: disable=unused-variable
if len(affine_niter) == 1:
affine_niter = affine_niter * len(affine_scales)
elif len(affine_scales) != len(affine_niter):
raise MRtrixError('affine_scales and affine_niter schedules are not equal in length')
raise MRtrixError('affine_scales and affine_niter schedules are not equal in length: scales stages: %s, niter stages: %s' % (len(affine_scales), len(affine_niter)))

linear_scales = []
linear_lmax = []
Expand All @@ -820,7 +820,13 @@ def execute(): #pylint: disable=unused-variable
assert len(linear_type) == len(linear_scales)
assert len(linear_scales) == len(linear_niter)
if do_fod_registration:
assert len(linear_lmax) == len(linear_niter)
if len(linear_lmax) != len(linear_niter):
mismatch = []
if len(rigid_lmax) != len(rigid_niter):
mismatch += ['rigid: lmax stages: %s, niter stages: %s' % (len(rigid_lmax), len(rigid_niter))]
if len(affine_lmax) != len(affine_niter):
mismatch += ['affine: lmax stages: %s, niter stages: %s' % (len(affine_lmax), len(affine_niter))]
raise MRtrixError('linear registration: lmax and niter schedules are not equal in length: %s' % (', '.join(mismatch)))
app.console('-' * 60)
app.console('initial alignment of images: %s' % initial_alignment)
app.console('-' * 60)
Expand Down Expand Up @@ -864,7 +870,7 @@ def execute(): #pylint: disable=unused-variable
nl_lmax = [int(x) for x in app.ARGS.nl_lmax.split(',')] if app.ARGS.nl_lmax else DEFAULT_NL_LMAX

if len(nl_scales) != len(nl_niter):
raise MRtrixError('nl_scales and nl_niter schedules are not equal in length')
raise MRtrixError('nl_scales and nl_niter schedules are not equal in length: scales stages: %s, niter stages: %s' % (len(nl_scales), len(nl_niter)))

app.console('-' * 60)
app.console('nonlinear registration stages:')
Expand All @@ -875,7 +881,7 @@ def execute(): #pylint: disable=unused-variable

if do_fod_registration:
if len(nl_scales) != len(nl_lmax):
raise MRtrixError('nl_scales and nl_lmax schedules are not equal in length')
raise MRtrixError('nl_scales and nl_lmax schedules are not equal in length: scales stages: %s, lmax stages: %s' % (len(nl_scales), len(nl_lmax)))

if do_fod_registration:
for istage, [scale, lmax, niter] in enumerate(zip(nl_scales, nl_lmax, nl_niter)):
Expand Down
4 changes: 2 additions & 2 deletions cmd/mrregister.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -758,8 +758,8 @@ void run () {
if (opt.size()) {
if (!do_nonlinear)
throw Exception ("the -nl_lmax option has been set when no non-linear registration is requested");
if (input1[0].ndim() < 4)
throw Exception ("-nl_lmax option is not valid with 3D images");
if (max_mc_image_lmax == 0)
throw Exception ("-nl_lmax option is not valid if no input image is FOD image");
nl_lmax = parse_ints<uint32_t> (opt[0][0]);
nl_registration.set_lmax (nl_lmax);
for (size_t i = 0; i < (nl_lmax).size (); ++i)
Expand Down
2 changes: 1 addition & 1 deletion lib/mrtrix3/_5ttgen/hsvs.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def execute(): #pylint: disable=unused-variable
hipp_subfield_paired_images.append(lh_filename[1:])
# Choose which of these image pairs we are going to use
for code in [ '.CA.', '.FS60.' ]:
if any([ code in filename for filename in hipp_subfield_paired_images ]):
if any(code in filename for filename in hipp_subfield_paired_images):
hipp_subfield_image_suffix = [ filename for filename in hipp_subfield_paired_images if code in filename ][0]
have_hipp_subfields = True
break
Expand Down
2 changes: 1 addition & 1 deletion lib/mrtrix3/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ def quote_nonpipe(item):
cmdstring += (' ' if cmdstring else '') + quote_nonpipe(entry)
cmdsplit.append(entry)
elif isinstance(entry, list):
assert all([ isinstance(item, STRING_TYPES) for item in entry ])
assert all(isinstance(item, STRING_TYPES) for item in entry)
if len(entry) > 1:
common_prefix = os.path.commonprefix(entry)
common_suffix = os.path.commonprefix([i[::-1] for i in entry])[::-1]
Expand Down