source: sasview/src/sas/qtgui/Utilities/ResultPanel.py @ 8748751

ESS_GUIESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalc
Last change on this file since 8748751 was 8748751, checked in by Piotr Rozyczko <piotr.rozyczko@…>, 5 years ago

Fit result viewer SASVIEW-274, SASVIEW-275

  • Property mode set to 100644
File size: 3.3 KB
Line 
1"""
2FitPanel class contains fields allowing to fit  models and  data
3
4"""
5import sys
6import datetime
7
8from PyQt5 import QtCore
9from PyQt5 import QtGui
10from PyQt5 import QtWidgets
11
12from bumps.dream.stats import var_stats, format_vars
13
14
15class ResultPanel(QtWidgets.QTabWidget):
16    """
17    FitPanel class contains fields allowing to fit  models and  data
18
19    :note: For Fit to be performed the user should check at least one parameter
20        on fit Panel window.
21
22    """
23    ## Internal name for the AUI manager
24    window_name = "Result panel"
25    windowClosedSignal = QtCore.pyqtSignal()
26
27    def __init__(self, parent, manager=None, *args, **kwargs):
28        """
29        """
30        super(ResultPanel, self).__init__(parent)
31        self.manager = manager
32        self.communicator = self.manager.communicator()
33        self.setMinimumSize(400, 400)
34
35        self.updateBumps() # patch bumps ## TEMPORARY ##
36
37        # the following two imports will move to the top once
38        # the monkeypatching is gone
39        from bumps.gui.convergence_view import ConvergenceView
40        from bumps.gui.uncertainty_view import UncertaintyView, CorrelationView, TraceView
41
42
43        self.convergenceView = ConvergenceView()
44        self.uncertaintyView = UncertaintyView()
45        self.correlationView = CorrelationView()
46        self.traceView = TraceView()
47        self.show()
48
49    def updateBumps(self):
50        """
51        Monkeypatching bumps plot viewer to allow Qt
52        """
53        from . import PlotView
54        import bumps.gui
55        sys.modules['bumps.gui.plot_view'] = PlotView
56
57    def onPlotResults(self, results):
58        # Clear up previous results
59        for view in (self.convergenceView, self.correlationView,
60                     self.uncertaintyView, self.traceView):
61            view.close()
62
63        result = results[0][0]
64        filename = result.data.sas_data.filename
65        current_time = datetime.datetime.now().strftime("%I:%M%p, %B %d, %Y")
66        self.setWindowTitle(self.window_name + " - " + filename + " - " + current_time)
67        if hasattr(result, 'convergence'):
68            best, pop = result.convergence[:, 0], result.convergence[:, 1:]
69            self.convergenceView.update(best, pop)
70            self.addTab(self.convergenceView, "Convergence")
71            self.convergenceView.show()
72        else:
73            self.convergenceView.close()
74        if hasattr(result, 'uncertainty_state'):
75            stats = var_stats(result.uncertainty_state.draw())
76            msg = format_vars(stats)
77            self.correlationView.update(result.uncertainty_state)
78            self.correlationView.show()
79            self.addTab(self.correlationView, "Correlation")
80
81            self.uncertaintyView.update((result.uncertainty_state, stats))
82            self.uncertaintyView.show()
83            self.addTab(self.uncertaintyView, "Uncertainty")
84
85            self.traceView.update(result.uncertainty_state)
86            self.traceView.show()
87            self.addTab(self.traceView, "Parameter Trace")
88        else:
89            for view in (self.correlationView, self.uncertaintyView, self.traceView):
90                view.close()
91
92    def closeEvent(self, event):
93        """
94        Overwrite QDialog close method to allow for custom widget close
95        """
96        # notify the parent so it hides this window
97        self.windowClosedSignal.emit()
98        event.ignore()
99
Note: See TracBrowser for help on using the repository browser.