Skip to content

Commit

Permalink
STY: Apply ruff/flake8-simplify rule SIM201
Browse files Browse the repository at this point in the history
SIM201 Use `... != ...` instead of `not ... == ...`
  • Loading branch information
DimitriPapadopoulos committed Oct 6, 2024
1 parent 2d86b80 commit cde4587
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 26 deletions.
8 changes: 4 additions & 4 deletions nipype/algorithms/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ def _run_interface(self, runtime):

output_array = merge_csvs(self.inputs.in_files)
_, name, ext = split_filename(self.inputs.out_file)
if not ext == ".csv":
if ext != ".csv":
ext = ".csv"

out_file = op.abspath(name + ext)
Expand Down Expand Up @@ -728,7 +728,7 @@ def _run_interface(self, runtime):
def _list_outputs(self):
outputs = self.output_spec().get()
_, name, ext = split_filename(self.inputs.out_file)
if not ext == ".csv":
if ext != ".csv":
ext = ".csv"
out_file = op.abspath(name + ext)
outputs["csv_file"] = out_file
Expand Down Expand Up @@ -774,7 +774,7 @@ class AddCSVColumn(BaseInterface):
def _run_interface(self, runtime):
in_file = open(self.inputs.in_file)
_, name, ext = split_filename(self.inputs.out_file)
if not ext == ".csv":
if ext != ".csv":
ext = ".csv"
out_file = op.abspath(name + ext)

Expand All @@ -794,7 +794,7 @@ def _run_interface(self, runtime):
def _list_outputs(self):
outputs = self.output_spec().get()
_, name, ext = split_filename(self.inputs.out_file)
if not ext == ".csv":
if ext != ".csv":
ext = ".csv"
out_file = op.abspath(name + ext)
outputs["csv_file"] = out_file
Expand Down
12 changes: 6 additions & 6 deletions nipype/interfaces/cmtk/cmtk.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def get_rois_crossed(pointsmm, roiData, voxelSize):
x = int(pointsmm[j, 0] / float(voxelSize[0]))
y = int(pointsmm[j, 1] / float(voxelSize[1]))
z = int(pointsmm[j, 2] / float(voxelSize[2]))
if not roiData[x, y, z] == 0:
if roiData[x, y, z] != 0:
rois_crossed.append(roiData[x, y, z])
rois_crossed = list(
dict.fromkeys(rois_crossed).keys()
Expand All @@ -91,7 +91,7 @@ def get_connectivity_matrix(n_rois, list_of_roi_crossed_lists):
for idx_i, roi_i in enumerate(rois_crossed):
for idx_j, roi_j in enumerate(rois_crossed):
if idx_i > idx_j:
if not roi_i == roi_j:
if roi_i != roi_j:
connectivity_matrix[roi_i - 1, roi_j - 1] += 1
connectivity_matrix = connectivity_matrix + connectivity_matrix.T
return connectivity_matrix
Expand Down Expand Up @@ -369,7 +369,7 @@ def cmat(
di["fiber_length_mean"] = 0
di["fiber_length_median"] = 0
di["fiber_length_std"] = 0
if not u == v: # Fix for self loop problem
if u != v: # Fix for self loop problem
G.add_edge(u, v, **di)
if "fiblist" in d:
numfib.add_edge(u, v, weight=di["number_of_fibers"])
Expand Down Expand Up @@ -398,7 +398,7 @@ def cmat(
pickle.dump(I, f, pickle.HIGHEST_PROTOCOL)

path, name, ext = split_filename(matrix_mat_name)
if not ext == ".mat":
if ext != ".mat":
ext = ".mat"
matrix_mat_name = matrix_mat_name + ext

Expand Down Expand Up @@ -608,7 +608,7 @@ def _run_interface(self, runtime):

matrix_mat_file = op.abspath(self.inputs.out_matrix_mat_file)
path, name, ext = split_filename(matrix_mat_file)
if not ext == ".mat":
if ext != ".mat":
ext = ".mat"
matrix_mat_file = matrix_mat_file + ext

Expand Down Expand Up @@ -673,7 +673,7 @@ def _list_outputs(self):

matrix_mat_file = op.abspath(self.inputs.out_matrix_mat_file)
path, name, ext = split_filename(matrix_mat_file)
if not ext == ".mat":
if ext != ".mat":
ext = ".mat"
matrix_mat_file = matrix_mat_file + ext

Expand Down
14 changes: 7 additions & 7 deletions nipype/interfaces/cmtk/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,17 +194,17 @@ def _run_interface(self, runtime):
for data in self.inputs.data_files:
_, data_name, _ = split_filename(data)
cda = cf.CData(name=data_name, src=data, fileformat="NumPy")
if not string.find(data_name, "lengths") == -1:
if string.find(data_name, 'lengths') != -1:
cda.dtype = "FinalFiberLengthArray"
if not string.find(data_name, "endpoints") == -1:
if string.find(data_name, 'endpoints') != -1:
cda.dtype = "FiberEndpoints"
if not string.find(data_name, "labels") == -1:
if string.find(data_name, 'labels') != -1:
cda.dtype = "FinalFiberLabels"
a.add_connectome_data(cda)

a.print_summary()
_, name, ext = split_filename(self.inputs.out_file)
if not ext == ".cff":
if ext != '.cff':
ext = ".cff"
cf.save_to_cff(a, op.abspath(name + ext))

Expand All @@ -213,7 +213,7 @@ def _run_interface(self, runtime):
def _list_outputs(self):
outputs = self._outputs().get()
_, name, ext = split_filename(self.inputs.out_file)
if not ext == ".cff":
if ext != '.cff':
ext = ".cff"
outputs["connectome_file"] = op.abspath(name + ext)
return outputs
Expand Down Expand Up @@ -281,7 +281,7 @@ def _run_interface(self, runtime):
metadata.set_email("My Email")

_, name, ext = split_filename(self.inputs.out_file)
if not ext == ".cff":
if ext != '.cff':
ext = ".cff"
cf.save_to_cff(newcon, op.abspath(name + ext))

Expand All @@ -290,7 +290,7 @@ def _run_interface(self, runtime):
def _list_outputs(self):
outputs = self._outputs().get()
_, name, ext = split_filename(self.inputs.out_file)
if not ext == ".cff":
if ext != '.cff':
ext = ".cff"
outputs["connectome_file"] = op.abspath(name + ext)
return outputs
8 changes: 4 additions & 4 deletions nipype/interfaces/cmtk/nx.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def average_networks(in_files, ntwk_res_file, group_id):
data = ntwk.edge[edge[0]][edge[1]]
if ntwk.edge[edge[0]][edge[1]]["count"] >= count_to_keep_edge:
for key in list(data.keys()):
if not key == "count":
if key != "count":
data[key] = data[key] / len(in_files)
ntwk.edge[edge[0]][edge[1]] = data
avg_ntwk.add_edge(edge[0], edge[1], **data)
Expand All @@ -184,7 +184,7 @@ def average_networks(in_files, ntwk_res_file, group_id):
for edge in avg_edges:
data = avg_ntwk.edge[edge[0]][edge[1]]
for key in list(data.keys()):
if not key == "count":
if key != "count":
edge_dict[key] = np.zeros(
(avg_ntwk.number_of_nodes(), avg_ntwk.number_of_nodes())
)
Expand Down Expand Up @@ -342,7 +342,7 @@ def add_node_data(node_array, ntwk):
node_ntwk = nx.Graph()
newdata = {}
for idx, data in ntwk.nodes(data=True):
if not int(idx) == 0:
if int(idx) != 0:
newdata["value"] = node_array[int(idx) - 1]
data.update(newdata)
node_ntwk.add_node(int(idx), **data)
Expand All @@ -354,7 +354,7 @@ def add_edge_data(edge_array, ntwk, above=0, below=0):
data = {}
for x, row in enumerate(edge_array):
for y in range(np.max(np.shape(edge_array[x]))):
if not edge_array[x, y] == 0:
if edge_array[x, y] != 0:
data["value"] = edge_array[x, y]
if data["value"] <= below or data["value"] >= above:
if edge_ntwk.has_edge(x + 1, y + 1):
Expand Down
2 changes: 1 addition & 1 deletion nipype/interfaces/dcmstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def _run_interface(self, runtime):
meta_filter = dcmstack.make_key_regex_filter(exclude_regexes, include_regexes)
stack = dcmstack.DicomStack(meta_filter=meta_filter)
for src_path in src_paths:
if not imghdr.what(src_path) == "gif":
if imghdr.what(src_path) != "gif":
src_dcm = pydicom.dcmread(src_path, force=self.inputs.force_read)
stack.add_dcm(src_dcm)
nii = stack.to_nifti(embed_meta=True)
Expand Down
4 changes: 2 additions & 2 deletions nipype/interfaces/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -1056,9 +1056,9 @@ def s3tolocal(self, s3path, bkt):
local_directory = str(self.inputs.local_directory)
bucket_path = str(self.inputs.bucket_path)
template = str(self.inputs.template)
if not os.path.basename(local_directory) == "":
if os.path.basename(local_directory) != "":
local_directory += "/"
if not os.path.basename(bucket_path) == "":
if os.path.basename(bucket_path) != "":
bucket_path += "/"
if template[0] == "/":
template = template[1:]
Expand Down
2 changes: 1 addition & 1 deletion nipype/interfaces/mne/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def _list_outputs(self):
else:
raise TypeError
outputs[k] = out_files
if not k.rfind("surface") == -1:
if k.rfind("surface") != -1:
mesh_paths.append(out_files)
outputs["mesh_files"] = mesh_paths
return outputs
2 changes: 1 addition & 1 deletion nipype/interfaces/mrtrix/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def track_gen(track_points):
pts_str = fileobj.read(n_pts * bytesize)
nan_str = fileobj.read(bytesize)
if len(pts_str) < (n_pts * bytesize):
if not n_streams == stream_count:
if n_streams != stream_count:
raise nb.trackvis.HeaderError(
f"Expecting {stream_count} points, found only {n_streams}"
)
Expand Down

0 comments on commit cde4587

Please sign in to comment.