Skip to content

Commit

Permalink
STY: pyupgrade + black
Browse files Browse the repository at this point in the history
  • Loading branch information
effigies committed Jul 5, 2023
1 parent 1567b72 commit b8b2ab5
Show file tree
Hide file tree
Showing 413 changed files with 1,077 additions and 1,649 deletions.
6 changes: 2 additions & 4 deletions doc/conf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# emacs: -*- coding: utf-8; mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vi: set fileencoding=utf-8 ft=python sts=4 ts=4 sw=4 et:
#
# nipype documentation build configuration file, created by
# sphinx-quickstart on Mon Jul 20 12:30:18 2009.
Expand Down Expand Up @@ -151,8 +149,8 @@
master_doc = "index"

# General information about the project.
project = u"nipype"
copyright = u"2009-21, Neuroimaging in Python team"
project = "nipype"
copyright = "2009-21, Neuroimaging in Python team"

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
Expand Down
5 changes: 2 additions & 3 deletions nipype/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vi: set ft=python sts=4 ts=4 sw=4 et:
"""
Expand Down Expand Up @@ -26,14 +25,14 @@
import faulthandler

faulthandler.enable()
except (ImportError, IOError) as e:
except (ImportError, OSError) as e:
pass

config = NipypeConfig()
logging = Logging(config)


class NipypeTester(object):
class NipypeTester:
def __call__(self, doctests=True, parallel=False):
try:
import pytest
Expand Down
1 change: 0 additions & 1 deletion nipype/algorithms/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vi: set ft=python sts=4 ts=4 sw=4 et:
"""
Expand Down
37 changes: 17 additions & 20 deletions nipype/algorithms/confounds.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vi: set ft=python sts=4 ts=4 sw=4 et:
"""
Expand Down Expand Up @@ -150,7 +149,7 @@ class ComputeDVARS(BaseInterface):

def __init__(self, **inputs):
self._results = {}
super(ComputeDVARS, self).__init__(**inputs)
super().__init__(**inputs)

def _gen_fname(self, suffix, ext=None):
fname, in_ext = op.splitext(op.basename(self.inputs.in_file))
Expand All @@ -165,7 +164,7 @@ def _gen_fname(self, suffix, ext=None):
if ext.startswith("."):
ext = ext[1:]

return op.abspath("{}_{}.{}".format(fname, suffix, ext))
return op.abspath(f"{fname}_{suffix}.{ext}")

def _run_interface(self, runtime):
dvars = compute_dvars(
Expand Down Expand Up @@ -584,7 +583,7 @@ class CompCor(SimpleInterface):

def __init__(self, *args, **kwargs):
"""exactly the same as compcor except the header"""
super(CompCor, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
self._header = "CompCor"

def _run_interface(self, runtime):
Expand Down Expand Up @@ -713,7 +712,7 @@ def _run_interface(self, runtime):
self.inputs.pre_filter
]
ncols = filter_basis.shape[1] if filter_basis.size > 0 else 0
header = ["{}{:02d}".format(ftype, i) for i in range(ncols)]
header = [f"{ftype}{i:02d}" for i in range(ncols)]
if skip_vols:
old_basis = filter_basis
# nrows defined above
Expand All @@ -724,7 +723,7 @@ def _run_interface(self, runtime):
filter_basis[skip_vols:, :ncols] = old_basis
filter_basis[:skip_vols, -skip_vols:] = np.eye(skip_vols)
header.extend(
["NonSteadyStateOutlier{:02d}".format(i) for i in range(skip_vols)]
[f"NonSteadyStateOutlier{i:02d}" for i in range(skip_vols)]
)
np.savetxt(
self._results["pre_filter_file"],
Expand All @@ -747,7 +746,7 @@ def _run_interface(self, runtime):
not_retained = np.where(np.logical_not(metadata["retained"]))
components_names[retained] = components_header
components_names[not_retained] = [
"dropped{}".format(i) for i in range(len(not_retained[0]))
f"dropped{i}" for i in range(len(not_retained[0]))
]
with open(self._results["metadata_file"], "w") as f:
f.write("\t".join(["component"] + list(metadata.keys())) + "\n")
Expand All @@ -768,7 +767,7 @@ def _make_headers(self, num_col):
if isdefined(self.inputs.header_prefix)
else self._header
)
headers = ["{}{:02d}".format(header, i) for i in range(num_col)]
headers = [f"{header}{i:02d}" for i in range(num_col)]
return headers


Expand All @@ -781,7 +780,7 @@ class ACompCor(CompCor):

def __init__(self, *args, **kwargs):
"""exactly the same as compcor except the header"""
super(ACompCor, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
self._header = "aCompCor"


Expand All @@ -807,7 +806,7 @@ class TCompCorInputSpec(CompCorInputSpec):
class TCompCorOutputSpec(CompCorOutputSpec):
# and all the fields in CompCorOutputSpec
high_variance_masks = OutputMultiPath(
File(exists=True), desc=(("voxels exceeding the variance" " threshold"))
File(exists=True), desc=("voxels exceeding the variance" " threshold")
)


Expand All @@ -832,7 +831,7 @@ class TCompCor(CompCor):

def __init__(self, *args, **kwargs):
"""exactly the same as compcor except the header"""
super(TCompCor, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
self._header = "tCompCor"
self._mask_files = []

Expand All @@ -854,7 +853,7 @@ def _process_masks(self, mask_images, timeseries=None):
out_image = nb.Nifti1Image(mask_data, affine=img.affine, header=img.header)

# save mask
mask_file = os.path.abspath("mask_{:03d}.nii.gz".format(i))
mask_file = os.path.abspath(f"mask_{i:03d}.nii.gz")
out_image.to_filename(mask_file)
IFLOGGER.debug(
"tCompcor computed and saved mask of shape %s to " "mask_file %s",
Expand All @@ -866,7 +865,7 @@ def _process_masks(self, mask_images, timeseries=None):
return out_images

def _list_outputs(self):
outputs = super(TCompCor, self)._list_outputs()
outputs = super()._list_outputs()
outputs["high_variance_masks"] = self._mask_files
return outputs

Expand Down Expand Up @@ -1136,7 +1135,7 @@ def plot_confound(tseries, figsize, name, units=None, series_tr=None, normalize=

xlabel = "Frame #"
if series_tr is not None:
xlabel = "Frame # ({} sec TR)".format(series_tr)
xlabel = f"Frame # ({series_tr} sec TR)"
ax.set_xlabel(xlabel)
ylim = ax.get_ylim()

Expand Down Expand Up @@ -1280,17 +1279,15 @@ def combine_mask_files(mask_files, mask_method=None, mask_index=None):
mask_index = 0
else:
raise ValueError(
(
"When more than one mask file is provided, "
"one of merge_method or mask_index must be "
"set"
)
"When more than one mask file is provided, "
"one of merge_method or mask_index must be "
"set"
)
if mask_index < len(mask_files):
mask = nb.load(mask_files[mask_index])
return [mask]
raise ValueError(
("mask_index {0} must be less than number of mask " "files {1}").format(
("mask_index {} must be less than number of mask " "files {}").format(
mask_index, len(mask_files)
)
)
Expand Down
1 change: 0 additions & 1 deletion nipype/algorithms/icc.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import os
from functools import lru_cache
import numpy as np
Expand Down
7 changes: 3 additions & 4 deletions nipype/algorithms/mesh.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vi: set ft=python sts=4 ts=4 sw=4 et:
"""
Expand Down Expand Up @@ -30,7 +29,7 @@ class TVTKBaseInterface(BaseInterface):
def __init__(self, **inputs):
if VTKInfo.no_tvtk():
raise ImportError("This interface requires tvtk to run.")
super(TVTKBaseInterface, self).__init__(**inputs)
super().__init__(**inputs)


class WarpPointsInputSpec(BaseInterfaceInputSpec):
Expand Down Expand Up @@ -92,7 +91,7 @@ def _gen_fname(self, in_file, suffix="generated", ext=None):

if ext[0] == ".":
ext = ext[1:]
return op.abspath("%s_%s.%s" % (fname, suffix, ext))
return op.abspath(f"{fname}_{suffix}.{ext}")

def _run_interface(self, runtime):
import nibabel as nb
Expand Down Expand Up @@ -423,7 +422,7 @@ class P2PDistance(ComputeMeshWarp):
"""

def __init__(self, **inputs):
super(P2PDistance, self).__init__(**inputs)
super().__init__(**inputs)
IFLOGGER.warning(
"This interface has been deprecated since 1.0, please "
"use ComputeMeshWarp"
Expand Down
1 change: 0 additions & 1 deletion nipype/algorithms/metrics.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vi: set ft=python sts=4 ts=4 sw=4 et:
"""
Expand Down
31 changes: 14 additions & 17 deletions nipype/algorithms/misc.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vi: set ft=python sts=4 ts=4 sw=4 et:
"""Miscellaneous algorithms."""
Expand Down Expand Up @@ -494,7 +493,7 @@ def merge_csvs(in_list):
try:
in_array = np.loadtxt(in_file, delimiter=",", skiprows=1)
except ValueError:
with open(in_file, "r") as first:
with open(in_file) as first:
header_line = first.readline()

header_list = header_line.split(",")
Expand Down Expand Up @@ -671,7 +670,7 @@ def _run_interface(self, runtime):
iflogger.info(
'Row headings have been provided. Adding "labels"' "column header."
)
prefix = '"{p}","'.format(p=self.inputs.row_heading_title)
prefix = f'"{self.inputs.row_heading_title}","'
csv_headings = prefix + '","'.join(itertools.chain(headings)) + '"\n'
rowheadingsBool = True
else:
Expand Down Expand Up @@ -772,7 +771,7 @@ class AddCSVColumn(BaseInterface):
output_spec = AddCSVColumnOutputSpec

def _run_interface(self, runtime):
in_file = open(self.inputs.in_file, "r")
in_file = open(self.inputs.in_file)
_, name, ext = split_filename(self.inputs.out_file)
if not ext == ".csv":
ext = ".csv"
Expand Down Expand Up @@ -808,12 +807,12 @@ class AddCSVRowInputSpec(DynamicTraitedSpec, BaseInterfaceInputSpec):
def __setattr__(self, key, value):
if key not in self.copyable_trait_names():
if not isdefined(value):
super(AddCSVRowInputSpec, self).__setattr__(key, value)
super().__setattr__(key, value)
self._outputs[key] = value
else:
if key in self._outputs:
self._outputs[key] = value
super(AddCSVRowInputSpec, self).__setattr__(key, value)
super().__setattr__(key, value)


class AddCSVRowOutputSpec(TraitedSpec):
Expand Down Expand Up @@ -850,7 +849,7 @@ class AddCSVRow(BaseInterface):
output_spec = AddCSVRowOutputSpec

def __init__(self, infields=None, force_run=True, **kwargs):
super(AddCSVRow, self).__init__(**kwargs)
super().__init__(**kwargs)
undefined_traits = {}
self._infields = infields
self._have_lock = False
Expand Down Expand Up @@ -882,10 +881,8 @@ def _run_interface(self, runtime):
from warnings import warn

warn(
(
"Python module filelock was not found: AddCSVRow will not be"
" thread-safe in multi-processor execution"
)
"Python module filelock was not found: AddCSVRow will not be"
" thread-safe in multi-processor execution"
)

input_dict = {}
Expand Down Expand Up @@ -926,7 +923,7 @@ def _list_outputs(self):
return outputs

def _outputs(self):
return self._add_output_traits(super(AddCSVRow, self)._outputs())
return self._add_output_traits(super()._outputs())

def _add_output_traits(self, base):
return base
Expand Down Expand Up @@ -1070,7 +1067,7 @@ def _run_interface(self, runtime):
def _gen_output_filename(self):
if not isdefined(self.inputs.out_file):
_, base, ext = split_filename(self.inputs.in_file)
out_file = os.path.abspath("%s_SNR%03.2f%s" % (base, self.inputs.snr, ext))
out_file = os.path.abspath(f"{base}_SNR{self.inputs.snr:03.2f}{ext}")
else:
out_file = self.inputs.out_file

Expand Down Expand Up @@ -1121,7 +1118,7 @@ def gen_noise(self, image, mask=None, snr_db=10.0, dist="normal", bg_dist="norma
im_noise = np.sqrt((image + stde_1) ** 2 + (stde_2) ** 2)
else:
raise NotImplementedError(
("Only normal and rician distributions " "are supported")
"Only normal and rician distributions " "are supported"
)

return im_noise
Expand Down Expand Up @@ -1547,7 +1544,7 @@ class CalculateMedian(BaseInterface):
output_spec = CalculateMedianOutputSpec

def __init__(self, *args, **kwargs):
super(CalculateMedian, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
self._median_files = []

def _gen_fname(self, suffix, idx=None, ext=None):
Expand All @@ -1569,10 +1566,10 @@ def _gen_fname(self, suffix, idx=None, ext=None):
if self.inputs.median_file:
outname = self.inputs.median_file
else:
outname = "{}_{}".format(fname, suffix)
outname = f"{fname}_{suffix}"
if idx:
outname += str(idx)
return op.abspath("{}.{}".format(outname, ext))
return op.abspath(f"{outname}.{ext}")

def _run_interface(self, runtime):
total = None
Expand Down
Loading

0 comments on commit b8b2ab5

Please sign in to comment.