Пример #1
0
    def build(self):
        sizer = wx.GridBagSizer(5, 5)
        sizer.SetVGap(5)
        sizer.SetHGap(5)

        splitter = wx.SplitterWindow(self, style=wx.SP_LIVE_UPDATE)
        splitter.SetMinimumPaneSize(200)

        self.datalistbox = EditableListBox(splitter,
                                           self.ShowDataSet,
                                           size=(250, -1))
        panel = scrolled.ScrolledPanel(splitter)

        self.SetMinSize((650, 600))
        self.colors = GUIColors()

        # title row
        self.wids = wids = {}
        title = SimpleText(panel,
                           'Linear Combination Results',
                           font=Font(FONTSIZE + 2),
                           colour=self.colors.title,
                           style=LEFT)

        wids['plot_one'] = Button(panel,
                                  'Plot This Fit',
                                  size=(125, -1),
                                  action=self.onPlotOne)
        wids['plot_sel'] = Button(panel,
                                  'Plot N Best Fits',
                                  size=(125, -1),
                                  action=self.onPlotSel)

        wids['plot_ntitle'] = SimpleText(panel, 'N fits to plot: ')

        wids['plot_nchoice'] = Choice(panel,
                                      size=(60, -1),
                                      choices=['%d' % i for i in range(1, 21)])
        wids['plot_nchoice'].SetStringSelection('5')

        wids['data_title'] = SimpleText(panel,
                                        '<--> ',
                                        font=Font(FONTSIZE + 2),
                                        colour=self.colors.title,
                                        style=LEFT)
        wids['nfits_title'] = SimpleText(panel, 'showing 5 best fits')

        copts = dict(size=(125, 30), default=True, action=self.onPlotOne)
        # wids['show_e0'] = Check(panel, label='show E0?', **copts)
        wids['show_fitrange'] = Check(panel, label='show fit range?', **copts)

        irow = 0
        sizer.Add(title, (irow, 0), (1, 1), LEFT)
        sizer.Add(wids['data_title'], (irow, 1), (1, 2), LEFT)

        irow += 1
        sizer.Add(wids['nfits_title'], (irow, 0), (1, 1), LEFT)

        irow += 1
        self.wids['paramstitle'] = SimpleText(panel,
                                              '[[Parameters]]',
                                              font=Font(FONTSIZE + 2),
                                              colour=self.colors.title,
                                              style=LEFT)
        sizer.Add(self.wids['paramstitle'], (irow, 0), (1, 1), LEFT)

        pview = self.wids['params'] = dv.DataViewListCtrl(panel, style=DVSTYLE)
        pview.SetMinSize((475, 200))
        pview.AppendTextColumn(' Parameter ', width=230)
        pview.AppendTextColumn(' Best-Fit Value', width=120)
        pview.AppendTextColumn(' Standard Error ', width=120)
        for col in range(3):
            this = pview.Columns[col]
            isort, align = True, wx.ALIGN_RIGHT
            if col == 0:
                align = wx.ALIGN_LEFT
            this.Sortable = isort
            this.Alignment = this.Renderer.Alignment = align

        irow += 1
        sizer.Add(self.wids['params'], (irow, 0), (4, 1), LEFT)
        sizer.Add(self.wids['plot_one'], (irow, 1), (1, 2), LEFT)
        sizer.Add(self.wids['plot_sel'], (irow + 1, 1), (1, 2), LEFT)
        sizer.Add(self.wids['plot_ntitle'], (irow + 2, 1), (1, 1), LEFT)
        sizer.Add(self.wids['plot_nchoice'], (irow + 2, 2), (1, 1), LEFT)
        # sizer.Add(self.wids['show_e0'],      (irow+3, 1), (1, 2), LEFT)
        sizer.Add(self.wids['show_fitrange'], (irow + 3, 1), (1, 2), LEFT)

        irow += 4
        sizer.Add(HLine(panel, size=(675, 3)), (irow, 0), (1, 4), LEFT)

        sview = self.wids['stats'] = dv.DataViewListCtrl(panel, style=DVSTYLE)
        sview.Bind(dv.EVT_DATAVIEW_SELECTION_CHANGED, self.onSelectFitStat)
        sview.AppendTextColumn(' Fit #', width=50)
        sview.AppendTextColumn(' N_vary', width=50)
        sview.AppendTextColumn(' N_eval', width=60)
        sview.AppendTextColumn(' \u03c7\u00B2', width=110)
        sview.AppendTextColumn(' \u03c7\u00B2_reduced', width=110)
        sview.AppendTextColumn(' Akaike Info', width=110)
        sview.AppendTextColumn(' Bayesian Info', width=110)

        for col in range(sview.ColumnCount):
            this = sview.Columns[col]
            isort, align = True, wx.ALIGN_RIGHT
            if col == 0:
                align = wx.ALIGN_CENTER
            this.Sortable = isort
            this.Alignment = this.Renderer.Alignment = align

        sview.SetMinSize((675, 175))

        irow += 1
        title = SimpleText(panel,
                           '[[Fit Statistics]]',
                           font=Font(FONTSIZE + 2),
                           colour=self.colors.title,
                           style=LEFT)
        sizer.Add(title, (irow, 0), (1, 4), LEFT)

        irow += 1
        sizer.Add(sview, (irow, 0), (1, 4), LEFT)

        irow += 1
        sizer.Add(HLine(panel, size=(675, 3)), (irow, 0), (1, 4), LEFT)

        irow += 1
        title = SimpleText(panel,
                           '[[Weights]]',
                           font=Font(FONTSIZE + 2),
                           colour=self.colors.title,
                           style=LEFT)
        sizer.Add(title, (irow, 0), (1, 4), LEFT)
        self.wids['weightspanel'] = ppan = wx.Panel(panel)

        p1 = SimpleText(ppan, ' < Weights > ')
        os = wx.BoxSizer(wx.VERTICAL)
        os.Add(p1, 1, 3)
        pack(ppan, os)
        ppan.SetMinSize((675, 175))

        irow += 1
        sizer.Add(ppan, (irow, 0), (1, 4), LEFT)

        irow += 1
        sizer.Add(HLine(panel, size=(675, 3)), (irow, 0), (1, 4), LEFT)

        pack(panel, sizer)
        panel.SetupScrolling()

        splitter.SplitVertically(self.datalistbox, panel, 1)

        mainsizer = wx.BoxSizer(wx.VERTICAL)
        mainsizer.Add(splitter, 1, wx.GROW | wx.ALL, 5)

        pack(self, mainsizer)
        # self.SetSize((725, 750))
        self.Show()
        self.Raise()
Пример #2
0
    def show_results(self, datagroup=None, form=None, larch_eval=None):
        if datagroup is not None:
            self.datagroup = datagroup
        if form is not None:
            self.form = form
        if larch_eval is not None:
            self.larch_eval = larch_eval

        form = self.form
        datagroup = self.datagroup
        lcf_history = getattr(self.datagroup, 'lcf_history', [])

        wids = self.wids
        wids['data_title'].SetLabel(self.datagroup.filename)
        # wids['show_e0'].SetValue(form['show_e0'])
        wids['show_fitrange'].SetValue(form['show_fitrange'])

        wids['stats'].DeleteAllItems()
        results = self.datagroup.lcf_result[:20]
        self.nresults = len(results)
        wids['nfits_title'].SetLabel('showing %i best results' % self.nresults)

        for i, res in enumerate(results):
            args = ['%2.2d' % (i + 1)]
            for attr in ('nvarys', 'nfev', 'chisqr', 'redchi', 'aic', 'bic'):
                val = getattr(res.result, attr)
                if isinstance(val, int):
                    val = '%d' % val
                else:
                    val = gformat(val, 12)
                args.append(val)
            wids['stats'].AppendItem(tuple(args))

        wpan = self.wids['weightspanel']
        wpan.DestroyChildren()

        wview = self.wids['weights'] = dv.DataViewListCtrl(wpan, style=DVSTYLE)
        wview.Bind(dv.EVT_DATAVIEW_SELECTION_CHANGED, self.onSelectFitParam)
        wview.AppendTextColumn(' Fit #', width=50)

        for i, cname in enumerate(form['comp_names']):
            wview.AppendTextColumn(cname, width=100)
        wview.AppendTextColumn('Total', width=100)

        for col in range(len(form['comp_names']) + 2):
            this = wview.Columns[col]
            isort, align = True, wx.ALIGN_RIGHT
            if col == 0:
                align = wx.ALIGN_CENTER
            this.Sortable = isort
            this.Alignment = this.Renderer.Alignment = align

        for i, res in enumerate(results):
            args = ['%2.2d' % (i + 1)]
            for cname in form['comp_names'] + ['total']:
                val = '--'
                if cname in res.params:
                    val = "%.4f" % res.params[cname].value
                args.append(val)
            wview.AppendItem(tuple(args))

        os = wx.BoxSizer(wx.VERTICAL)
        os.Add(wview, 1, wx.GROW | wx.ALL)
        pack(wpan, os)

        wview.SetMinSize((675, 200))
        s1, s2 = self.GetSize()
        if s2 % 2 == 0:
            s2 = s2 + 1
        else:
            s2 = s2 - 1
        self.SetSize((s1, s2))
        self.show_fitresult(0)
        self.Refresh()
Пример #3
0
    def build(self):
        sizer = wx.GridBagSizer(10, 5)
        sizer.SetVGap(5)
        sizer.SetHGap(5)

        panel = scrolled.ScrolledPanel(self)
        self.SetMinSize((675, 600))
        self.colors = GUIColors()

        # title row
        self.wids = wids = {}
        title = SimpleText(panel,
                           'Linear Combination Results',
                           font=Font(12),
                           colour=self.colors.title,
                           style=LCEN)

        wids['plot_one'] = Button(panel,
                                  'Plot This Fit',
                                  size=(150, -1),
                                  action=self.onPlotOne)
        wids['plot_sel'] = Button(panel,
                                  'Plot top N Fits',
                                  size=(150, -1),
                                  action=self.onPlotSel)

        wids['plot_ntitle'] = SimpleText(panel, 'N fits to plot: ')

        wids['plot_nchoice'] = Choice(panel,
                                      size=(100, -1),
                                      choices=['%d' % i for i in range(1, 21)])
        wids['plot_nchoice'].SetStringSelection('5')

        wids['data_title'] = SimpleText(panel,
                                        '<--> ',
                                        font=Font(12),
                                        colour=self.colors.title,
                                        style=LCEN)
        wids['nfits_title'] = SimpleText(panel, 'showing top 5 fits')

        irow = 0
        sizer.Add(title, (irow, 0), (1, 2), LCEN)
        sizer.Add(wids['data_title'], (irow, 2), (1, 2), LCEN)

        irow += 1
        sizer.Add(wids['nfits_title'], (irow, 0), (1, 4), LCEN)

        irow += 1
        sizer.Add(self.wids['plot_one'], (irow, 0), (1, 1), LCEN)
        sizer.Add(self.wids['plot_sel'], (irow, 1), (1, 1), LCEN)
        sizer.Add(self.wids['plot_ntitle'], (irow, 2), (1, 1), LCEN)
        sizer.Add(self.wids['plot_nchoice'], (irow, 3), (1, 1), LCEN)

        irow += 1
        self.wids['paramstitle'] = SimpleText(panel,
                                              '[[Parameters]]',
                                              font=Font(12),
                                              colour=self.colors.title,
                                              style=LCEN)
        sizer.Add(self.wids['paramstitle'], (irow, 0), (1, 4), LCEN)

        pview = self.wids['params'] = dv.DataViewListCtrl(panel, style=DVSTYLE)
        pview.SetMinSize((675, 200))
        pview.AppendTextColumn(' Parameter ', width=250)
        pview.AppendTextColumn(' Best-Fit Value', width=150)
        pview.AppendTextColumn(' Uncertainty ', width=150)
        for col in range(3):
            this = pview.Columns[col]
            isort, align = True, wx.ALIGN_RIGHT
            if col == 0:
                align = wx.ALIGN_LEFT
            this.Sortable = isort
            this.Alignment = this.Renderer.Alignment = align

        irow += 1
        sizer.Add(self.wids['params'], (irow, 0), (1, 4), LCEN)

        irow += 1
        sizer.Add(HLine(panel, size=(675, 3)), (irow, 0), (1, 4), LCEN)

        sview = self.wids['stats'] = dv.DataViewListCtrl(panel, style=DVSTYLE)
        sview.Bind(dv.EVT_DATAVIEW_SELECTION_CHANGED, self.onSelectFitStat)
        sview.AppendTextColumn(' Fit #', width=50)
        sview.AppendTextColumn(' N_Vary', width=60)
        sview.AppendTextColumn(' N_Data', width=60)
        sview.AppendTextColumn(' N_eval', width=60)
        sview.AppendTextColumn(u' \u03c7\u00B2', width=100)
        sview.AppendTextColumn(u' \u03c7\u00B2_reduced', width=100)
        sview.AppendTextColumn(' Akaike Info', width=100)
        sview.AppendTextColumn(' Bayesian Info', width=100)

        for col in range(8):
            this = sview.Columns[col]
            isort, align = True, wx.ALIGN_RIGHT
            if col == 0:
                align = wx.ALIGN_CENTER
            this.Sortable = isort
            this.Alignment = this.Renderer.Alignment = align

        sview.SetMinSize((675, 175))

        irow += 1
        title = SimpleText(panel,
                           '[[Fit Statistics]]',
                           font=Font(12),
                           colour=self.colors.title,
                           style=LCEN)
        sizer.Add(title, (irow, 0), (1, 4), LCEN)

        irow += 1
        sizer.Add(sview, (irow, 0), (1, 4), LCEN)

        irow += 1
        sizer.Add(HLine(panel, size=(675, 3)), (irow, 0), (1, 4), LCEN)

        irow += 1
        title = SimpleText(panel,
                           '[[Weights]]',
                           font=Font(12),
                           colour=self.colors.title,
                           style=LCEN)
        sizer.Add(title, (irow, 0), (1, 4), LCEN)
        self.wids['weightspanel'] = ppan = wx.Panel(self)

        p1 = SimpleText(ppan, ' < Weights > ')
        os = wx.BoxSizer(wx.VERTICAL)
        os.Add(p1, 1, 3)
        pack(ppan, os)
        ppan.SetMinSize((675, 175))

        irow += 1
        sizer.Add(ppan, (irow, 0), (1, 4), LCEN)

        irow += 1
        sizer.Add(HLine(panel, size=(675, 3)), (irow, 0), (1, 4), LCEN)

        pack(panel, sizer)
        panel.SetupScrolling()

        mainsizer = wx.BoxSizer(wx.VERTICAL)
        mainsizer.Add(panel, 1, wx.GROW | wx.ALL, 1)

        pack(self, mainsizer)
        self.Show()
        self.Raise()