Ejemplo n.º 1
0
    def __init__(self, *args, **kwargs):
        super(EnsembleGUIPlugin, self).__init__(*args, **kwargs)

        self._projectors = []  # List[Callable[[BlueskyRun], List[Intent]]]
        self.ensemble_model = EnsembleModel()

        self.intents_model = IntentsModel()
        self.intents_model.setSourceModel(self.ensemble_model)

        self.ensemble_view = DataSelectorView()
        self.ensemble_view.setModel(self.ensemble_model)

        self.canvases_view = StackedCanvasView()
        self.canvases_view.setModel(self.intents_model)

        self.canvases_view.sigInteractiveAction.connect(self.process_action)

        self.workflow_editor = WorkflowEditor(Workflow())

        self.xi_help = HelpWidget()

        self.gui_layout_template = {
            "center": self.canvases_view,
            "right": self.ensemble_view,
            "rightbottom": self.workflow_editor,
            "leftbottom": self.xi_help
        }
Ejemplo n.º 2
0
    def __init__(self):

        self.workflow = Workflow()
        self.workfloweditor = WorkflowEditor(
            self.workflow,
            callback_slot=self.showResult,
            except_slot=lambda *_: self.workflow._pretty_print())

        self.ensemble_model = EnsembleModel()

        data_selector_view = DataSelectorView()
        data_selector_view.setModel(self.ensemble_model)

        # Our results views' model (should only contain intents)
        intents_model = IntentsModel()
        intents_model.setSourceModel(self.ensemble_model)

        # Our results view widget container
        results_view = StackedCanvasView()
        results_view.setModel(intents_model)

        self.stages = {
            'Testing':
            GUILayout(results_view,
                      left=None,
                      righttop=data_selector_view,
                      right=self.workfloweditor),
        }
        super(WorkflowEditorPlugin, self).__init__()
Ejemplo n.º 3
0
def test_view(simple_workflow_with_intents, qtbot):
    # Tests ingesting an internally run workflow, projecting it, storing it in a model
    # and using a CanvasView to display it

    @live_plugin('PlotMixinPlugin')
    class PlotMixinTest(PlotWidget):
        def __init__(self, *args, **kwargs):
            super(PlotMixinTest, self).__init__(*args,
                                                background='g',
                                                **kwargs)

    @live_plugin('ImageMixinPlugin')
    class ImageMixinTest(ImageView):
        def __init__(self, *args, **kwargs):
            super(ImageMixinTest, self).__init__(*args, **kwargs)
            self.setStyleSheet('* {background-color:green;}')

    execution.executor = LocalExecutor()
    ensemble_model = EnsembleModel()
    intents_model = IntentsModel()
    intents_model.setSourceModel(ensemble_model)

    data_selector_view = DataSelectorView()
    data_selector_view.setModel(ensemble_model)

    stacked_canvas_view = StackedCanvasView()
    stacked_canvas_view.setModel(intents_model)

    widget = QWidget()
    layout = QHBoxLayout()
    layout.addWidget(stacked_canvas_view)
    layout.addWidget(data_selector_view)
    widget.setLayout(layout)

    def showResult(*result):
        ensemble = Ensemble()
        doc_generator = ingest_result_set(simple_workflow_with_intents, result)

        documents = list(doc_generator)
        catalog = BlueskyInMemoryCatalog()
        catalog.upsert(documents[0][1], documents[-1][1], ingest_result_set,
                       [simple_workflow_with_intents, result], {})
        catalog = catalog[-1]

        ensemble.append_catalog(catalog)
        ensemble_model.add_ensemble(ensemble, project_intents)
        qtbot.wait(1000)
        root = ensemble_model.index(0, 0, QModelIndex())
        ensemble_model.setData(root.child(0, 0), True, Qt.CheckStateRole)

    widget.setMinimumSize(800, 600)
    widget.show()
    qtbot.addWidget(widget)

    workflow_editor = WorkflowEditor(simple_workflow_with_intents,
                                     callback_slot=showResult)
    workflow_editor.run_workflow()

    qtbot.wait(3000)
Ejemplo n.º 4
0
class EnsembleGUIPlugin(GUIPlugin):
    """GUI plugin that uses the Xi-CAM 'Ensemble' architecture for data organization.

    Attributes
    ----------
    canvases_view : StackedCanvasView
        Canvas view attached to the `intents_model`, visualizes data.
    ensemble_model : EnsembleModel
        Model that stores Ensembles.
    ensemble_view : DataSelectorView
        View attached to `ensemble_model` that controls visualizing data.
    intents_model : IntentsModel
        Model that stores visualizable data in the `ensemble_model` (i.e. Intents).
    gui_layout_template : dict
        Dict that includes `canvases_view`, `ensemble_view`, `workflow_editor`, and `xi_help`.
        Convenience as a template layout when creating GUILayouts for stages.
    workflow_editor : WorkflowEditor
        Workflow editor that contains empty Workflow; re-initialize for custom workflows.
    xi-help : HelpWidget
        Interactive helper widget.
    """
    name = "Ensemble Plugin"
    supports_ensembles = True

    def __init__(self, *args, **kwargs):
        super(EnsembleGUIPlugin, self).__init__(*args, **kwargs)

        self._projectors = []  # List[Callable[[BlueskyRun], List[Intent]]]
        self.ensemble_model = EnsembleModel()

        self.intents_model = IntentsModel()
        self.intents_model.setSourceModel(self.ensemble_model)

        self.ensemble_view = DataSelectorView()
        self.ensemble_view.setModel(self.ensemble_model)

        self.canvases_view = StackedCanvasView()
        self.canvases_view.setModel(self.intents_model)

        self.canvases_view.sigInteractiveAction.connect(self.process_action)

        self.workflow_editor = WorkflowEditor(Workflow())

        self.xi_help = HelpWidget()

        self.gui_layout_template = {
            "center": self.canvases_view,
            "right": self.ensemble_view,
            "rightbottom": self.workflow_editor,
            "leftbottom": self.xi_help
        }

    def process_action(self, action: Action, canvas: "XicamIntentCanvas"):
        ...

    def appendCatalog(self, catalog: BlueskyRun, **kwargs):
        self.ensemble_model.append_to_ensemble(catalog, None, self._projectors)
Ejemplo n.º 5
0
    def __init__(self):
        self.ensemble_model = EnsembleModel()
        self.intents_model = IntentsModel()
        self.intents_model.setSourceModel(self.ensemble_model)
        self.data_selector_view = DataSelectorView()
        self.data_selector_view.setModel(self.ensemble_model)

        self.current_catalog = None

        # TODO: use catalogs as output of workflows
        self.current_data = None

        self.catalog_viewer = NDImageView()
        self.library_viewer = LibraryWidget()

        super(SpectralBase, self).__init__()
Ejemplo n.º 6
0
    def canvases(self, model: IntentsModel) -> Generator[IntentCanvas, None, None]:
        """Retrieve all canvases from a given model."""
        # Create a mapping from canvas to rows to get unique canvas references.
        seen_canvases = set()

        for row in range(model.rowCount()):
            canvas = self.canvas_from_row(row, model)
            if canvas not in seen_canvases:
                seen_canvases.add(canvas)
                yield canvas
Ejemplo n.º 7
0
class SpectralBase(GUIPlugin):
    name = "Spectral"

    def __init__(self):
        self.ensemble_model = EnsembleModel()
        self.intents_model = IntentsModel()
        self.intents_model.setSourceModel(self.ensemble_model)
        self.data_selector_view = DataSelectorView()
        self.data_selector_view.setModel(self.ensemble_model)

        self.current_catalog = None

        # TODO: use catalogs as output of workflows
        self.current_data = None

        self.catalog_viewer = NDImageView()
        self.library_viewer = LibraryWidget()

        super(SpectralBase, self).__init__()

    def treatment_kwargs(self, workflow):

        # FIXME: Putting this here for now...
        self.current_data = None
        return {'data': project_all(self.current_catalog)}

    def append_treatment(self, result_set):
        if self.current_data is None:
            self.current_data = result_set['data']
        else:
            self.current_data = xr.concat(
                [self.current_data, result_set['data']],
                dim='E (eV)')  # FIXME do this better

    def show_treatment(self):
        self.catalog_viewer.setImage(self.current_data,
                                     reset_crosshair=True,
                                     autoRange=True)

    def appendCatalog(self, run_catalog: BlueskyRun, **kwargs):
        # catalog.metadata.update(self.schema())
        ensemble = Ensemble()
        ensemble.append_catalog(run_catalog)
        self.ensemble_model.add_ensemble(ensemble, projection_mapping.values())

        try:
            # Apply nxSTXM projection

            #add conditional to split xarray from intent
            xdata = project_all(run_catalog)
            if isinstance(
                    xdata, list
            ):  # temporary logic to allow for intents to be returned rather than xarray
                for intent in xdata:
                    if isinstance(intent, ImageIntent):
                        xdata = intent.image
                        break
                else:
                    raise ValueError("No data returned from ingestion.")

            self.catalog_viewer.setData(
                xdata)  #, view_dims=('y (μm)', 'x (μm)')

        except Exception as e:
            msg.logError(e)
            msg.showMessage("Unable to display: ", str(e))

        self.current_catalog = run_catalog
Ejemplo n.º 8
0
def test_view(simple_workflow_with_intents, qtbot):
    # Tests ingesting an internally run workflow, projecting it, storing it in a model
    # and using a CanvasView to display it

    plugin_manager.qt_is_safe = True
    plugin_manager.initialize_types()
    plugin_manager.collect_plugins()

    pc = next(
        filter(lambda task: task.name == 'plot_canvas', plugin_manager._tasks))
    plugin_manager._load_plugin(pc)
    plugin_manager._instantiate_plugin(pc)

    ic = next(
        filter(lambda task: task.name == 'image_canvas',
               plugin_manager._tasks))
    plugin_manager._load_plugin(ic)
    plugin_manager._instantiate_plugin(ic)

    plot_intent_task = next(
        filter(lambda task: task.name == 'PlotIntent', plugin_manager._tasks))
    plugin_manager._load_plugin(plot_intent_task)
    plugin_manager._instantiate_plugin(plot_intent_task)
    image_intent_task = next(
        filter(lambda task: task.name == 'ImageIntent', plugin_manager._tasks))
    plugin_manager._load_plugin(image_intent_task)
    plugin_manager._instantiate_plugin(image_intent_task)

    execution.executor = LocalExecutor()
    ensemble_model = EnsembleModel()
    intents_model = IntentsModel()
    intents_model.setSourceModel(ensemble_model)

    data_selector_view = DataSelectorView()
    data_selector_view.setModel(ensemble_model)

    stacked_canvas_view = StackedCanvasView()
    stacked_canvas_view.setModel(intents_model)

    widget = QWidget()
    layout = QHBoxLayout()
    layout.addWidget(stacked_canvas_view)
    layout.addWidget(data_selector_view)
    widget.setLayout(layout)

    def showResult(*result):
        ensemble = Ensemble()
        doc_generator = ingest_result_set(simple_workflow_with_intents, result)

        documents = list(doc_generator)
        catalog = BlueskyInMemoryCatalog()
        catalog.upsert(documents[0][1], documents[-1][1], ingest_result_set,
                       [simple_workflow_with_intents, result], {})
        catalog = catalog[-1]

        ensemble.append_catalog(catalog)
        ensemble_model.add_ensemble(ensemble, project_intents)
        qtbot.wait(1000)
        root = ensemble_model.index(0, 0, QModelIndex())
        ensemble_model.setData(root.child(0, 0), True, Qt.CheckStateRole)

    widget.setMinimumSize(800, 600)
    widget.show()
    qtbot.addWidget(widget)

    workflow_editor = WorkflowEditor(simple_workflow_with_intents,
                                     callback_slot=showResult)
    workflow_editor.run_workflow()

    qtbot.wait(7000)