def run_step_sweep(self, param_sweep_widget: ParamSweepWidget,
                       ui_inputs: List[List[str]]) -> None:
        """
        Run a step in the active workflow as a sweep
        i: index of step to run in the active workflow
        parameter_inputs: Each dictionary has the same shape as a WorkflowStep.parameter_values
        dictionary, but with the parameter values obtained from the UI instead of default values.
        ui_inputs List[List[str]]: inputs for the sweep values from the sweep UI
        type str: type of sweep, either "normal" or "grid"
        """
        self.param_sweep_widget = param_sweep_widget
        i: int = param_sweep_widget.step_number
        parameter_inputs: Dict[str, Any] = param_sweep_widget.param_set

        if not self._run_lock:
            if parameter_inputs:
                parameter_inputs_2: Dict[str, Any] = self._parse_inputs(
                    copy.deepcopy(parameter_inputs), ui_inputs)
                self._worker: GeneratorWorker = create_worker(
                    self._run_step_sweep_grid, i, parameter_inputs,
                    parameter_inputs_2)
                self._worker.yielded.connect(self._on_step_processed)
                self._worker.started.connect(self._on_sweep_started)
                self._worker.finished.connect(self.on_sweep_finished)
                self._sweep_step = 0
                self._worker.start()
            else:
                self._worker: GeneratorWorker = create_worker(
                    self._run_step_async, i, parameter_inputs)
                self._worker.yielded.connect(self._on_step_processed)
                self._worker.started.connect(self._on_sweep_started)
                self._worker.finished.connect(self.on_sweep_finished)
                self._worker.start()
 def run_batch(self):
     if not self._run_lock:
         self._worker: GeneratorWorker = create_worker(
             self._run_batch_async)
         self._worker.yielded.connect(self._on_step_processed)
         self._worker.started.connect(self._on_run_batch_started)
         self._worker.aborted.connect(self._on_run_batch_aborted)
         self._worker.finished.connect(self._on_run_batch_finished)
         self._worker.start()
 def run_next_step(self, parameter_inputs: Dict[str, Any]) -> None:
     """
     Run the next step in the active workflow
     parameter_inputs: Each dictionary has the same shape as a WorkflowStep.parameter_values
     dictionary, but with the parameter values obtained from the UI instead of default values.
     """
     if not self._run_lock:
         self._worker: GeneratorWorker = create_worker(
             self._run_next_step_async, parameter_inputs)
         self._worker.yielded.connect(self._on_step_processed)
         self._worker.started.connect(self._on_run_all_started)
         self._worker.finished.connect(self._on_run_all_finished)
         self._worker.start()
Ejemplo n.º 4
0
    def _submit(
        self, func: Callable, *args, _wait=True, **kwargs
    ) -> WorkerBase:
        new_worker = create_worker(func, *args, _start_thread=False, **kwargs)
        new_worker.finished.connect(self._start_next_worker)

        if self.worker and self.worker.is_running:
            self._next_worker = new_worker
            if not _wait:
                self.worker.quit()
        else:
            self.worker = new_worker
            self.worker.start()
        return new_worker
    def run_step(self, i: int, parameter_inputs: Dict[str, Any]) -> None:
        """
        Run a step in the active workflow
        i int: index of step to run in the active workflow
        parameter_inputs: Each dictionary has the same shape as a WorkflowStep.parameter_values
        dictionary, but with the parameter values obtained from the UI instead of default values.
        """
        if not self._run_lock:
            selected_layers: List[Image] = self.viewer.get_active_layer()
            cont: bool = True  # continue execution

            step_to_run: WorkflowStep = self.model.active_workflow.workflow_definition.steps[
                i]
            if len(step_to_run.parent) != len(selected_layers):
                # too many or too few images selected as the input layer,
                # abort run attempt and show warning
                self.warn_box(
                    f"{step_to_run.name} requires {len(step_to_run.parent)} input images, "
                    f"but you have selected {len(selected_layers)} images."
                    f"\nPlease select {len(step_to_run.parent)} images by ctrl+clicking.",
                    "Wrong number of input images selected",
                    one_option=True,
                )
                cont = False  # continue if user is running steps in order, and correct input steps are selected
            else:
                # check to see if correct layers were selected to run this segmentation in order
                # some steps require multiple layers.
                for selected_layer in selected_layers:

                    if selected_layer.name[:1].isdigit() and int(
                            selected_layer.name[:1]) not in step_to_run.parent:
                        # check to see if the correct image input layer is selected.
                        if i == 0:
                            response = self.warn_box(
                                f"You currently have the layer {selected_layer.name} selected in napari which will "
                                f"be used as the input layer. You will run this segmentation"
                                f" out of order. \nTo run the segmentation in order, "
                                f"please select the starting image (step 0) as the "
                                f"input layer for this step. "
                                f"\n Would you still like to continue?",
                                "Run segmentation out of order",
                            )
                        else:
                            step_required_name = self.model.active_workflow.workflow_definition.steps[
                                step_to_run.parent[0] - 1].name
                            response = self.warn_box(
                                f"You currently have the layer {selected_layer.name} selected in napari which will "
                                f"be used as the input layer. You will run this segmentation"
                                f" out of order. To run the segmentation in order, "
                                f"please select a layer that is the output of "
                                f"{i}. {step_required_name}."
                                f"\n Would you like to continue?",
                                "Run segmentation out of order",
                            )
                        cont = response == 1024
                    elif not selected_layer.name[:1].isdigit():
                        if i == 0:
                            response = self.warn_box(
                                f"You currently have the layer {selected_layer.name} selected in napari which will "
                                f"be used as the input layer. You will run this segmentation"
                                f" out of order. \nTo run the segmentation in order, "
                                f"please select the starting image (step 0) as the "
                                f"input layer for this step. "
                                f"\n Would you still like to continue?",
                                "Run segmentation out of order",
                            )
                        else:
                            step_required_name = self.model.active_workflow.workflow_definition.steps[
                                step_to_run.parent[0] - 1].name
                            response = self.warn_box(
                                f"You currently have the layer {selected_layer.name} selected in napari which will "
                                f"be used as the input layer. You will run this segmentation"
                                f" out of order. To run the segmentation in order, "
                                f"please select a layer that is the output of "
                                f"{i}. {step_required_name}."
                                f"\n Would you like to continue?",
                                "Run segmentation out of order",
                            )
                        cont = response == 1024

            if cont:
                self._worker: GeneratorWorker = create_worker(
                    self._run_step_async, i, parameter_inputs)
                self._worker.yielded.connect(self._on_step_processed)
                self._worker.started.connect(self._on_run_all_started)
                self._worker.finished.connect(self._on_run_step_finished)
                self._worker.start()