From cde458746a5c8def714e70ddb6f16246de7502c2 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Sun, 22 Sep 2024 13:13:07 +0200 Subject: [PATCH] STY: Apply ruff/flake8-simplify rule SIM201 SIM201 Use `... != ...` instead of `not ... == ...` --- nipype/algorithms/misc.py | 8 ++++---- nipype/interfaces/cmtk/cmtk.py | 12 ++++++------ nipype/interfaces/cmtk/convert.py | 14 +++++++------- nipype/interfaces/cmtk/nx.py | 8 ++++---- nipype/interfaces/dcmstack.py | 2 +- nipype/interfaces/io.py | 4 ++-- nipype/interfaces/mne/base.py | 2 +- nipype/interfaces/mrtrix/convert.py | 2 +- 8 files changed, 26 insertions(+), 26 deletions(-) diff --git a/nipype/algorithms/misc.py b/nipype/algorithms/misc.py index edc750f387..f122f21955 100644 --- a/nipype/algorithms/misc.py +++ b/nipype/algorithms/misc.py @@ -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) @@ -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 @@ -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) @@ -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 diff --git a/nipype/interfaces/cmtk/cmtk.py b/nipype/interfaces/cmtk/cmtk.py index 9bc3a36d6d..8f8d7a05fc 100644 --- a/nipype/interfaces/cmtk/cmtk.py +++ b/nipype/interfaces/cmtk/cmtk.py @@ -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() @@ -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 @@ -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"]) @@ -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 @@ -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 @@ -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 diff --git a/nipype/interfaces/cmtk/convert.py b/nipype/interfaces/cmtk/convert.py index 72d105b715..4f55242a94 100644 --- a/nipype/interfaces/cmtk/convert.py +++ b/nipype/interfaces/cmtk/convert.py @@ -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)) @@ -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 @@ -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)) @@ -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 diff --git a/nipype/interfaces/cmtk/nx.py b/nipype/interfaces/cmtk/nx.py index 7a9e2f9d8a..164009541e 100644 --- a/nipype/interfaces/cmtk/nx.py +++ b/nipype/interfaces/cmtk/nx.py @@ -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) @@ -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()) ) @@ -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) @@ -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): diff --git a/nipype/interfaces/dcmstack.py b/nipype/interfaces/dcmstack.py index b76255ab84..8e9b8feb42 100644 --- a/nipype/interfaces/dcmstack.py +++ b/nipype/interfaces/dcmstack.py @@ -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) diff --git a/nipype/interfaces/io.py b/nipype/interfaces/io.py index 4ed411b1b5..0cc639553e 100644 --- a/nipype/interfaces/io.py +++ b/nipype/interfaces/io.py @@ -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:] diff --git a/nipype/interfaces/mne/base.py b/nipype/interfaces/mne/base.py index 39d23e253c..fdf612f278 100644 --- a/nipype/interfaces/mne/base.py +++ b/nipype/interfaces/mne/base.py @@ -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 diff --git a/nipype/interfaces/mrtrix/convert.py b/nipype/interfaces/mrtrix/convert.py index 8a0e14d3eb..f47bc0eff2 100644 --- a/nipype/interfaces/mrtrix/convert.py +++ b/nipype/interfaces/mrtrix/convert.py @@ -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}" )