source: sasview/src/sas/sasgui/perspectives/fitting/resultpanel.py @ 9f3db13

ESS_GUIESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_opencl
Last change on this file since 9f3db13 was 959eb01, checked in by ajj, 8 years ago

normalising line endings

  • Property mode set to 100644
File size: 3.5 KB
RevLine 
[959eb01]1"""
2FitPanel class contains fields allowing to fit  models and  data
3
4:note: For Fit to be performed the user should check at least one parameter
5    on fit Panel window.
6
7"""
8import wx
9import wx.lib.newevent
10from wx.aui import AuiNotebook as Notebook
11
12import datetime
13
14from bumps.gui.convergence_view import ConvergenceView
15from bumps.gui.uncertainty_view import UncertaintyView, CorrelationView, TraceView
16from bumps.dream.stats import var_stats, format_vars
17
18from sas.sasgui.guiframe.panel_base import PanelBase
19from sas.sasgui.guiframe.events import StatusEvent
20
21(PlotResultEvent, EVT_PLOT_RESULT) = wx.lib.newevent.NewEvent()
22
23
24class ResultPanel(Notebook, PanelBase):
25    """
26    FitPanel class contains fields allowing to fit  models and  data
27
28    :note: For Fit to be performed the user should check at least one parameter
29        on fit Panel window.
30
31    """
32    ## Internal name for the AUI manager
33    window_name = "Result panel"
34    ## Title to appear on top of the window
35    window_caption = "Result Panel"
36    CENTER_PANE = True
37
38    def __init__(self, parent, manager=None, *args, **kwargs):
39        """
40        """
41        style = ((wx.aui.AUI_NB_WINDOWLIST_BUTTON
42                 | wx.aui.AUI_NB_DEFAULT_STYLE
43                 | wx.CLIP_CHILDREN)
44                 & ~wx.aui.AUI_NB_CLOSE_ON_ACTIVE_TAB)
45        Notebook.__init__(self, parent, wx.ID_ANY, style=style)
46        PanelBase.__init__(self, parent)
47        self.frame = parent
48        self.Bind(EVT_PLOT_RESULT, self.on_plot_results)
49        self.frame.Bind(wx.EVT_CLOSE, self.on_close)
50        self._manager = None
51
52    def on_close(self, event):
53        if event.CanVeto():
54            self.frame.Hide()
55            event.Veto()
56        else:
57            event.Skip()
58
59    def on_plot_results(self, event):
60        self.frame.Show(True)
61        result = event.result[0][0]
62        filename = result.data.sas_data.filename
63        current_time = datetime.datetime.now().strftime("%I:%M%p, %B %d, %Y")
64        self.parent.SetTitle(self.window_name + " - " + filename + " - " + current_time)
65        if hasattr(result, 'convergence'):
66            best, pop = result.convergence[:, 0], result.convergence[:, 1:]
67            self._get_view(ConvergenceView).update(best, pop)
68        else:
69            self._del_view(ConvergenceView)
70        if hasattr(result, 'uncertainty_state'):
71            stats = var_stats(result.uncertainty_state.draw())
72            msg = format_vars(stats)
73            self._get_view(CorrelationView).update(result.uncertainty_state)
74            self._get_view(UncertaintyView).update((result.uncertainty_state, stats))
75            self._get_view(TraceView).update(result.uncertainty_state)
76            # TODO: stats should be stored in result rather than computed in bumps UncertaintyView
77            wx.PostEvent(self.frame.parent,
78                         StatusEvent(status=msg, info="info"))
79        else:
80            for view in (CorrelationView, UncertaintyView, TraceView):
81                self._del_view(view)
82
83    def get_frame(self):
84        return self.frame
85
86    def _get_view(self, view_class):
87        for idx in range(self.PageCount):
88            if self.GetPageText(idx) == view_class.title:
89                return self.GetPage(idx)
90        else:
91            panel = view_class(self)
92            self.AddPage(panel, panel.title)
93            return panel
94
95    def _del_view(self, view_class):
96        for idx in range(self.PageCount):
97            if self.GetPageText(idx) == view_class.title:
98                self.DeletePage(idx)
99
Note: See TracBrowser for help on using the repository browser.