Skip to content
Merged
4 changes: 1 addition & 3 deletions niworkflows/func/tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,7 @@ def test_masking(input_fname, expected_fname):

res = wf.run(plugin='MultiProc')

combine_masks = [node for node in res.nodes if node.name.endswith('combine_masks')][
0
]
combine_masks = next(node for node in res.nodes if node.name.endswith('combine_masks'))
overlap = symmetric_overlap(expected_fname, combine_masks.result.outputs.out_file)

mask_dir = reports_dir / 'fmriprep_bold_mask' / dsname
Expand Down
12 changes: 7 additions & 5 deletions niworkflows/interfaces/bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ def _run_interface(self, runtime):
data_dtype = nb.load(self.inputs.source_file[0]).get_data_dtype()
except Exception: # noqa: BLE001
LOGGER.warning(
f'Could not get data type of file {self.inputs.source_file[0]}'
'Could not get data type of file %s', self.inputs.source_file[0]
)
data_dtype = None

Expand All @@ -682,8 +682,10 @@ def _run_interface(self, runtime):
orig_dtype = nii.get_data_dtype()
if orig_dtype != data_dtype:
LOGGER.warning(
f'Changing {Path(dest_file).name} dtype '
f'from {orig_dtype} to {data_dtype}'
'Changing %s dtype from %s to %s',
Path(dest_file).name,
orig_dtype,
data_dtype,
)
# coerce dataobj to new data dtype
if np.issubdtype(data_dtype, np.integer):
Expand Down Expand Up @@ -1186,7 +1188,7 @@ def _run_interface(self, runtime):
data_dtype = nb.load(self.inputs.source_file[0]).get_data_dtype()
except Exception: # noqa: BLE001
LOGGER.warning(
f'Could not get data type of file {self.inputs.source_file[0]}'
'Could not get data type of file %s', self.inputs.source_file[0]
)
data_dtype = None

Expand All @@ -1195,7 +1197,7 @@ def _run_interface(self, runtime):
orig_dtype = nii.get_data_dtype()
if orig_dtype != data_dtype:
LOGGER.warning(
f'Changing {out_file} dtype from {orig_dtype} to {data_dtype}'
'Changing %s dtype from %s to %s', out_file, orig_dtype, orig_dtype
)
# coerce dataobj to new data dtype
if np.issubdtype(data_dtype, np.integer):
Expand Down
22 changes: 11 additions & 11 deletions niworkflows/interfaces/confounds.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,20 +534,20 @@ def _expand_shorthand(model_formula, variables):
nss = _get_matches_from_data('non_steady_state_outlier[0-9]+', variables)
spikes = _get_matches_from_data('motion_outlier[0-9]+', variables)

model_formula = re.sub(r'wm', wm, model_formula)
model_formula = re.sub(r'gsr', gsr, model_formula)
model_formula = re.sub(r'rps', rps, model_formula)
model_formula = re.sub(r'fd', fd, model_formula)
model_formula = re.sub(r'acc', acc, model_formula)
model_formula = re.sub(r'tcc', tcc, model_formula)
model_formula = re.sub(r'dv', dv, model_formula)
model_formula = re.sub(r'dvall', dvall, model_formula)
model_formula = re.sub(r'nss', nss, model_formula)
model_formula = re.sub(r'spikes', spikes, model_formula)
model_formula = model_formula.replace('wm', wm)
model_formula = model_formula.replace('gsr', gsr)
model_formula = model_formula.replace('rps', rps)
model_formula = model_formula.replace('fd', fd)
model_formula = model_formula.replace('acc', acc)
model_formula = model_formula.replace('tcc', tcc)
model_formula = model_formula.replace('dv', dv)
model_formula = model_formula.replace('dvall', dvall)
model_formula = model_formula.replace('nss', nss)
model_formula = model_formula.replace('spikes', spikes)

formula_variables = _get_variables_from_formula(model_formula)
others = ' + '.join(set(variables) - set(formula_variables))
model_formula = re.sub(r'others', others, model_formula)
model_formula = model_formula.replace('others', others)
return model_formula


Expand Down
2 changes: 1 addition & 1 deletion niworkflows/interfaces/tests/test_bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ def make_empty_nii_with_dtype(fname, dtype):
for s in source_file:
make_empty_nii_with_dtype(s, source_dtype)

prep, save = make_prep_and_save(
prep, _save = make_prep_and_save(
interface,
base_directory=str(tmp_path),
data_dtype='source',
Expand Down
2 changes: 1 addition & 1 deletion niworkflows/interfaces/tests/test_itk.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def test_applytfms(tmpdir, ext, copy_dtype, in_dtype):

ifargs = {'copy_dtype': copy_dtype, 'reference_image': in_file}
args = (in_file, in_xform, ifargs, 0, str(tmpdir))
out_file, cmdline = _applytfms(args)
out_file, _cmdline = _applytfms(args)

assert out_file == str(tmpdir / (f'src_xform-00000{ext}'))

Expand Down
4 changes: 2 additions & 2 deletions niworkflows/interfaces/tests/test_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

def test_cifti_carpetplot():
"""Exercise extraction of timeseries from CIFTI2."""
save_artifacts = os.getenv('SAVE_CIRCLE_ARTIFACTS', False)
save_artifacts = os.getenv('SAVE_CIRCLE_ARTIFACTS')

cifti_file = load_test_data(
'sub-01_task-mixedgamblestask_run-02_space-fsLR_den-91k_bold.dtseries.nii'
Expand All @@ -54,7 +54,7 @@ def test_cifti_carpetplot():

def test_nifti_carpetplot():
"""Exercise extraction of timeseries from CIFTI2."""
save_artifacts = os.getenv('SAVE_CIRCLE_ARTIFACTS', False)
save_artifacts = os.getenv('SAVE_CIRCLE_ARTIFACTS')

nifti_file = load_test_data('sub-ds205s03_task-functionallocalizer_run-01_bold_volreg.nii.gz')
seg_file = load_test_data('sub-ds205s03_task-functionallocalizer_run-01_bold_parc.nii.gz')
Expand Down
2 changes: 1 addition & 1 deletion niworkflows/interfaces/workbench.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ def _format_arg(self, opt, spec, val):
if opt == 'valid_roi_out' and val:
# generate a filename and add it to argstr
roi_out = self._gen_filename(self.inputs.in_file, suffix='_roi')
iflogger.info('Setting roi output file as', roi_out)
iflogger.info('Setting roi output file as %s', roi_out)
spec.argstr += ' ' + roi_out
return super()._format_arg(opt, spec, val)

Expand Down
4 changes: 1 addition & 3 deletions niworkflows/reports/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,9 +462,7 @@ def _process_orderings(orderings, layout):
{value[idx] for value in all_value_combos} for idx in range(len(orderings))
]
# if all values are None for an entity, we do not want to keep that entity
keep_idx = [
not (len(val_set) == 1 and None in val_set or not val_set) for val_set in unique_values
]
keep_idx = [val_set not in (set(), {None}) for val_set in unique_values]
# the "kept" entities
entities = list(compress(orderings, keep_idx))
# the "kept" value combinations
Expand Down
2 changes: 1 addition & 1 deletion niworkflows/tests/test_confounds.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
def _smoke_test_report(report_interface, artifact_name):
out_report = report_interface.run().outputs.out_file

save_artifacts = os.getenv('SAVE_CIRCLE_ARTIFACTS', False)
save_artifacts = os.getenv('SAVE_CIRCLE_ARTIFACTS')
if save_artifacts:
copy(out_report, os.path.join(save_artifacts, artifact_name))
assert os.path.isfile(out_report), f'Report "{out_report}" does not exist'
Expand Down
2 changes: 1 addition & 1 deletion niworkflows/tests/test_registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def _smoke_test_report(report_interface, artifact_name):
res = pe.Node(report_interface, name='smoke_test', base_dir=tmpdir).run()
out_report = res.outputs.out_report

save_artifacts = os.getenv('SAVE_CIRCLE_ARTIFACTS', False)
save_artifacts = os.getenv('SAVE_CIRCLE_ARTIFACTS')
if save_artifacts:
copy(out_report, os.path.join(save_artifacts, artifact_name))
assert os.path.isfile(out_report), 'Report does not exist'
Expand Down
2 changes: 1 addition & 1 deletion niworkflows/tests/test_segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def _smoke_test_report(report_interface, artifact_name):
res = pe.Node(report_interface, name='smoke_test', base_dir=tmpdir).run()
out_report = res.outputs.out_report

save_artifacts = os.getenv('SAVE_CIRCLE_ARTIFACTS', False)
save_artifacts = os.getenv('SAVE_CIRCLE_ARTIFACTS')
if save_artifacts:
copy(out_report, os.path.join(save_artifacts, artifact_name))
assert os.path.isfile(out_report), f'Report "{out_report}" does not exist'
Expand Down
4 changes: 2 additions & 2 deletions niworkflows/tests/test_viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
@pytest.mark.parametrize('sorting', [None, 'ward', 'linkage'])
def test_carpetplot(tr, sorting):
"""Write a carpetplot"""
save_artifacts = os.getenv('SAVE_CIRCLE_ARTIFACTS', False)
save_artifacts = os.getenv('SAVE_CIRCLE_ARTIFACTS')

rng = np.random.default_rng(2010)

Expand Down Expand Up @@ -137,7 +137,7 @@ def test_carpetplot(tr, sorting):
)
def test_fmriplot(input_files):
"""Exercise the fMRIPlot class."""
save_artifacts = os.getenv('SAVE_CIRCLE_ARTIFACTS', False)
save_artifacts = os.getenv('SAVE_CIRCLE_ARTIFACTS')
rng = np.random.default_rng(2010)

in_file = os.path.join(datadir, input_files[0])
Expand Down
27 changes: 22 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -118,32 +118,49 @@ line-length = 99

[tool.ruff.lint]
extend-select = [
"F",
"E",
"W",
"I",
"UP",
"YTT",
"S",
"BLE",
"B",
"A",
# "CPY",
"C4",
# "CPY",
"DTZ",
"T10",
# "EM",
"EXE",
"FA",
"ISC",
"ICN",
"LOG",
"G",
"PIE",
"PYI",
"PT",
"Q",
# "SIM",
# "TID",
"FLY",
# "PD",
"PERF",
"W",
"PGH",
"PLC",
"PLE",
"PLW",
"FURB",
"RUF",
]
ignore = [
"S311", # We are not using random for cryptographic purposes
"ISC001",
"S404",
"S603",
"PLW1510",
"PLW2901",
"RUF005",
"RUF012",
]

[tool.ruff.lint.flake8-quotes]
Expand Down