From 05de2b66d714e3fe13f7e77c624b310b1ef932f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=20Haitz=20Legarreta=20Gorro=C3=B1o?= Date: Sat, 18 May 2024 11:24:49 -0400 Subject: [PATCH] STYLE: Fix unused loop control variable warning 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 --- doc/examples/combined_workflow_creation.py | 40 ++++++++++++++++++---- 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/doc/examples/combined_workflow_creation.py b/doc/examples/combined_workflow_creation.py index ff9da26fc1..63a31030ec 100644 --- a/doc/examples/combined_workflow_creation.py +++ b/doc/examples/combined_workflow_creation.py @@ -10,6 +10,8 @@ file is usually located in the ``dipy/workflows`` directory. """ +import os + from dipy.workflows.combined_workflow import CombinedWorkflow ############################################################################### @@ -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 ---------- @@ -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. """ """ @@ -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, + ) ###############################################################################