class CarvingWorkflow(Workflow): workflowName = "Carving" @property def applets(self): return self._applets @property def imageNameListSlot(self): return self.dataSelectionApplet.topLevelOperator.ImageName def __init__(self, hintoverlayFile=None, pmapoverlayFile=None, *args, **kwargs): if hintoverlayFile is not None: assert isinstance(hintoverlayFile, str), "hintoverlayFile should be a string, not '%s'" % type( hintoverlayFile ) if pmapoverlayFile is not None: assert isinstance(pmapoverlayFile, str), "pmapoverlayFile should be a string, not '%s'" % type( pmapoverlayFile ) graph = Graph() super(CarvingWorkflow, self).__init__(graph=graph, *args, **kwargs) ## Create applets self.projectMetadataApplet = ProjectMetadataApplet() self.dataSelectionApplet = DataSelectionApplet( self, "Input Data", "Input Data", supportIlastik05Import=True, batchDataGui=False ) self.carvingApplet = CarvingApplet( workflow=self, projectFileGroupName="carving", hintOverlayFile=hintoverlayFile, pmapOverlayFile=pmapoverlayFile, ) self.preprocessingApplet = PreprocessingApplet( workflow=self, title="Preprocessing", projectFileGroupName="carving" ) # self.carvingApplet.topLevelOperator.MST.connect(self.preprocessingApplet.topLevelOperator.PreprocessedData) # Expose to shell self._applets = [] self._applets.append(self.projectMetadataApplet) self._applets.append(self.dataSelectionApplet) self._applets.append(self.preprocessingApplet) self._applets.append(self.carvingApplet) def connectLane(self, laneIndex): ## Access applet operators opData = self.dataSelectionApplet.topLevelOperator.getLane(laneIndex) opPreprocessing = self.preprocessingApplet.topLevelOperator.getLane(laneIndex) opCarvingTopLevel = self.carvingApplet.topLevelOperator.getLane(laneIndex) op5 = Op5ifyer(parent=self) op5.order.setValue("txyzc") op5.input.connect(opData.Image) ## Connect operators opPreprocessing.RawData.connect(op5.output) opCarvingTopLevel.RawData.connect(op5.output) opCarvingTopLevel.opCarving.MST.connect(opPreprocessing.PreprocessedData) opCarvingTopLevel.opCarving.opLabeling.LabelsAllowedFlag.connect(opData.AllowLabels) opCarvingTopLevel.opCarving.UncertaintyType.setValue("none") self.preprocessingApplet.enableDownstream(False)
class SplitBodyCarvingWorkflow(Workflow): workflowName = "Split Body Tool Workflow" defaultAppletIndex = 1 # show DataSelection by default DATA_ROLE_RAW = 0 DATA_ROLE_PIXEL_PROB = 1 DATA_ROLE_RAVELER_LABELS = 2 @property def applets(self): return self._applets @property def imageNameListSlot(self): return self.dataSelectionApplet.topLevelOperator.ImageName def __init__(self, shell, headless, workflow_cmdline_args, project_creation_args, hintoverlayFile=None, pmapoverlayFile=None, *args, **kwargs): graph = Graph() super(SplitBodyCarvingWorkflow, self).__init__(shell, headless, workflow_cmdline_args, project_creation_args, *args, graph=graph, **kwargs) ## Create applets self.projectMetadataApplet = ProjectMetadataApplet() self.dataSelectionApplet = DataSelectionApplet(self, "Input Data", "Input Data", supportIlastik05Import=True, batchDataGui=False) opDataSelection = self.dataSelectionApplet.topLevelOperator opDataSelection.DatasetRoles.setValue( ['Raw Data', 'Pixel Probabilities', 'Raveler Labels'] ) self.preprocessingApplet = PreprocessingApplet(workflow=self, title = "Preprocessing", projectFileGroupName="preprocessing") self.splitBodyCarvingApplet = SplitBodyCarvingApplet(workflow=self, projectFileGroupName="carving") self.splitBodyPostprocessingApplet = SplitBodyPostprocessingApplet(workflow=self) self.splitBodySupervoxelExportApplet = SplitBodySupervoxelExportApplet(workflow=self) # Expose to shell self._applets = [] self._applets.append(self.projectMetadataApplet) self._applets.append(self.dataSelectionApplet) self._applets.append(self.preprocessingApplet) self._applets.append(self.splitBodyCarvingApplet) self._applets.append(self.splitBodyPostprocessingApplet) self._applets.append(self.splitBodySupervoxelExportApplet) self._split_tool_params = None if workflow_cmdline_args: arg_parser = argparse.ArgumentParser(description="Specify parameters for the split-body carving workflow") arg_parser.add_argument('--split_tool_param_file', required=False) parsed_args, unused_args = arg_parser.parse_known_args(workflow_cmdline_args) if unused_args: logger.warn("Unused command-line args: {}".format( unused_args )) if parsed_args.split_tool_param_file is None: logger.warn("Missing cmd-line arg: --split_tool_param_file") else: logger.debug("Parsing split tool parameters: {}".format( parsed_args.split_tool_param_file )) json_parser = JsonConfigParser( SplitToolParamsSchema ) self._split_tool_params = json_parser.parseConfigFile( parsed_args.split_tool_param_file ) def onProjectLoaded(self, projectManager): """ Overridden from Workflow base class. Called by the Project Manager. - Use the parameter json file provided on the command line to populate the project's input data settings. - Also set the annotation file location. - Run the preprocessing step. - Save the project. """ if self._split_tool_params is None: return # -- Data Selection opDataSelection = self.dataSelectionApplet.topLevelOperator # If there is already data in this project, don't touch it. if len(opDataSelection.DatasetGroup) > 0: logger.warn("Not changing project data, because your project appears to have data already.") else: opDataSelection.DatasetGroup.resize(1) for role, data_params in [ ( self.DATA_ROLE_RAW, self._split_tool_params.raw_data_info ), ( self.DATA_ROLE_PIXEL_PROB, self._split_tool_params.pixel_probabilities_info ), ( self.DATA_ROLE_RAVELER_LABELS, self._split_tool_params.raveler_labels_info ) ]: logger.debug( "Configuring dataset for role {}".format( role ) ) logger.debug( "Params: {}".format(data_params) ) datasetInfo = DatasetInfo() datasetInfo.updateFromJson( data_params ) # Check for globstring, which means we need to import the stack first. if '*' in datasetInfo.filePath: totalProgress = [-100] def handleStackImportProgress( progress ): if progress / 10 != totalProgress[0] / 10: totalProgress[0] = progress logger.info( "Importing stack: {}%".format( totalProgress[0] ) ) serializer = self.dataSelectionApplet.dataSerializers[0] serializer.progressSignal.connect( handleStackImportProgress ) serializer.importStackAsLocalDataset( datasetInfo ) opDataSelection.DatasetGroup[0][ role ].setValue( datasetInfo ) # -- Split settings (annotation file) opSplitBodyCarving = self.splitBodyCarvingApplet.topLevelOperator.getLane(0) opSplitBodyCarving.AnnotationFilepath.setValue( self._split_tool_params.raveler_bookmarks_file ) # -- Preprocessing settings opPreprocessing = self.preprocessingApplet.topLevelOperator.getLane(0) opPreprocessing.Sigma.setValue(1.0) opPreprocessing.Filter.setValue( OpFilter.RAW ) # Run preprocessing def showProgress( progress ): logger.info( "Preprocessing Progress: {}%".format( progress ) ) self.preprocessingApplet.progressSignal.connect( showProgress ) opPreprocessing.PreprocessedData[:].wait() logger.info("Preprocessing Complete") logger.info("Saving project...") projectManager.saveProject() # Special FlyEM supervoxelized body export: if self._split_tool_params.supervoxelized_bodies_export_path is not None: opSupervoxelExport = self.splitBodySupervoxelExportApplet.topLevelOperator.getLane(0) def showExportProgress( progress ): logger.info( "Supervoxelized Body Export Progress: {}%".format( progress ) ) req = opSupervoxelExport.exportFinalSupervoxels( self._split_tool_params.supervoxelized_bodies_export_path, 'zyx', progressCallback=showExportProgress ) req.wait() logger.info("FINISHED") def connectLane(self, laneIndex): ## Access applet operators opData = self.dataSelectionApplet.topLevelOperator.getLane(laneIndex) opPreprocessing = self.preprocessingApplet.topLevelOperator.getLane(laneIndex) opSplitBodyCarving = self.splitBodyCarvingApplet.topLevelOperator.getLane(laneIndex) opPostprocessing = self.splitBodyPostprocessingApplet.topLevelOperator.getLane(laneIndex) op5Raw = OpReorderAxes(parent=self) op5Raw.AxisOrder.setValue("txyzc") op5Raw.Input.connect(opData.ImageGroup[self.DATA_ROLE_RAW]) op5PixelProb = OpReorderAxes(parent=self) op5PixelProb.AxisOrder.setValue("txyzc") op5PixelProb.Input.connect(opData.ImageGroup[self.DATA_ROLE_PIXEL_PROB]) op5RavelerLabels = OpReorderAxes(parent=self) op5RavelerLabels.AxisOrder.setValue("txyzc") op5RavelerLabels.Input.connect(opData.ImageGroup[self.DATA_ROLE_RAVELER_LABELS]) # We assume the membrane boundaries are found in the first prediction class (channel 0) opSingleChannelSelector = OpSingleChannelSelector(parent=self) opSingleChannelSelector.Input.connect( op5PixelProb.Output ) opSingleChannelSelector.Index.setValue(0) opPreprocessing.InputData.connect( opSingleChannelSelector.Output ) opPreprocessing.RawData.connect( op5Raw.Output ) opSplitBodyCarving.RawData.connect( op5Raw.Output ) opSplitBodyCarving.InputData.connect( opSingleChannelSelector.Output ) opSplitBodyCarving.RavelerLabels.connect( op5RavelerLabels.Output ) opSplitBodyCarving.FilteredInputData.connect( opPreprocessing.FilteredImage ) # Special input-input connection: WriteSeeds metadata must mirror the input data opSplitBodyCarving.WriteSeeds.connect( opSplitBodyCarving.InputData ) opSplitBodyCarving.MST.connect(opPreprocessing.PreprocessedData) opSplitBodyCarving.UncertaintyType.setValue("none") opPostprocessing.RawData.connect( opSplitBodyCarving.RawData ) opPostprocessing.InputData.connect( opSplitBodyCarving.InputData ) opPostprocessing.RavelerLabels.connect( opSplitBodyCarving.RavelerLabels ) opPostprocessing.MST.connect(opSplitBodyCarving.MstOut) # Split-body carving -> Postprocessing opPostprocessing.EditedRavelerBodyList.connect(opSplitBodyCarving.EditedRavelerBodyList) opPostprocessing.NavigationCoordinates.connect(opSplitBodyCarving.NavigationCoordinates) if not self._headless: self.preprocessingApplet.enableDownstream(False) # Supervoxel export opSupervoxelExport = self.splitBodySupervoxelExportApplet.topLevelOperator.getLane(laneIndex) opSupervoxelExport.DatasetInfos.connect( opData.DatasetGroup ) opSupervoxelExport.WorkingDirectory.connect( opData.WorkingDirectory ) opSupervoxelExport.RawData.connect( opPreprocessing.RawData ) opSupervoxelExport.InputData.connect( opPreprocessing.InputData ) opSupervoxelExport.Supervoxels.connect( opPreprocessing.WatershedImage ) opSupervoxelExport.RavelerLabels.connect( opSplitBodyCarving.RavelerLabels ) opSupervoxelExport.AnnotationBodyIds.connect( opSplitBodyCarving.AnnotationBodyIds )
class CarvingFromPixelPredictionsWorkflow(Workflow): workflowName = "Carving From Pixel Predictions" defaultAppletIndex = 1 # show DataSelection by default @property def applets(self): return self._applets @property def imageNameListSlot(self): return self.dataSelectionApplet.topLevelOperator.ImageName def __init__(self, headless, workflow_cmdline_args, hintoverlayFile=None, pmapoverlayFile=None, *args, **kwargs): if workflow_cmdline_args: assert False, "Not using workflow cmdline args yet." if hintoverlayFile is not None: assert isinstance(hintoverlayFile, str), "hintoverlayFile should be a string, not '%s'" % type(hintoverlayFile) if pmapoverlayFile is not None: assert isinstance(pmapoverlayFile, str), "pmapoverlayFile should be a string, not '%s'" % type(pmapoverlayFile) graph = Graph() super(CarvingFromPixelPredictionsWorkflow, self).__init__(headless, *args, graph=graph, **kwargs) ## Create applets self.projectMetadataApplet = ProjectMetadataApplet() self.dataSelectionApplet = DataSelectionApplet(self, "Input Data", "Input Data", supportIlastik05Import=True, batchDataGui=False) opDataSelection = self.dataSelectionApplet.topLevelOperator opDataSelection.DatasetRoles.setValue( ['Raw Data'] ) self.featureSelectionApplet = FeatureSelectionApplet(self, "Feature Selection", "FeatureSelections") self.pixelClassificationApplet = PixelClassificationApplet(self, "PixelClassification") self.carvingApplet = CarvingApplet(workflow=self, projectFileGroupName="carving", hintOverlayFile=hintoverlayFile, pmapOverlayFile=pmapoverlayFile) self.preprocessingApplet = PreprocessingApplet(workflow=self, title = "Preprocessing", projectFileGroupName="carving") #self.carvingApplet.topLevelOperator.MST.connect(self.preprocessingApplet.topLevelOperator.PreprocessedData) # Expose to shell self._applets = [] self._applets.append(self.projectMetadataApplet) self._applets.append(self.dataSelectionApplet) self._applets.append(self.featureSelectionApplet) self._applets.append(self.pixelClassificationApplet) self._applets.append(self.preprocessingApplet) self._applets.append(self.carvingApplet) def connectLane(self, laneIndex): ## Access applet operators opData = self.dataSelectionApplet.topLevelOperator.getLane(laneIndex) opFeatureSelection = self.featureSelectionApplet.topLevelOperator.getLane(laneIndex) opPixelClassification = self.pixelClassificationApplet.topLevelOperator.getLane(laneIndex) opPreprocessing = self.preprocessingApplet.topLevelOperator.getLane(laneIndex) opCarvingLane = self.carvingApplet.topLevelOperator.getLane(laneIndex) op5 = Op5ifyer(parent=self) op5.order.setValue("txyzc") op5.input.connect(opData.Image) ## Connect operators opFeatureSelection.InputImage.connect( op5.output ) opPixelClassification.InputImages.connect( op5.output ) opPixelClassification.FeatureImages.connect( opFeatureSelection.OutputImage ) opPixelClassification.CachedFeatureImages.connect( opFeatureSelection.CachedOutputImage ) opPixelClassification.LabelsAllowedFlags.connect( opData.AllowLabels ) # We assume the membrane boundaries are found in the first prediction class (channel 0) opSingleChannelSelector = OpSingleChannelSelector(parent=self) opSingleChannelSelector.Input.connect( opPixelClassification.PredictionProbabilities ) opSingleChannelSelector.Index.setValue(0) opPreprocessing.InputData.connect( opSingleChannelSelector.Output ) opPreprocessing.RawData.connect( op5.output ) opCarvingLane.RawData.connect( op5.output ) opCarvingLane.InputData.connect( opSingleChannelSelector.Output ) opCarvingLane.FilteredInputData.connect( opPreprocessing.FilteredImage ) # Special input-input connection: WriteSeeds metadata must mirror the input data opCarvingLane.WriteSeeds.connect( opCarvingLane.InputData ) opCarvingLane.MST.connect(opPreprocessing.PreprocessedData) #opCarvingLane.opLabeling.LabelsAllowedFlag.connect( opData.AllowLabels ) opCarvingLane.UncertaintyType.setValue("none") self.preprocessingApplet.enableDownstream(False)
class CarvingWorkflow(Workflow): workflowName = "Carving" defaultAppletIndex = 1 # show DataSelection by default @property def applets(self): return self._applets @property def imageNameListSlot(self): return self.dataSelectionApplet.topLevelOperator.ImageName def __init__(self, shell, headless, workflow_cmdline_args, project_creation_args, hintoverlayFile=None, pmapoverlayFile=None, *args, **kwargs): if hintoverlayFile is not None: assert isinstance(hintoverlayFile, str), "hintoverlayFile should be a string, not '%s'" % type(hintoverlayFile) if pmapoverlayFile is not None: assert isinstance(pmapoverlayFile, str), "pmapoverlayFile should be a string, not '%s'" % type(pmapoverlayFile) graph = Graph() super(CarvingWorkflow, self).__init__(shell, headless, workflow_cmdline_args, project_creation_args, graph=graph, *args, **kwargs) self.workflow_cmdline_args = workflow_cmdline_args data_instructions = "Select your input data using the 'Raw Data' tab shown on the right" ## Create applets self.projectMetadataApplet = ProjectMetadataApplet() self.dataSelectionApplet = DataSelectionApplet( self, "Input Data", "Input Data", supportIlastik05Import=True, batchDataGui=False, instructionText=data_instructions, max_lanes=1 ) opDataSelection = self.dataSelectionApplet.topLevelOperator opDataSelection.DatasetRoles.setValue( DATA_ROLES ) self.preprocessingApplet = PreprocessingApplet(workflow=self, title = "Preprocessing", projectFileGroupName="preprocessing") self.carvingApplet = CarvingApplet(workflow=self, projectFileGroupName="carving", hintOverlayFile=hintoverlayFile, pmapOverlayFile=pmapoverlayFile) #self.carvingApplet.topLevelOperator.MST.connect(self.preprocessingApplet.topLevelOperator.PreprocessedData) # Expose to shell self._applets = [] self._applets.append(self.projectMetadataApplet) self._applets.append(self.dataSelectionApplet) self._applets.append(self.preprocessingApplet) self._applets.append(self.carvingApplet) def connectLane(self, laneIndex): ## Access applet operators opData = self.dataSelectionApplet.topLevelOperator.getLane(laneIndex) opPreprocessing = self.preprocessingApplet.topLevelOperator.getLane(laneIndex) opCarvingLane = self.carvingApplet.topLevelOperator.getLane(laneIndex) opCarvingLane.connectToPreprocessingApplet(self.preprocessingApplet) op5 = OpReorderAxes(parent=self) op5.AxisOrder.setValue("txyzc") op5.Input.connect(opData.Image) ## Connect operators opPreprocessing.InputData.connect(op5.Output) #opCarvingTopLevel.RawData.connect(op5.output) opCarvingLane.InputData.connect(op5.Output) opCarvingLane.FilteredInputData.connect(opPreprocessing.FilteredImage) opCarvingLane.MST.connect(opPreprocessing.PreprocessedData) opCarvingLane.UncertaintyType.setValue("none") # Special input-input connection: WriteSeeds metadata must mirror the input data opCarvingLane.WriteSeeds.connect( opCarvingLane.InputData ) self.preprocessingApplet.enableDownstream(False) def handleAppletStateUpdateRequested(self): # If no data, nothing else is ready. opDataSelection = self.dataSelectionApplet.topLevelOperator input_ready = len(opDataSelection.ImageGroup) > 0 # If preprocessing isn't configured yet, don't allow carving preprocessed_data_ready = input_ready and self.preprocessingApplet._enabledDS # Enable each applet as appropriate self._shell.setAppletEnabled(self.preprocessingApplet, input_ready) self._shell.setAppletEnabled(self.carvingApplet, preprocessed_data_ready) def onProjectLoaded(self, projectManager): """ Overridden from Workflow base class. Called by the Project Manager. If the user provided command-line arguments, apply them to the workflow operators. Currently, we support command-line configuration of: - DataSelection - Preprocessing, in which case preprocessing is immediately executed """ # If input data files were provided on the command line, configure the DataSelection applet now. # (Otherwise, we assume the project already had a dataset selected.) input_data_args, unused_args = DataSelectionApplet.parse_known_cmdline_args(self.workflow_cmdline_args, DATA_ROLES) if input_data_args.raw_data: self.dataSelectionApplet.configure_operator_with_parsed_args(input_data_args) # # Parse the remaining cmd-line arguments # filter_indexes = { 'bright-lines' : OpFilter.HESSIAN_BRIGHT, 'dark-lines' : OpFilter.HESSIAN_DARK, 'step-edges' : OpFilter.STEP_EDGES, 'original' : OpFilter.RAW, 'inverted' : OpFilter.RAW_INVERTED } parser = argparse.ArgumentParser() parser.add_argument('--run-preprocessing', action='store_true') parser.add_argument('--preprocessing-sigma', type=float, required=False) parser.add_argument('--preprocessing-filter', required=False, type=str.lower, choices=filter_indexes.keys()) parsed_args, unused_args = parser.parse_known_args(unused_args) if unused_args: logger.warn("Did not use the following command-line arguments: {}".format(unused_args)) # Execute pre-processing. if parsed_args.run_preprocessing: if len(self.preprocessingApplet.topLevelOperator) != 1: raise RuntimeError("Can't run preprocessing on a project with no images.") opPreprocessing = self.preprocessingApplet.topLevelOperator.getLane(0) # Carving has only one 'lane' # If user provided parameters, override the defaults. if parsed_args.preprocessing_sigma is not None: opPreprocessing.Sigma.setValue(parsed_args.preprocessing_sigma) if parsed_args.preprocessing_filter: filter_index = filter_indexes[parsed_args.preprocessing_filter] opPreprocessing.Filter.setValue(filter_index) logger.info("Running Preprocessing...") opPreprocessing.PreprocessedData[:].wait() logger.info("FINISHED Preprocessing...") logger.info("Saving project...") self._shell.projectManager.saveProject() logger.info("Done saving.")
class CarvingWorkflow(Workflow): workflowName = "Carving" defaultAppletIndex = 1 # show DataSelection by default @property def applets(self): return self._applets @property def imageNameListSlot(self): return self.dataSelectionApplet.topLevelOperator.ImageName def __init__(self, shell, headless, workflow_cmdline_args, hintoverlayFile=None, pmapoverlayFile=None, *args, **kwargs): if hintoverlayFile is not None: assert isinstance(hintoverlayFile, str), "hintoverlayFile should be a string, not '%s'" % type(hintoverlayFile) if pmapoverlayFile is not None: assert isinstance(pmapoverlayFile, str), "pmapoverlayFile should be a string, not '%s'" % type(pmapoverlayFile) graph = Graph() super(CarvingWorkflow, self).__init__(shell, headless, graph=graph, *args, **kwargs) data_instructions = "Select your input data using the 'Raw Data' tab shown on the right" ## Create applets self.projectMetadataApplet = ProjectMetadataApplet() self.dataSelectionApplet = DataSelectionApplet( self, "Input Data", "Input Data", supportIlastik05Import=True, batchDataGui=False, instructionText=data_instructions, max_lanes=1 ) opDataSelection = self.dataSelectionApplet.topLevelOperator opDataSelection.DatasetRoles.setValue( ['Raw Data'] ) self.preprocessingApplet = PreprocessingApplet(workflow=self, title = "Preprocessing", projectFileGroupName="preprocessing") self.carvingApplet = CarvingApplet(workflow=self, projectFileGroupName="carving", hintOverlayFile=hintoverlayFile, pmapOverlayFile=pmapoverlayFile) #self.carvingApplet.topLevelOperator.MST.connect(self.preprocessingApplet.topLevelOperator.PreprocessedData) # Expose to shell self._applets = [] self._applets.append(self.projectMetadataApplet) self._applets.append(self.dataSelectionApplet) self._applets.append(self.preprocessingApplet) self._applets.append(self.carvingApplet) def connectLane(self, laneIndex): ## Access applet operators opData = self.dataSelectionApplet.topLevelOperator.getLane(laneIndex) opPreprocessing = self.preprocessingApplet.topLevelOperator.getLane(laneIndex) opCarvingLane = self.carvingApplet.topLevelOperator.getLane(laneIndex) opCarvingLane.connectToPreprocessingApplet(self.preprocessingApplet) op5 = Op5ifyer(parent=self) op5.order.setValue("txyzc") op5.input.connect(opData.Image) ## Connect operators opPreprocessing.InputData.connect(op5.output) #opCarvingTopLevel.RawData.connect(op5.output) opCarvingLane.InputData.connect(op5.output) opCarvingLane.FilteredInputData.connect(opPreprocessing.FilteredImage) opCarvingLane.MST.connect(opPreprocessing.PreprocessedData) opCarvingLane.UncertaintyType.setValue("none") # Special input-input connection: WriteSeeds metadata must mirror the input data opCarvingLane.WriteSeeds.connect( opCarvingLane.InputData ) self.preprocessingApplet.enableDownstream(False) def handleAppletStateUpdateRequested(self): # If no data, nothing else is ready. opDataSelection = self.dataSelectionApplet.topLevelOperator input_ready = len(opDataSelection.ImageGroup) > 0 # If preprocessing isn't configured yet, don't allow carving preprocessed_data_ready = input_ready and self.preprocessingApplet._enabledDS # Enable each applet as appropriate self._shell.setAppletEnabled(self.preprocessingApplet, input_ready) self._shell.setAppletEnabled(self.carvingApplet, preprocessed_data_ready)
class CarvingWorkflow(Workflow): workflowName = "Carving" defaultAppletIndex = 1 # show DataSelection by default @property def applets(self): return self._applets @property def imageNameListSlot(self): return self.dataSelectionApplet.topLevelOperator.ImageName def __init__(self, shell, headless, workflow_cmdline_args, project_creation_args, hintoverlayFile=None, pmapoverlayFile=None, *args, **kwargs): if hintoverlayFile is not None: assert isinstance(hintoverlayFile, str), "hintoverlayFile should be a string, not '%s'" % type(hintoverlayFile) if pmapoverlayFile is not None: assert isinstance(pmapoverlayFile, str), "pmapoverlayFile should be a string, not '%s'" % type(pmapoverlayFile) graph = Graph() super(CarvingWorkflow, self).__init__(shell, headless, workflow_cmdline_args, project_creation_args, graph=graph, *args, **kwargs) data_instructions = "Select your input data using the 'Raw Data' tab shown on the right" ## Create applets self.projectMetadataApplet = ProjectMetadataApplet() self.dataSelectionApplet = DataSelectionApplet( self, "Input Data", "Input Data", supportIlastik05Import=True, batchDataGui=False, instructionText=data_instructions, max_lanes=1 ) opDataSelection = self.dataSelectionApplet.topLevelOperator opDataSelection.DatasetRoles.setValue( ['Raw Data'] ) self.preprocessingApplet = PreprocessingApplet(workflow=self, title = "Preprocessing", projectFileGroupName="preprocessing") self.carvingApplet = CarvingApplet(workflow=self, projectFileGroupName="carving", hintOverlayFile=hintoverlayFile, pmapOverlayFile=pmapoverlayFile) #self.carvingApplet.topLevelOperator.MST.connect(self.preprocessingApplet.topLevelOperator.PreprocessedData) # Expose to shell self._applets = [] self._applets.append(self.projectMetadataApplet) self._applets.append(self.dataSelectionApplet) self._applets.append(self.preprocessingApplet) self._applets.append(self.carvingApplet) def connectLane(self, laneIndex): ## Access applet operators opData = self.dataSelectionApplet.topLevelOperator.getLane(laneIndex) opPreprocessing = self.preprocessingApplet.topLevelOperator.getLane(laneIndex) opCarvingLane = self.carvingApplet.topLevelOperator.getLane(laneIndex) opCarvingLane.connectToPreprocessingApplet(self.preprocessingApplet) op5 = OpReorderAxes(parent=self) op5.AxisOrder.setValue("txyzc") op5.Input.connect(opData.Image) ## Connect operators opPreprocessing.InputData.connect(op5.Output) #opCarvingTopLevel.RawData.connect(op5.output) opCarvingLane.InputData.connect(op5.Output) opCarvingLane.FilteredInputData.connect(opPreprocessing.FilteredImage) opCarvingLane.MST.connect(opPreprocessing.PreprocessedData) opCarvingLane.UncertaintyType.setValue("none") # Special input-input connection: WriteSeeds metadata must mirror the input data opCarvingLane.WriteSeeds.connect( opCarvingLane.InputData ) self.preprocessingApplet.enableDownstream(False) def handleAppletStateUpdateRequested(self): # If no data, nothing else is ready. opDataSelection = self.dataSelectionApplet.topLevelOperator input_ready = len(opDataSelection.ImageGroup) > 0 # If preprocessing isn't configured yet, don't allow carving preprocessed_data_ready = input_ready and self.preprocessingApplet._enabledDS # Enable each applet as appropriate self._shell.setAppletEnabled(self.preprocessingApplet, input_ready) self._shell.setAppletEnabled(self.carvingApplet, preprocessed_data_ready)
class SplitBodyCarvingWorkflow(Workflow): workflowName = "Split Body Tool Workflow" defaultAppletIndex = 1 # show DataSelection by default DATA_ROLE_RAW = 0 DATA_ROLE_PIXEL_PROB = 1 DATA_ROLE_RAVELER_LABELS = 2 @property def applets(self): return self._applets @property def imageNameListSlot(self): return self.dataSelectionApplet.topLevelOperator.ImageName def __init__(self, shell, headless, workflow_cmdline_args, project_creation_args, hintoverlayFile=None, pmapoverlayFile=None, *args, **kwargs): graph = Graph() super(SplitBodyCarvingWorkflow, self).__init__(shell, headless, workflow_cmdline_args, project_creation_args, *args, graph=graph, **kwargs) ## Create applets self.projectMetadataApplet = ProjectMetadataApplet() self.dataSelectionApplet = DataSelectionApplet( self, "Input Data", "Input Data", supportIlastik05Import=True, batchDataGui=False) opDataSelection = self.dataSelectionApplet.topLevelOperator opDataSelection.DatasetRoles.setValue( ['Raw Data', 'Pixel Probabilities', 'Raveler Labels']) self.preprocessingApplet = PreprocessingApplet( workflow=self, title="Preprocessing", projectFileGroupName="preprocessing") self.splitBodyCarvingApplet = SplitBodyCarvingApplet( workflow=self, projectFileGroupName="carving") self.splitBodyPostprocessingApplet = SplitBodyPostprocessingApplet( workflow=self) self.splitBodySupervoxelExportApplet = SplitBodySupervoxelExportApplet( workflow=self) # Expose to shell self._applets = [] self._applets.append(self.projectMetadataApplet) self._applets.append(self.dataSelectionApplet) self._applets.append(self.preprocessingApplet) self._applets.append(self.splitBodyCarvingApplet) self._applets.append(self.splitBodyPostprocessingApplet) self._applets.append(self.splitBodySupervoxelExportApplet) self._split_tool_params = None if workflow_cmdline_args: arg_parser = argparse.ArgumentParser( description= "Specify parameters for the split-body carving workflow") arg_parser.add_argument('--split_tool_param_file', required=False) parsed_args, unused_args = arg_parser.parse_known_args( workflow_cmdline_args) if unused_args: logger.warn("Unused command-line args: {}".format(unused_args)) if parsed_args.split_tool_param_file is None: logger.warn("Missing cmd-line arg: --split_tool_param_file") else: logger.debug("Parsing split tool parameters: {}".format( parsed_args.split_tool_param_file)) json_parser = JsonConfigParser(SplitToolParamsSchema) self._split_tool_params = json_parser.parseConfigFile( parsed_args.split_tool_param_file) def onProjectLoaded(self, projectManager): """ Overridden from Workflow base class. Called by the Project Manager. - Use the parameter json file provided on the command line to populate the project's input data settings. - Also set the annotation file location. - Run the preprocessing step. - Save the project. """ if self._split_tool_params is None: return # -- Data Selection opDataSelection = self.dataSelectionApplet.topLevelOperator # If there is already data in this project, don't touch it. if len(opDataSelection.DatasetGroup) > 0: logger.warn( "Not changing project data, because your project appears to have data already." ) else: opDataSelection.DatasetGroup.resize(1) for role, data_params in [ (self.DATA_ROLE_RAW, self._split_tool_params.raw_data_info), (self.DATA_ROLE_PIXEL_PROB, self._split_tool_params.pixel_probabilities_info), (self.DATA_ROLE_RAVELER_LABELS, self._split_tool_params.raveler_labels_info) ]: logger.debug("Configuring dataset for role {}".format(role)) logger.debug("Params: {}".format(data_params)) datasetInfo = DatasetInfo() datasetInfo.updateFromJson(data_params) # Check for globstring, which means we need to import the stack first. if '*' in datasetInfo.filePath: totalProgress = [-100] def handleStackImportProgress(progress): if progress // 10 != totalProgress[0] // 10: totalProgress[0] = progress logger.info("Importing stack: {}%".format( totalProgress[0])) serializer = self.dataSelectionApplet.dataSerializers[0] serializer.progressSignal.connect( handleStackImportProgress) serializer.importStackAsLocalDataset(datasetInfo) opDataSelection.DatasetGroup[0][role].setValue(datasetInfo) # -- Split settings (annotation file) opSplitBodyCarving = self.splitBodyCarvingApplet.topLevelOperator.getLane( 0) opSplitBodyCarving.AnnotationFilepath.setValue( self._split_tool_params.raveler_bookmarks_file) # -- Preprocessing settings opPreprocessing = self.preprocessingApplet.topLevelOperator.getLane( 0) opPreprocessing.Sigma.setValue(1.0) opPreprocessing.Filter.setValue(OpFilter.RAW) # Run preprocessing def showProgress(progress): logger.info("Preprocessing Progress: {}%".format(progress)) self.preprocessingApplet.progressSignal.connect(showProgress) opPreprocessing.PreprocessedData[:].wait() logger.info("Preprocessing Complete") logger.info("Saving project...") projectManager.saveProject() # Special FlyEM supervoxelized body export: if self._split_tool_params.supervoxelized_bodies_export_path is not None: opSupervoxelExport = self.splitBodySupervoxelExportApplet.topLevelOperator.getLane( 0) def showExportProgress(progress): logger.info("Supervoxelized Body Export Progress: {}%".format( progress)) req = opSupervoxelExport.exportFinalSupervoxels( self._split_tool_params.supervoxelized_bodies_export_path, 'zyx', progressCallback=showExportProgress) req.wait() logger.info("FINISHED") def connectLane(self, laneIndex): ## Access applet operators opData = self.dataSelectionApplet.topLevelOperator.getLane(laneIndex) opPreprocessing = self.preprocessingApplet.topLevelOperator.getLane( laneIndex) opSplitBodyCarving = self.splitBodyCarvingApplet.topLevelOperator.getLane( laneIndex) opPostprocessing = self.splitBodyPostprocessingApplet.topLevelOperator.getLane( laneIndex) op5Raw = OpReorderAxes(parent=self) op5Raw.AxisOrder.setValue("txyzc") op5Raw.Input.connect(opData.ImageGroup[self.DATA_ROLE_RAW]) op5PixelProb = OpReorderAxes(parent=self) op5PixelProb.AxisOrder.setValue("txyzc") op5PixelProb.Input.connect( opData.ImageGroup[self.DATA_ROLE_PIXEL_PROB]) op5RavelerLabels = OpReorderAxes(parent=self) op5RavelerLabels.AxisOrder.setValue("txyzc") op5RavelerLabels.Input.connect( opData.ImageGroup[self.DATA_ROLE_RAVELER_LABELS]) # We assume the membrane boundaries are found in the first prediction class (channel 0) opSingleChannelSelector = OpSingleChannelSelector(parent=self) opSingleChannelSelector.Input.connect(op5PixelProb.Output) opSingleChannelSelector.Index.setValue(0) opPreprocessing.InputData.connect(opSingleChannelSelector.Output) opPreprocessing.RawData.connect(op5Raw.Output) opSplitBodyCarving.RawData.connect(op5Raw.Output) opSplitBodyCarving.InputData.connect(opSingleChannelSelector.Output) opSplitBodyCarving.RavelerLabels.connect(op5RavelerLabels.Output) opSplitBodyCarving.FilteredInputData.connect( opPreprocessing.FilteredImage) # Special input-input connection: WriteSeeds metadata must mirror the input data opSplitBodyCarving.WriteSeeds.connect(opSplitBodyCarving.InputData) opSplitBodyCarving.MST.connect(opPreprocessing.PreprocessedData) opSplitBodyCarving.UncertaintyType.setValue("none") opPostprocessing.RawData.connect(opSplitBodyCarving.RawData) opPostprocessing.InputData.connect(opSplitBodyCarving.InputData) opPostprocessing.RavelerLabels.connect( opSplitBodyCarving.RavelerLabels) opPostprocessing.MST.connect(opSplitBodyCarving.MstOut) # Split-body carving -> Postprocessing opPostprocessing.EditedRavelerBodyList.connect( opSplitBodyCarving.EditedRavelerBodyList) opPostprocessing.NavigationCoordinates.connect( opSplitBodyCarving.NavigationCoordinates) if not self._headless: self.preprocessingApplet.enableDownstream(False) # Supervoxel export opSupervoxelExport = self.splitBodySupervoxelExportApplet.topLevelOperator.getLane( laneIndex) opSupervoxelExport.DatasetInfos.connect(opData.DatasetGroup) opSupervoxelExport.WorkingDirectory.connect(opData.WorkingDirectory) opSupervoxelExport.RawData.connect(opPreprocessing.RawData) opSupervoxelExport.InputData.connect(opPreprocessing.InputData) opSupervoxelExport.Supervoxels.connect(opPreprocessing.WatershedImage) opSupervoxelExport.RavelerLabels.connect( opSplitBodyCarving.RavelerLabels) opSupervoxelExport.AnnotationBodyIds.connect( opSplitBodyCarving.AnnotationBodyIds)
class CarvingWorkflow(Workflow): workflowName = "Carving" defaultAppletIndex = 1 # show DataSelection by default @property def applets(self): return self._applets @property def imageNameListSlot(self): return self.dataSelectionApplet.topLevelOperator.ImageName def __init__(self, headless, workflow_cmdline_args, hintoverlayFile=None, pmapoverlayFile=None, *args, **kwargs): if hintoverlayFile is not None: assert isinstance(hintoverlayFile, str), "hintoverlayFile should be a string, not '%s'" % type(hintoverlayFile) if pmapoverlayFile is not None: assert isinstance(pmapoverlayFile, str), "pmapoverlayFile should be a string, not '%s'" % type(pmapoverlayFile) graph = Graph() super(CarvingWorkflow, self).__init__(headless, graph=graph, *args, **kwargs) ## Create applets self.projectMetadataApplet = ProjectMetadataApplet() self.dataSelectionApplet = DataSelectionApplet(self, "Input Data", "Input Data", supportIlastik05Import=True, batchDataGui=False) opDataSelection = self.dataSelectionApplet.topLevelOperator opDataSelection.DatasetRoles.setValue( ['Raw Data'] ) self.carvingApplet = CarvingApplet(workflow=self, projectFileGroupName="carving", hintOverlayFile=hintoverlayFile, pmapOverlayFile=pmapoverlayFile) self.preprocessingApplet = PreprocessingApplet(workflow=self, title = "Preprocessing", projectFileGroupName="preprocessing") #self.carvingApplet.topLevelOperator.MST.connect(self.preprocessingApplet.topLevelOperator.PreprocessedData) # Expose to shell self._applets = [] self._applets.append(self.projectMetadataApplet) self._applets.append(self.dataSelectionApplet) self._applets.append(self.preprocessingApplet) self._applets.append(self.carvingApplet) def connectLane(self, laneIndex): ## Access applet operators opData = self.dataSelectionApplet.topLevelOperator.getLane(laneIndex) opPreprocessing = self.preprocessingApplet.topLevelOperator.getLane(laneIndex) opCarvingLane = self.carvingApplet.topLevelOperator.getLane(laneIndex) op5 = Op5ifyer(parent=self) op5.order.setValue("txyzc") op5.input.connect(opData.Image) ## Connect operators opPreprocessing.InputData.connect(op5.output) #opCarvingTopLevel.RawData.connect(op5.output) opCarvingLane.InputData.connect(op5.output) opCarvingLane.FilteredInputData.connect(opPreprocessing.FilteredImage) opCarvingLane.MST.connect(opPreprocessing.PreprocessedData) opCarvingLane.UncertaintyType.setValue("none") # Special input-input connection: WriteSeeds metadata must mirror the input data opCarvingLane.WriteSeeds.connect( opCarvingLane.InputData ) self.preprocessingApplet.enableDownstream(False)