Example #1
0
    def doCalibrateWorkflow(self, workflow: Workflow):
        data = self.calibrationtabview.currentWidget().header.meta_array('primary')[0]
        device = self.calibrationpanel.parameter['Device']
        ai = self.calibrationsettings.AI('pilatus2M')
        ai.detector = detectors.Pilatus2M()
        c = calibrant.ALL_CALIBRANTS('AgBh')

        def setAI(result):
            self.calibrationsettings.setAI(result['ai'].value, device)
            self.doMaskingWorkflow(self.maskingworkflow)

        workflow.execute(None, data=data, ai=ai, calibrant=c, callback_slot=setAI, threadkey='calibrate')
Example #2
0
    def doDisplayWorkflow(self, workflow: Workflow):
        currentwidget = self.reducetabview.currentWidget()
        data = currentwidget.header.meta_array('primary')[currentwidget.timeIndex(currentwidget.timeLine)[0]]
        ai = self.calibrationsettings.AI('pilatus2M')
        ai.detector = detectors.Pilatus2M()
        mask = self.maskingworkflow.lastresult[0]['mask'].value if self.maskingworkflow.lastresult else None
        outputwidget = currentwidget

        def showDisplay(*results):
            outputwidget.setResults(results)

        workflow.execute(None, data=data, ai=ai, mask=mask, callback_slot=showDisplay, threadkey='display')
Example #3
0
    def doSimulateWorkflow(self, workflow: Workflow):
        data = self.calibrationtabview.currentWidget().header.meta_array('primary')[0]
        ai = self.calibrationsettings.AI('pilatus2M')
        ai.detector = detectors.Pilatus2M()
        calibrant = self.calibrationpanel.parameter['Calibrant Material']
        outputwidget = self.calibrationtabview.currentWidget()

        def showSimulatedCalibrant(result=None):
            outputwidget.setCalibrantImage(result['data'].value)

        workflow.execute(None, data=data, ai=ai, calibrant=calibrant, callback_slot=showSimulatedCalibrant,
                         threadkey='simulate')
Example #4
0
    def doCalibrateWorkflow(self, workflow: Workflow):
        data = self.calibrationtabview.currentWidget().image
        data = self.checkDataShape(data)
        if data is None: return
        device = self.rawtoolbar.detectorcombobox.currentText()
        ai = self.calibrationsettings.AI(device)
        # ai.detector = detectors.Pilatus2M()
        calibrant = self.calibrationpanel.parameter['Calibrant Material']

        def setAI(result):
            self.calibrationsettings.setAI(result['ai'].value, device)
            self.doMaskingWorkflow()

        workflow.execute(None, data=data, ai=ai, calibrant=calibrant, callback_slot=setAI, threadkey='calibrate')
Example #5
0
    def doMaskingWorkflow(self, workflow: Workflow):
        if not self.checkPolygonsSet(workflow):
            data = self.calibrationtabview.currentWidget().header.meta_array('primary')[0]
            ai = self.calibrationsettings.AI('pilatus2M')
            ai.detector = detectors.Pilatus2M()
            outputwidget = self.masktabview.currentWidget()

            def showMask(result=None):
                if result:
                    outputwidget.setMaskImage(result['mask'].value)
                else:
                    outputwidget.setMaskImage(None)
                self.doDisplayWorkflow(self.displayworkflow)
                self.doReduceWorkflow(self.reduceworkflow)

            workflow.execute(None, data=data, ai=ai, callback_slot=showMask, threadkey='masking')
 def test_execute(self, sum_op, square_op, negative_op):
     workflow = Workflow()
     workflow.add_operations(sum_op, square_op, negative_op)
     workflow.add_link(sum_op, square_op, "sum", "n")
     workflow.add_link(square_op, negative_op, "square", "num")
     results = workflow.execute(n1=2, n2=5).result()
     assert results == ({"negative": -49}, )
Example #7
0
 def test_execute_no_links_diff_input_names(self, sum_op, square_op, negative_op):
     # do the input names have to match in this case (more than one entry op)
     operations = [sum_op, square_op, negative_op]
     workflow = Workflow(name="test", operations=operations)
     results = workflow.execute(n1=3, n2=-3, n=10, num=33).result()
     assert len(results) == 3
     assert {"sum": 0} in results
     assert {"square": 100} in results
     assert {"negative": -33} in results
    def test_execute_operation_no_default_no_value(self, sum_op):
        # not sure how to test this....
        def handle_exception(exception):
            with pytest.raises(TypeError):
                raise exception

        workflow = Workflow()
        workflow.add_operation(sum_op)
        results = workflow.execute(except_slot=handle_exception).result()
        print(results)
Example #9
0
    def test_execute_operation_default_input_value(self):
        @operation
        @output_names("doubled")
        def double_op(x=10):
            return x * 2

        workflow = Workflow()
        workflow.add_operation(double_op)
        results = workflow.execute().result()
        assert results == ({"doubled": 20}, )
Example #10
0
    def test_execute_no_links(self):
        @operation
        @output_names("doubled")
        def double_op(n):
            return n * 2

        @operation
        @output_names("tripled")
        def triple_op(n):
            return n * 3

        workflow = Workflow()
        workflow.add_operations(double_op, triple_op)
        results = workflow.execute(n=10).result()
        assert len(results) == 2
        assert {"doubled": 20} in results
        assert {"tripled": 30} in results
Example #11
0
class TomographyPlugin(GUIPlugin):
    name = 'Tomography'
    sigLog = Signal(int, str, str, np.ndarray)
    slice = 0
    multislice = 1
    preview3d = 2
    fullrecon = 3

    def __init__(self):
        self.workflow = Workflow()

        self.headermodel = QStandardItemModel()
        # self.alignmenttabview = TabView(self.headermodel)
        self.rawtabview = TabView(self.headermodel,
                                  widgetcls=RAWViewer,
                                  field='primary')
        self.recontabs = QTabWidget()

        self.workfloweditor = WorkflowEditor(self.workflow)
        self.workfloweditor.setHidden(True)

        self.tomotoolbar = TomoToolbar()
        self.tomotoolbar.sigSliceReconstruction.connect(self.sliceReconstruct)
        self.tomotoolbar.sigFullReconstruction.connect(self.fullReconstruction)

        self.stages = {
            'Alignment':
            GUILayout(QLabel('Alignment'),
                      right=self.workfloweditor,
                      top=self.tomotoolbar),
            'Preprocess':
            GUILayout(self.rawtabview,
                      right=self.workfloweditor,
                      top=self.tomotoolbar),
            'Reconstruct':
            GUILayout(self.recontabs,
                      top=self.tomotoolbar,
                      right=self.workfloweditor),
        }
        super(TomographyPlugin, self).__init__()

    def appendHeader(self, header: NonDBHeader, **kwargs):
        item = QStandardItem(header.startdoc.get('sample_name', '????'))
        item.header = header
        self.headermodel.appendRow(item)
        self.headermodel.dataChanged.emit(QModelIndex(), QModelIndex())

    def sliceReconstruct(self):
        currentitem = self.headermodel.item(self.rawtabview.currentIndex())
        if not currentitem:
            msg.showMessage(
                'Error: You must open files before reconstructing.')
        try:
            msg.showBusy()
            msg.showMessage('Running slice reconstruction...', level=msg.INFO)
            path = self.headermodel.item(
                self.rawtabview.currentIndex()).header.startdoc['path']
            self.workflow.execute(
                None,
                path=path,
                threadkey='slicereconstruct',
                callback_slot=partial(self.showReconstruction,
                                      mode=self.slice),
                except_slot=self.exceptionCallback)
        except Exception as ex:
            msg.logError(ex)
            msg.showReady()
            msg.clearMessage()

    def fullReconstruction(self):
        volumeviewer = VolumeViewer()
        self.recontabs.addTab(volumeviewer, '????')

        currentitem = self.headermodel.item(self.rawtabview.currentIndex())
        if not currentitem:
            msg.showMessage(
                'Error: You must open files before reconstructing.')
        try:
            msg.showBusy()
            msg.showMessage('Running slice reconstruction...', level=msg.INFO)
            currentheader = self.headermodel.item(
                self.rawtabview.currentIndex()).header
            readprocess = self.workflow.processes[
                0]  # hopefully! TODO: require a readprocess first
            readprocess.path.value = currentheader.startdoc['path']

            numofsinograms = currentheader.meta_array('primary').shape[1]

            executor = DaskExecutor()
            client = distributed.Client()

            def chunkiterator(workflow):
                for i in range(0, int(numofsinograms),
                               int(readprocess.chunksize.value)):
                    readprocess.sinoindex.value = i
                    yield executor.execute(workflow)

            _reconthread = QThreadFutureIterator(
                chunkiterator,
                self.workflow,
                callback_slot=partial(self.showReconstruction,
                                      mode=self.fullrecon),
                except_slot=self.exceptionCallback)
            _reconthread.start()
        except Exception as ex:
            msg.logError(ex)
            msg.showReady()
            msg.clearMessage()

    def exceptionCallback(self, ex):
        msg.notifyMessage("Reconstruction failed;\n see log for error")
        msg.showMessage("Reconstruction failed; see log for error")
        msg.logError(ex)
        msg.showReady()

    def showReconstruction(self, result, mode):
        print('result:', result)
        if mode == self.slice:
            sliceviewer = SliceViewer()
            sliceviewer.setImage(list(result.values())[0].value.squeeze())
            self.recontabs.addTab(sliceviewer, '????')

        if mode == self.fullrecon:
            self.recontabs.widget(self.recontabs.count() - 1).appendData(
                list(result.values())[0].value[::4, ::4, ::4])
        msg.showReady()
 def test_execute_operation_no_default(self, sum_op):
     workflow = Workflow()
     workflow.add_operation(sum_op)
     results = workflow.execute(n1=10, n2=5).result()
     assert results == ({"sum": 15}, )
 def test_execute_no_operations(self):
     workflow = Workflow("Test Workflow")
     results = workflow.execute().result()
     assert results == ({}, )
Example #14
0
 def test_execute_no_links_TODO(self, sum_op, square_op, negative_op):
     # do the input names have to match in this case (more than one entry op)
     operations = [sum_op, square_op, negative_op]
     workflow = Workflow(name="test", operations=operations)
     results = workflow.execute(n1=3, n2=-3).result()
     assert results == ({"sum": 0})