diff --git a/niworkflows/anat/ants.py b/niworkflows/anat/ants.py index c77089f85eb..8e14c53e415 100644 --- a/niworkflows/anat/ants.py +++ b/niworkflows/anat/ants.py @@ -716,15 +716,11 @@ def init_atropos_wf( me_7_2 = pe.Node(ImageMath(operation='ME', op2='5'), name='22_me_7_2') # De-pad - depad_mask = pe.Node( - ImageMath(operation='PadImage', op2='-%d' % padding), name='23_depad_mask' - ) - depad_segm = pe.Node( - ImageMath(operation='PadImage', op2='-%d' % padding), name='24_depad_segm' - ) - depad_gm = pe.Node(ImageMath(operation='PadImage', op2='-%d' % padding), name='25_depad_gm') - depad_wm = pe.Node(ImageMath(operation='PadImage', op2='-%d' % padding), name='26_depad_wm') - depad_csf = pe.Node(ImageMath(operation='PadImage', op2='-%d' % padding), name='27_depad_csf') + depad_mask = pe.Node(ImageMath(operation='PadImage', op2=f'-{padding}'), name='23_depad_mask') + depad_segm = pe.Node(ImageMath(operation='PadImage', op2=f'-{padding}'), name='24_depad_segm') + depad_gm = pe.Node(ImageMath(operation='PadImage', op2=f'-{padding}'), name='25_depad_gm') + depad_wm = pe.Node(ImageMath(operation='PadImage', op2=f'-{padding}'), name='26_depad_wm') + depad_csf = pe.Node(ImageMath(operation='PadImage', op2=f'-{padding}'), name='27_depad_csf') msk_conform = pe.Node(niu.Function(function=_conform_mask), name='msk_conform') merge_tpms = pe.Node(niu.Merge(in_segmentation_model[0]), name='merge_tpms') @@ -1052,7 +1048,7 @@ def _select_labels(in_segm, labels): for label in labels: newnii = nii.__class__(np.uint8(label_data == label), nii.affine, nii.header) newnii.set_data_dtype('uint8') - out_file = fname_presuffix(in_segm, suffix='_class-%02d' % label, newpath=cwd) + out_file = fname_presuffix(in_segm, suffix=f'_class-{label:02d}', newpath=cwd) newnii.to_filename(out_file) out_files.append(out_file) return out_files diff --git a/niworkflows/interfaces/itk.py b/niworkflows/interfaces/itk.py index 86e532dbf47..ae9b0274f52 100644 --- a/niworkflows/interfaces/itk.py +++ b/niworkflows/interfaces/itk.py @@ -182,7 +182,7 @@ def _applytfms(args): in_file, in_xform, ifargs, index, newpath = args out_file = fname_presuffix( - in_file, suffix='_xform-%05d' % index, newpath=newpath, use_ext=True + in_file, suffix=f'_xform-{index:05d}', newpath=newpath, use_ext=True ) copy_dtype = ifargs.pop('copy_dtype', False) @@ -244,19 +244,19 @@ def _arrange_xfms(transforms, num_files, tmp_folder): if nxforms != num_files: raise RuntimeError( - 'Number of transforms (%d) found in the ITK file does not match' - ' the number of input image files (%d).' % (nxforms, num_files) + f'Number of transforms ({nxforms}) found in the ITK file does not' + f' match the number of input image files ({num_files}).' ) # At this point splitting transforms will be necessary, generate a base name out_base = fname_presuffix( - tf_file, suffix='_pos-%03d_xfm-{:05d}' % i, newpath=tmp_folder.name + tf_file, suffix=f'_pos-{i:03d}_xfm-{{:05d}}', newpath=tmp_folder.name ).format # Split combined ITK transforms file split_xfms = [] for xform_i in range(nxforms): # Find start token to extract - startidx = tfdata.index('#Transform %d' % xform_i) + startidx = tfdata.index(f'#Transform {xform_i}') next_xform = base_xform + tfdata[startidx + 1 : startidx + 4] + [''] xfm_file = out_base(xform_i) with open(xfm_file, 'w') as out_xfm: diff --git a/niworkflows/interfaces/norm.py b/niworkflows/interfaces/norm.py index d3a3336b9ea..3f2f3399046 100644 --- a/niworkflows/interfaces/norm.py +++ b/niworkflows/interfaces/norm.py @@ -222,7 +222,7 @@ def _run_interface(self, runtime): if interface_result.runtime.returncode != 0: NIWORKFLOWS_LOG.warning('Retry #%d failed.', self.retry) # Save outputs (if available) - term_out = _write_outputs(interface_result.runtime, '.nipype-%04d' % self.retry) + term_out = _write_outputs(interface_result.runtime, f'.nipype-{self.retry:04d}') if term_out: NIWORKFLOWS_LOG.warning('Log of failed retry saved (%s).', ', '.join(term_out)) else: @@ -235,9 +235,7 @@ def _run_interface(self, runtime): self.retry += 1 # If all tries fail, raise an error. - raise RuntimeError( - 'Robust spatial normalization failed after %d retries.' % (self.retry - 1) - ) + raise RuntimeError(f'Robust spatial normalization failed after {self.retry - 1} retries.') def _get_ants_args(self): args = { diff --git a/niworkflows/interfaces/tests/test_images.py b/niworkflows/interfaces/tests/test_images.py index 525f0c9309f..4f261bcf485 100644 --- a/niworkflows/interfaces/tests/test_images.py +++ b/niworkflows/interfaces/tests/test_images.py @@ -60,13 +60,13 @@ def test_signal_extraction_equivalence(tmp_path, nvols, nmasks, ext, factor): se1 = nl.SignalExtraction( in_file=img_fname, label_files=masks_fname, - class_labels=['a%d' % i for i in range(nmasks)], + class_labels=[f'a{i}' for i in range(nmasks)], out_file=nlsignals, ) se2 = im.SignalExtraction( in_file=img_fname, label_files=masks_fname, - class_labels=['a%d' % i for i in range(nmasks)], + class_labels=[f'a{i}' for i in range(nmasks)], out_file=imsignals, ) diff --git a/niworkflows/interfaces/tests/test_itk.py b/niworkflows/interfaces/tests/test_itk.py index 7648ab02d3f..b622e36f3c5 100644 --- a/niworkflows/interfaces/tests/test_itk.py +++ b/niworkflows/interfaces/tests/test_itk.py @@ -52,7 +52,7 @@ def test_applytfms(tmpdir, ext, copy_dtype, in_dtype): args = (in_file, in_xform, ifargs, 0, str(tmpdir)) out_file, cmdline = _applytfms(args) - assert out_file == str(tmpdir / ('src_xform-%05d%s' % (0, ext))) + assert out_file == str(tmpdir / (f'src_xform-00000{ext}')) out_nii = nb.load(out_file) assert np.allclose(nii.affine, out_nii.affine) diff --git a/niworkflows/reports/core.py b/niworkflows/reports/core.py index 90348f39c1b..016c2fb4721 100644 --- a/niworkflows/reports/core.py +++ b/niworkflows/reports/core.py @@ -537,7 +537,7 @@ def generate_reports( logger = logging.getLogger('cli') error_list = ', '.join( - '%s (%d)' % (subid, err) for subid, err in zip(subject_list, report_errors) if err + f'{subid} ({err})' for subid, err in zip(subject_list, report_errors) if err ) logger.error( 'Preprocessing did not finish successfully. Errors occurred while processing ' diff --git a/niworkflows/tests/test_segmentation.py b/niworkflows/tests/test_segmentation.py index 2f3abac336b..52729c62c8d 100644 --- a/niworkflows/tests/test_segmentation.py +++ b/niworkflows/tests/test_segmentation.py @@ -129,7 +129,7 @@ def test_ROIsPlot2(tmp_path): for i in range(1, 5): seg = np.zeros_like(newdata, dtype='uint8') seg[(newdata > 0) & (newdata <= i)] = 1 - out_file = str(tmp_path / ('segments%02d.nii.gz' % i)) + out_file = str(tmp_path / f'segments{i:02d}.nii.gz') nb.Nifti1Image(seg, im.affine, hdr).to_filename(out_file) out_files.append(out_file) roi_rpt = ROIsPlot( diff --git a/niworkflows/tests/test_utils.py b/niworkflows/tests/test_utils.py index 06810604648..278ddaee892 100644 --- a/niworkflows/tests/test_utils.py +++ b/niworkflows/tests/test_utils.py @@ -89,6 +89,6 @@ def test_compression(tmp_path): size = int(os.stat(uncompressed).st_size) size_compress = int(os.stat(compressed).st_size) assert size >= size_compress, ( - 'The uncompressed report is smaller (%d)' - 'than the compressed report (%d)' % (size, size_compress) + f'The uncompressed report is smaller ({size})' + f'than the compressed report ({size_compress})' )