Skip to content

Commit

Permalink
STYLE: Fix unused loop control variable warning
Browse files Browse the repository at this point in the history
Fix unused loop control variable warning: show how to specify multiple
output filenames for a combined workflow, and provide them to the
corresponding sub-workflows.

Fixes:
```
doc/examples/combined_workflow_creation.py:68:22:
 B007 Loop control variable `out_file` not used within loop body
```

raised for example in:
https://github.com/dipy/dipy/actions/runs/9131684633/job/25111443178#step:4:116
  • Loading branch information
jhlegarreta committed May 18, 2024
1 parent 37995db commit 05de2b6
Showing 1 changed file with 34 additions and 6 deletions.
40 changes: 34 additions & 6 deletions doc/examples/combined_workflow_creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
file is usually located in the ``dipy/workflows`` directory.
"""

import os

from dipy.workflows.combined_workflow import CombinedWorkflow

###############################################################################
Expand Down Expand Up @@ -37,7 +39,14 @@ def _get_sub_flows(self):
sub workflows parameters available in commandline.
"""

def run(self, input_files, out_dir="", out_file="processed.nii.gz"):
def run(
self,
input_files,
out_dir="",
out_denoised="processed.nii.gz",
out_mask="brain_mask.nii.gz",
out_masked="dwi_masked.nii.gz",
):
"""
Parameters
----------
Expand All @@ -48,8 +57,14 @@ def run(self, input_files, out_dir="", out_file="processed.nii.gz"):
out_dir : string, optional
Where the resulting file will be saved. (default '')
out_file : string, optional
Name of the result file to be saved. (default 'processed.nii.gz')
out_denoised : string, optional
Name of the denoised file to be saved.
out_mask : string, optional
Name of the Otsu mask file to be saved.
out_masked : string, optional
Name of the Otsu masked file to be saved.
"""

"""
Expand All @@ -65,13 +80,26 @@ def run(self, input_files, out_dir="", out_file="processed.nii.gz"):

io_it = self.get_io_iterator()

for in_file, out_file in io_it:
for fnames in io_it:
in_fname = fnames[0]
_out_denoised = os.path.basename(fnames[1])
_out_mask = os.path.basename(fnames[2])
_out_masked = os.path.basename(fnames[3])

nl_flow = NLMeansFlow()
self.run_sub_flow(nl_flow, in_file, out_dir=out_dir)
self.run_sub_flow(
nl_flow, in_fname, out_dir=out_dir, out_denoised=_out_denoised
)
denoised = nl_flow.last_generated_outputs["out_denoised"]

me_flow = MedianOtsuFlow()
self.run_sub_flow(me_flow, denoised, out_dir=out_dir)
self.run_sub_flow(
me_flow,
denoised,
out_dir=out_dir,
out_mask=_out_mask,
out_masked=_out_masked,
)


###############################################################################
Expand Down

0 comments on commit 05de2b6

Please sign in to comment.