1 | """ |
---|
2 | FitPanel class contains fields allowing to fit models and data |
---|
3 | |
---|
4 | """ |
---|
5 | import sys |
---|
6 | import datetime |
---|
7 | |
---|
8 | from PyQt5 import QtCore |
---|
9 | from PyQt5 import QtGui |
---|
10 | from PyQt5 import QtWidgets |
---|
11 | |
---|
12 | from bumps.dream.stats import var_stats, format_vars |
---|
13 | |
---|
14 | |
---|
15 | class 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, optimizer="Unknown"): |
---|
58 | # Clear up previous results |
---|
59 | for view in (self.convergenceView, self.correlationView, |
---|
60 | self.uncertaintyView, self.traceView): |
---|
61 | view.close() |
---|
62 | # close all tabs. REMEMBER TO USE REVERSED RANGE!!! |
---|
63 | for index in reversed(range(self.count())): |
---|
64 | self.removeTab(index) |
---|
65 | |
---|
66 | result = results[0][0] |
---|
67 | filename = result.data.sas_data.filename |
---|
68 | current_optimizer = optimizer |
---|
69 | self.setWindowTitle(self.window_name + " - " + filename + " - " + current_optimizer) |
---|
70 | if hasattr(result, 'convergence') and len(result.convergence) > 0: |
---|
71 | best, pop = result.convergence[:, 0], result.convergence[:, 1:] |
---|
72 | self.convergenceView.update(best, pop) |
---|
73 | self.addTab(self.convergenceView, "Convergence") |
---|
74 | self.convergenceView.show() |
---|
75 | else: |
---|
76 | self.convergenceView.close() |
---|
77 | if hasattr(result, 'uncertainty_state'): |
---|
78 | stats = var_stats(result.uncertainty_state.draw()) |
---|
79 | msg = format_vars(stats) |
---|
80 | self.correlationView.update(result.uncertainty_state) |
---|
81 | self.correlationView.show() |
---|
82 | self.addTab(self.correlationView, "Correlation") |
---|
83 | |
---|
84 | self.uncertaintyView.update((result.uncertainty_state, stats)) |
---|
85 | self.uncertaintyView.show() |
---|
86 | self.addTab(self.uncertaintyView, "Uncertainty") |
---|
87 | |
---|
88 | self.traceView.update(result.uncertainty_state) |
---|
89 | self.traceView.show() |
---|
90 | self.addTab(self.traceView, "Parameter Trace") |
---|
91 | else: |
---|
92 | for view in (self.correlationView, self.uncertaintyView, self.traceView): |
---|
93 | view.close() |
---|
94 | # no tabs in the widget - possibly LM optimizer. Mark "closed" |
---|
95 | if self.count()==0: |
---|
96 | self.close() |
---|
97 | |
---|
98 | def closeEvent(self, event): |
---|
99 | """ |
---|
100 | Overwrite QDialog close method to allow for custom widget close |
---|
101 | """ |
---|
102 | # notify the parent so it hides this window |
---|
103 | self.windowClosedSignal.emit() |
---|
104 | event.ignore() |
---|
105 | |
---|