Skip to content

Commit ea421bc

Browse files
DimitriPapadopouloseffigies
authored andcommitted
STY: Apply ruff/flake8-bugbear rule B007
B007 Loop control variable not used within loop body
1 parent fffc1c2 commit ea421bc

File tree

23 files changed

+60
-63
lines changed

23 files changed

+60
-63
lines changed

nipype/algorithms/mesh.py

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

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

nipype/algorithms/modelgen.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ def _generate_standard_design(
389389
if hasattr(info, "conditions") and info.conditions is not None:
390390
for cid, cond in enumerate(info.conditions):
391391
sessinfo[i]["cond"].insert(cid, dict())
392-
sessinfo[i]["cond"][cid]["name"] = info.conditions[cid]
392+
sessinfo[i]["cond"][cid]["name"] = cond
393393
scaled_onset = scale_timings(
394394
info.onsets[cid],
395395
self.inputs.input_units,
@@ -434,12 +434,12 @@ def _generate_standard_design(
434434
sessinfo[i]["regress"][j]["name"] = info.regressor_names[j]
435435
else:
436436
sessinfo[i]["regress"][j]["name"] = "UR%d" % (j + 1)
437-
sessinfo[i]["regress"][j]["val"] = info.regressors[j]
437+
sessinfo[i]["regress"][j]["val"] = r
438438
sessinfo[i]["scans"] = functional_runs[i]
439439

440440
if realignment_parameters is not None:
441441
for i, rp in enumerate(realignment_parameters):
442-
mc = realignment_parameters[i]
442+
mc = rp
443443
for col in range(mc.shape[1]):
444444
colidx = len(sessinfo[i]["regress"])
445445
sessinfo[i]["regress"].insert(colidx, dict(name="", val=[]))
@@ -597,7 +597,7 @@ def _concatenate_info(self, infolist):
597597
for i, info in enumerate(infolist[1:]):
598598
# info.[conditions, tmod] remain the same
599599
if info.onsets:
600-
for j, val in enumerate(info.onsets):
600+
for j, _ in enumerate(info.onsets):
601601
if self.inputs.input_units == "secs":
602602
onsets = np.array(
603603
info.onsets[j]
@@ -621,7 +621,7 @@ def _concatenate_info(self, infolist):
621621
)
622622

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

627627
if hasattr(info, "pmod") and info.pmod:
@@ -633,7 +633,7 @@ def _concatenate_info(self, infolist):
633633
if hasattr(info, "regressors") and info.regressors:
634634
# assumes same ordering of regressors across different
635635
# runs and the same names for the regressors
636-
for j, v in enumerate(info.regressors):
636+
for j, _ in enumerate(info.regressors):
637637
infoout.regressors[j].extend(info.regressors[j])
638638

639639
# insert session regressors

nipype/interfaces/cmtk/nx.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ def add_node_data(node_array, ntwk):
351351
def add_edge_data(edge_array, ntwk, above=0, below=0):
352352
edge_ntwk = ntwk.copy()
353353
data = {}
354-
for x, row in enumerate(edge_array):
354+
for x, row in enumerate(edge_array): # noqa: B007
355355
for y in range(np.max(np.shape(edge_array[x]))):
356356
if edge_array[x, y] != 0:
357357
data["value"] = edge_array[x, y]
@@ -550,14 +550,14 @@ def _run_interface(self, runtime):
550550
# stacks them together, and saves them in a MATLAB .mat file via Scipy
551551
global dicts
552552
dicts = list()
553-
for idx, key in enumerate(dict_measures.keys()):
554-
for idxd, keyd in enumerate(dict_measures[key].keys()):
553+
for key, value in dict_measures:
554+
for idxd, keyd in enumerate(value.keys()):
555555
if idxd == 0:
556556
nparraykeys = np.array(keyd)
557-
nparrayvalues = np.array(dict_measures[key][keyd])
557+
nparrayvalues = np.array(value[keyd])
558558
else:
559559
nparraykeys = np.append(nparraykeys, np.array(keyd))
560-
values = np.array(dict_measures[key][keyd])
560+
values = np.array(value[keyd])
561561
nparrayvalues = np.append(nparrayvalues, values)
562562
nparray = np.vstack((nparraykeys, nparrayvalues))
563563
out_file = op.abspath(self._gen_outfilename(key, "mat"))

nipype/interfaces/cmtk/parcellation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ def create_wm_mask(subject_id, subjects_dir, fs_dir, parcellation_name):
598598
roid = np.asanyarray(roi.dataobj)
599599
assert roid.shape[0] == wmmask.shape[0]
600600
pg = nx.read_graphml(pgpath)
601-
for brk, brv in pg.nodes(data=True):
601+
for brk, brv in pg.nodes(data=True): # noqa: B007
602602
if brv["dn_region"] == "cortical":
603603
iflogger.info(
604604
"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
@@ -208,7 +208,7 @@ def _run_interface(self, runtime):
208208
dirs = np.hstack((dirs, fd[msk > 0]))
209209

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

344-
for i in range(nb0s):
344+
for _ in range(nb0s):
345345
bvals = bvals.tolist()
346346
bvals.insert(0, 0)
347347

nipype/interfaces/fsl/model.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,8 @@ def _create_ev_files(
198198
# generate sections for conditions and other nuisance
199199
# regressors
200200
num_evs = [0, 0]
201-
for field in ["cond", "regress"]:
202-
for i, cond in enumerate(runinfo[field]):
201+
for field in ("cond", "regress"):
202+
for cond in runinfo[field]:
203203
name = cond["name"]
204204
evname.append(name)
205205
evfname = os.path.join(
@@ -278,9 +278,7 @@ def _create_ev_files(
278278
contrastmask_element = load_template("feat_contrastmask_element.tcl")
279279
# add t/f contrast info
280280
ev_txt += contrast_header.substitute()
281-
con_names = []
282-
for j, con in enumerate(contrasts):
283-
con_names.append(con[0])
281+
con_names = [con[0] for con in contrasts]
284282
con_map = {}
285283
ftest_idx = []
286284
ttest_idx = []
@@ -364,7 +362,7 @@ def _run_interface(self, runtime):
364362
n_tcon = 0
365363
n_fcon = 0
366364
if isdefined(self.inputs.contrasts):
367-
for i, c in enumerate(self.inputs.contrasts):
365+
for c in self.inputs.contrasts:
368366
if c[1] == "T":
369367
n_tcon += 1
370368
elif c[1] == "F":
@@ -421,7 +419,7 @@ def _list_outputs(self):
421419
outputs["ev_files"].insert(runno, [])
422420
evname = []
423421
for field in ["cond", "regress"]:
424-
for i, cond in enumerate(runinfo[field]):
422+
for cond in runinfo[field]:
425423
name = cond["name"]
426424
evname.append(name)
427425
evfname = os.path.join(
@@ -1388,8 +1386,7 @@ def _run_interface(self, runtime):
13881386
"",
13891387
"/Matrix",
13901388
]
1391-
for i in range(self.inputs.num_copes):
1392-
mat_txt += ["1"]
1389+
mat_txt.extend("1" for _ in range(self.inputs.num_copes))
13931390
mat_txt = "\n".join(mat_txt)
13941391

13951392
con_txt = [
@@ -1411,16 +1408,15 @@ def _run_interface(self, runtime):
14111408
"",
14121409
"/Matrix",
14131410
]
1414-
for i in range(self.inputs.num_copes):
1415-
grp_txt += ["1"]
1411+
grp_txt.extend("1" for _ in range(self.inputs.num_copes))
14161412
grp_txt = "\n".join(grp_txt)
14171413

14181414
txt = {"design.mat": mat_txt, "design.con": con_txt, "design.grp": grp_txt}
14191415

14201416
# write design files
1421-
for i, name in enumerate(["design.mat", "design.con", "design.grp"]):
1417+
for name, name_txt in txt.items():
14221418
with open(os.path.join(cwd, name), "w") as f:
1423-
f.write(txt[name])
1419+
f.write(name_txt)
14241420

14251421
return runtime
14261422

@@ -1559,7 +1555,7 @@ def _run_interface(self, runtime):
15591555
"",
15601556
"/Matrix",
15611557
]
1562-
for conidx, con in enumerate(self.inputs.contrasts):
1558+
for con in self.inputs.contrasts:
15631559
if con[1] == "F":
15641560
convals = np.zeros((ntcons, 1))
15651561
for tcon in con[2]:

nipype/interfaces/fsl/preprocess.py

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

nipype/interfaces/io.py

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

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

nipype/interfaces/mrtrix/convert.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,10 @@ def points_per_track(offset):
100100
] # Converts numpy array to list, removes the last value
101101
for idx, value in enumerate(nonfinite_list):
102102
if idx == 0:
103-
track_points.append(nonfinite_list[idx])
103+
track_points.append(value)
104104
else:
105-
track_points.append(nonfinite_list[idx] - nonfinite_list[idx - 1] - 1)
105+
track_points.append(value - last_value - 1)
106+
last_value = value
106107
return track_points, nonfinite_list
107108

108109
def track_gen(track_points):

0 commit comments

Comments
 (0)