Skip to content

Commit ea1bb2d

Browse files
Apply ruff/flake8-bugbear rule B007
B007 Loop control variable not used within loop body
1 parent fcad394 commit ea1bb2d

File tree

24 files changed

+58
-57
lines changed

24 files changed

+58
-57
lines changed

nipype/algorithms/mesh.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ def _run_interface(self, runtime):
243243
if self.inputs.weighting == "area":
244244
faces = vtk1.polys.to_array().reshape(-1, 4).astype(int)[:, 1:]
245245

246-
for i, p1 in enumerate(points2):
246+
for i, _ in enumerate(points2):
247247
# compute surfaces, set in weight
248248
w = 0.0
249249
point_faces = faces[(faces[:, :] == i).any(axis=1)]

nipype/algorithms/misc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ def _run_interface(self, runtime):
713713
mx = shape[0]
714714
else:
715715
mx = 1
716-
for idx in range(0, mx):
716+
for _ in range(0, mx):
717717
extrafieldlist.append(self.inputs.extra_field)
718718
iflogger.info(len(extrafieldlist))
719719
output[extraheading] = extrafieldlist

nipype/algorithms/modelgen.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ def _generate_standard_design(
385385
sessinfo[i]["hpf"] = float(self.inputs.high_pass_filter_cutoff)
386386

387387
if hasattr(info, "conditions") and info.conditions is not None:
388-
for cid, cond in enumerate(info.conditions):
388+
for cid, _ in enumerate(info.conditions):
389389
sessinfo[i]["cond"].insert(cid, dict())
390390
sessinfo[i]["cond"][cid]["name"] = info.conditions[cid]
391391
scaled_onset = scale_timings(
@@ -423,7 +423,7 @@ def _generate_standard_design(
423423

424424
sessinfo[i]["regress"] = []
425425
if hasattr(info, "regressors") and info.regressors is not None:
426-
for j, r in enumerate(info.regressors):
426+
for j, _ in enumerate(info.regressors):
427427
sessinfo[i]["regress"].insert(j, dict(name="", val=[]))
428428
if (
429429
hasattr(info, "regressor_names")
@@ -436,7 +436,7 @@ def _generate_standard_design(
436436
sessinfo[i]["scans"] = functional_runs[i]
437437

438438
if realignment_parameters is not None:
439-
for i, rp in enumerate(realignment_parameters):
439+
for i, _ in enumerate(realignment_parameters):
440440
mc = realignment_parameters[i]
441441
for col in range(mc.shape[1]):
442442
colidx = len(sessinfo[i]["regress"])
@@ -595,7 +595,7 @@ def _concatenate_info(self, infolist):
595595
for i, info in enumerate(infolist[1:]):
596596
# info.[conditions, tmod] remain the same
597597
if info.onsets:
598-
for j, val in enumerate(info.onsets):
598+
for j, _ in enumerate(info.onsets):
599599
if self.inputs.input_units == "secs":
600600
onsets = np.array(
601601
info.onsets[j]
@@ -619,7 +619,7 @@ def _concatenate_info(self, infolist):
619619
)
620620

621621
if hasattr(info, "amplitudes") and info.amplitudes:
622-
for j, val in enumerate(info.amplitudes):
622+
for j, _ in enumerate(info.amplitudes):
623623
infoout.amplitudes[j].extend(info.amplitudes[j])
624624

625625
if hasattr(info, "pmod") and info.pmod:
@@ -631,7 +631,7 @@ def _concatenate_info(self, infolist):
631631
if hasattr(info, "regressors") and info.regressors:
632632
# assumes same ordering of regressors across different
633633
# runs and the same names for the regressors
634-
for j, v in enumerate(info.regressors):
634+
for j, _ in enumerate(info.regressors):
635635
infoout.regressors[j].extend(info.regressors[j])
636636

637637
# insert session regressors

nipype/interfaces/cmtk/nx.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ def add_node_data(node_array, ntwk):
352352
def add_edge_data(edge_array, ntwk, above=0, below=0):
353353
edge_ntwk = ntwk.copy()
354354
data = {}
355-
for x, row in enumerate(edge_array):
355+
for x, _row in enumerate(edge_array):
356356
for y in range(0, np.max(np.shape(edge_array[x]))):
357357
if not edge_array[x, y] == 0:
358358
data["value"] = edge_array[x, y]
@@ -551,7 +551,7 @@ def _run_interface(self, runtime):
551551
# stacks them together, and saves them in a MATLAB .mat file via Scipy
552552
global dicts
553553
dicts = list()
554-
for idx, key in enumerate(dict_measures.keys()):
554+
for key in dict_measures.keys():
555555
for idxd, keyd in enumerate(dict_measures[key].keys()):
556556
if idxd == 0:
557557
nparraykeys = np.array(keyd)

nipype/interfaces/cmtk/parcellation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ def create_wm_mask(subject_id, subjects_dir, fs_dir, parcellation_name):
600600
roid = np.asanyarray(roi.dataobj)
601601
assert roid.shape[0] == wmmask.shape[0]
602602
pg = nx.read_graphml(pgpath)
603-
for brk, brv in pg.nodes(data=True):
603+
for _brk, brv in pg.nodes(data=True):
604604
if brv["dn_region"] == "cortical":
605605
iflogger.info(
606606
"Subtracting region %s with intensity value %s",

nipype/interfaces/dcmstack.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ def _run_interface(self, runtime):
186186
stacks = dcmstack.parse_and_stack(src_paths)
187187

188188
self.out_list = []
189-
for key, stack in list(stacks.items()):
189+
for stack in stacks.values():
190190
nw = NiftiWrapper(stack.to_nifti(embed_meta=True))
191191
const_meta = nw.meta_ext.get_class_dict(("global", "const"))
192192
out_path = self._get_out_path(const_meta)

nipype/interfaces/dipy/simulate.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ def _run_interface(self, runtime):
207207
dirs = np.hstack((dirs, fd[msk > 0]))
208208

209209
# Add random directions for isotropic components
210-
for d in range(nballs):
210+
for _ in range(nballs):
211211
fd = np.random.randn(nvox, 3)
212212
w = np.linalg.norm(fd, axis=1)
213213
fd[w < np.finfo(float).eps, ...] = np.array([1.0, 0.0, 0.0])
@@ -343,7 +343,7 @@ def _generate_gradients(ndirs=64, values=(1000, 3000), nb0s=1):
343343
bvecs = np.vstack((bvecs, vertices))
344344
bvals = np.hstack((bvals, v * np.ones(vertices.shape[0])))
345345

346-
for i in range(0, nb0s):
346+
for _ in range(0, nb0s):
347347
bvals = bvals.tolist()
348348
bvals.insert(0, 0)
349349

nipype/interfaces/fsl/model.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ def _create_ev_files(
199199
# regressors
200200
num_evs = [0, 0]
201201
for field in ["cond", "regress"]:
202-
for i, cond in enumerate(runinfo[field]):
202+
for cond in runinfo[field]:
203203
name = cond["name"]
204204
evname.append(name)
205205
evfname = os.path.join(
@@ -279,7 +279,7 @@ def _create_ev_files(
279279
# add t/f contrast info
280280
ev_txt += contrast_header.substitute()
281281
con_names = []
282-
for j, con in enumerate(contrasts):
282+
for con in contrasts:
283283
con_names.append(con[0])
284284
con_map = {}
285285
ftest_idx = []
@@ -364,7 +364,7 @@ def _run_interface(self, runtime):
364364
n_tcon = 0
365365
n_fcon = 0
366366
if isdefined(self.inputs.contrasts):
367-
for i, c in enumerate(self.inputs.contrasts):
367+
for c in self.inputs.contrasts:
368368
if c[1] == "T":
369369
n_tcon += 1
370370
elif c[1] == "F":
@@ -422,7 +422,7 @@ def _list_outputs(self):
422422
outputs["ev_files"].insert(runno, [])
423423
evname = []
424424
for field in ["cond", "regress"]:
425-
for i, cond in enumerate(runinfo[field]):
425+
for cond in runinfo[field]:
426426
name = cond["name"]
427427
evname.append(name)
428428
evfname = os.path.join(
@@ -1382,7 +1382,7 @@ def _run_interface(self, runtime):
13821382
"",
13831383
"/Matrix",
13841384
]
1385-
for i in range(self.inputs.num_copes):
1385+
for _ in range(self.inputs.num_copes):
13861386
mat_txt += ["1"]
13871387
mat_txt = "\n".join(mat_txt)
13881388

@@ -1405,16 +1405,16 @@ def _run_interface(self, runtime):
14051405
"",
14061406
"/Matrix",
14071407
]
1408-
for i in range(self.inputs.num_copes):
1408+
for _ in range(self.inputs.num_copes):
14091409
grp_txt += ["1"]
14101410
grp_txt = "\n".join(grp_txt)
14111411

14121412
txt = {"design.mat": mat_txt, "design.con": con_txt, "design.grp": grp_txt}
14131413

14141414
# write design files
1415-
for i, name in enumerate(["design.mat", "design.con", "design.grp"]):
1415+
for name, name_txt in txt.items():
14161416
f = open(os.path.join(cwd, name), "w")
1417-
f.write(txt[name])
1417+
f.write(name_txt)
14181418
f.close()
14191419

14201420
return runtime
@@ -1554,7 +1554,7 @@ def _run_interface(self, runtime):
15541554
"",
15551555
"/Matrix",
15561556
]
1557-
for conidx, con in enumerate(self.inputs.contrasts):
1557+
for con in self.inputs.contrasts:
15581558
if con[1] == "F":
15591559
convals = np.zeros((ntcons, 1))
15601560
for tcon in con[2]:

nipype/interfaces/fsl/preprocess.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ def _list_outputs(self):
425425
if len(self.inputs.in_files) > 1:
426426
# for multi-image segmentation there is one corrected image
427427
# per input
428-
for val, f in enumerate(self.inputs.in_files):
428+
for val, _ in enumerate(self.inputs.in_files):
429429
# image numbering is 1-based
430430
outputs["restored_image"].append(
431431
self._gen_fname(
@@ -453,7 +453,7 @@ def _list_outputs(self):
453453
if len(self.inputs.in_files) > 1:
454454
# for multi-image segmentation there is one bias field image
455455
# per input
456-
for val, f in enumerate(self.inputs.in_files):
456+
for val, _ in enumerate(self.inputs.in_files):
457457
# image numbering is 1-based
458458
outputs["bias_field"].append(
459459
self._gen_fname(

nipype/interfaces/io.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ def _upload_to_s3(self, bucket, src, dst):
608608
# If src is a directory, collect files (this assumes dst is a dir too)
609609
if os.path.isdir(src):
610610
src_files = []
611-
for root, dirs, files in os.walk(src):
611+
for root, _dirs, files in os.walk(src):
612612
src_files.extend([os.path.join(root, fil) for fil in files])
613613
# Make the dst files have the dst folder as base dir
614614
dst_files = [os.path.join(dst, src_f.split(src)[1]) for src_f in src_files]
@@ -1395,7 +1395,7 @@ def __init__(self, templates, **kwargs):
13951395

13961396
# Infer the infields and outfields from the template
13971397
infields = []
1398-
for name, template in list(templates.items()):
1398+
for template in templates.values():
13991399
for _, field_name, _, _ in string.Formatter().parse(template):
14001400
if field_name is not None:
14011401
field_name = re.match(r"\w+", field_name).group()

0 commit comments

Comments
 (0)