示例#1
0
    def __init__(self, parent=None, size=(-1, -1)):
        wx.Frame.__init__(self, parent, -1, 'Parameter Panel Test',
                          size=size, style=wx.DEFAULT_FRAME_STYLE)
        panel = GridPanel(self)

        name1 = 'peak1_amp'
        param1 = Parameter(value=99.0, vary=True, min=0, name=name1)
        name2 = 'peak1_cen'
        param2 = Parameter(value=1.23, vary=True, min=0.5, max=2.0, name=name2)

        p1 = ParameterPanel(panel, param1)
        p2 = ParameterPanel(panel, param2)
        panel.AddText(" %s: " % name1, style=LEFT)
        panel.Add(p1,  style=LEFT)
        panel.NewRow()

        panel.AddText(" %s: " % name2, style=LEFT)
        panel.Add(p2,  style=LEFT)

        panel.pack()
        self.createMenus()

        self.SetSize((400, 90))
        self.Show()
        self.Raise()
示例#2
0
    def __init__(self, parent=None, size=(-1, -1)):
        wx.Frame.__init__(self,
                          parent,
                          -1,
                          'Parameter Panel Test',
                          size=size,
                          style=wx.DEFAULT_FRAME_STYLE)
        panel = GridPanel(self)

        param1 = Parameter(value=99.0,
                           vary=True,
                           min=0,
                           name='peak1_amplitude')
        param2 = Parameter(value=110.2,
                           vary=True,
                           min=100,
                           max=120,
                           name='peak1_center')
        param3 = Parameter(value=1.23,
                           vary=True,
                           min=0.5,
                           max=2.0,
                           name='peak1_sigma')

        panel.Add(ParameterPanel(panel, param1, show_name=True), style=LEFT)
        # panel.NewRow()
        panel.Add(ParameterPanel(panel, param2, show_name=True), style=LEFT)
        panel.Add(ParameterPanel(panel, param3, show_name=True), style=LEFT)
        panel.pack()
        self.createMenus()

        self.SetSize((700, 200))
        self.Show()
        self.Raise()
示例#3
0
    def fitpeaks_page(self):
        "create row for filters parameters"
        mca = self.parent.mca
        self.wids.peaks = []

        p = GridPanel(self)

        p.AddManyText((' ROI Name', 'Fit?', 'Center', 'Sigma', 'Amplitude'),
                      style=CEN)
        p.Add(HLine(p, size=(600, 3)), dcol=5, newrow=True)
        offset, slope = self.mca.offset, self.mca.slope
        for iroi, roi in enumerate(self.mca.rois):
            try:
                cenval, ecen, fwhm, ampval, _x = self.mca.init_calib[roi.name]
            except KeyError:
                continue
            sigval = 0.4 * fwhm
            mincen = offset + slope * (roi.left - 4 * roi.bgr_width)
            maxcen = offset + slope * (roi.right + 4 * roi.bgr_width)

            pname = roi.name.replace(' ', '').lower()
            ampnam = '%s_amp' % pname
            cennam = '%s_cen' % pname
            signam = '%s_sig' % pname
            sigexpr = "%s + %s*%s +%s*%s**2" % (self.gsig_offset,
                                                self.gsig_slope, cennam,
                                                self.gsig_quad, cennam)

            p_amp = Parameter(value=ampval, vary=True, min=0, name=ampnam)
            p_sig = Parameter(value=sigval, expr=sigexpr, min=0, name=signam)
            p_cen = Parameter(value=cenval,
                              vary=False,
                              name=cennam,
                              min=mincen,
                              max=maxcen)

            setattr(self.paramgroup, ampnam, p_amp)
            setattr(self.paramgroup, cennam, p_cen)
            setattr(self.paramgroup, signam, p_sig)

            _use = Check(p, label='use', default=True)
            _cen = ParameterPanel(p, p_cen, precision=3)
            _sig = ParameterPanel(p, p_sig, precision=3)
            _amp = ParameterPanel(p, p_amp, precision=2)

            self.wids.peaks.append((_use, _cen, _sig, _amp))

            p.AddText(' %s' % roi.name, newrow=True, style=LEFT)
            p.Add(_use, style=wx.ALIGN_CENTER)
            p.Add(_cen)
            p.Add(_sig)
            p.Add(_amp)
        p.Add(HLine(p, size=(600, 3)), dcol=5, newrow=True)
        p.pack()
        return p
示例#4
0
    def __init__(self, parent, calfile, **kws):

        self.parent = parent
        self.scandb = parent.scandb
        self.calfile = calfile
        poni = read_poni(calfile)

        wx.Dialog.__init__(self,
                           parent,
                           wx.ID_ANY,
                           size=(600, 525),
                           title="Read Calibration File")

        panel = GridPanel(self, ncols=3, nrows=4, pad=2, itemstyle=LCEN)

        self.wids = wids = {}

        wids['filename'] = SimpleText(panel, calfile)

        _p, fname = os.path.split(calfile)
        wids['calname'] = wx.TextCtrl(panel, value=fname, size=(350, -1))

        wids['ok'] = Button(panel, 'OK', size=(150, -1), action=self.on_apply)

        def add_text(text, dcol=1, newrow=True):
            panel.Add(SimpleText(panel, text), dcol=dcol, newrow=newrow)

        add_text('  Calibration file: ', newrow=False)
        panel.Add(wids['filename'], dcol=3)
        add_text('  Save as : ')
        panel.Add(wids['calname'], dcol=3)

        opts = dict(size=(90, -1), digits=5)
        for wname in ('wavelength', 'dist', 'pixel1', 'pixel2', 'poni1',
                      'poni2', 'rot1', 'rot2', 'rot3'):
            scale, units = self.conv[wname]
            val = scale * float(poni[wname])
            if wname == 'wavelength':
                energy = 12398.4193 / val
                units = '%s,  Energy=%.2f' % (units, energy)

            wids[wname] = FloatCtrl(panel,
                                    value=val,
                                    size=(100, -1),
                                    precision=4)
            wids[wname + '_units'] = SimpleText(panel, units)
            add_text('  %s:' % wname.title())
            panel.Add(wids[wname])
            panel.Add(wids[wname + '_units'])

        panel.Add((5, 5))
        panel.Add(wids['ok'], dcol=2, newrow=True)
        panel.pack()
示例#5
0
    def __init__(self, parent, size=(400, 300), **kws):
        self.parent = parent
        conf = parent.conf
        kws['style'] = wx.DEFAULT_FRAME_STYLE
        wx.Frame.__init__(self,
                          parent,
                          -1,
                          size=size,
                          title='XRF Color Settings',
                          **kws)

        panel = GridPanel(self)
        panel.SetFont(Font(11))

        def add_color(panel, name):
            cval = hexcolor(getattr(conf, name))
            c = csel.ColourSelect(panel, -1, "", cval, size=(35, 25))
            c.Bind(csel.EVT_COLOURSELECT, partial(self.onColor, item=name))
            return c

        def scolor(txt, attr, **kws):
            panel.AddText(txt,
                          size=(130, -1),
                          style=LEFT,
                          font=Font(11),
                          **kws)
            panel.Add(add_color(panel, attr), style=LEFT)

        panel.AddText('    XRF Display Colors', dcol=4, colour='#880000')
        panel.Add(HLine(panel, size=(400, 3)), dcol=4, newrow=True)
        scolor(' Main Spectra:', 'spectra_color', newrow=True)
        scolor(' Background Spectra:', 'spectra2_color')
        scolor(' ROIs:', 'roi_color', newrow=True)
        scolor(' ROI Fill:', 'roi_fillcolor')
        scolor(' Cursor:', 'marker_color', newrow=True)
        scolor(' XRF Background:', 'bgr_color')
        scolor(' Major X-ray Lines:', 'major_elinecolor', newrow=True)
        scolor(' Minor X-ray Lines:', 'minor_elinecolor')
        scolor(' Selected X-ray Line:', 'emph_elinecolor', newrow=True)
        scolor(' Held  X-ray Lines:', 'hold_elinecolor')
        scolor(' Pileup Prediction:', 'pileup_color', newrow=True)
        scolor(' Escape Prediction:', 'escape_color')

        panel.Add(HLine(panel, size=(400, 3)), dcol=4, newrow=True)
        panel.Add(Button(panel, 'Done', size=(80, -1), action=self.onDone),
                  dcol=2,
                  newrow=True)

        panel.pack()
        self.SetMinSize(panel.GetBestSize())
        self.Show()
        self.Raise()
示例#6
0
    def __init__(self, parent, name,  **kws):
        title = "Video Capture"
        wx.Dialog.__init__(self, parent, wx.ID_ANY, title=title)

        panel = GridPanel(self, ncols=3, nrows=2, pad=2, itemstyle=LCEN)

        self.filename = wx.TextCtrl(panel, -1, 'Capture.avi',  size=(150, -1))
        self.runtime  = wx.TextCtrl(panel, -1, '15.0',   size=(150, -1))

        panel.Add(SimpleText(panel, 'File Name : '), newrow=True)
        panel.Add(self.filename)
        panel.Add(SimpleText(panel, 'Run Time: '), newrow=True)
        panel.Add(self.runtime)
        panel.Add(OkCancel(panel), dcol=2, newrow=True)
        panel.pack()
示例#7
0
    def filters_page(self):
        "create row for filters parameters"
        mca = self.parent.mca
        self.wids.filters = []

        p = GridPanel(self, itemstyle=LEFT)

        bx = Button(p,
                    'Customize Filter List',
                    size=(150, -1),
                    action=self.onEditFilters)
        bx.Disable()
        p.AddManyText(
            (' filter', 'material', 'density (gr/cm^3)', 'thickness (mm)'),
            style=CEN)
        p.Add(HLine(p, size=(600, 3)), dcol=5, newrow=True)
        for i in range(4):
            _mat = Choice(p,
                          choices=self.Filter_Materials,
                          default=0,
                          size=(125, -1),
                          action=partial(self.onFilterMaterial, index=i))
            _den = FloatCtrl(p,
                             value=0,
                             minval=0,
                             maxval=30,
                             precision=4,
                             size=(75, -1))

            pnam = 'filter%i_thickness' % (i + 1)
            param = Parameter(value=0.0, vary=False, min=0, name=pnam)
            setattr(self.paramgroup, pnam, param)
            _len = ParameterPanel(p, param, precision=4)

            self.wids.filters.append((_mat, _den, _len))
            p.AddText('  %i ' % (i + 1), newrow=True)
            p.Add(_mat)
            p.Add(_den, style=wx.ALIGN_CENTER)
            p.Add(_len)
        p.Add(HLine(p, size=(600, 3)), dcol=5, newrow=True)
        p.AddText(' ', newrow=True)
        p.Add(bx, dcol=3)

        p.pack()
        return p
示例#8
0
    def addModel(self, event=None, model=None):
        if model is None and event is not None:
            model = event.GetString()
        if model is None or model.startswith('<'):
            return

        curmodels = [
            "c%i_" % (i + 1) for i in range(1 + len(self.fit_components))
        ]
        for comp in self.fit_components:
            if comp in curmodels:
                curmodels.remove(comp)

        prefix = curmodels[0]

        label = "%s(prefix='%s')" % (model, prefix)
        title = "%s: %s" % (prefix[:-1], (model + ' ' * 8)[:8])
        mclass_kws = {'prefix': prefix}
        if 'step' in model.lower():
            form = model.lower().replace('step', '').strip()

            if form.startswith('err'): form = 'erf'
            label = "Step(form='%s', prefix='%s')" % (form, prefix)
            title = "%s: Step %s" % (prefix[:-1], form[:3])
            mclass = lm_models.StepModel
            mclass_kws['form'] = form
            minst = mclass(form=form, prefix=prefix)
        else:
            mclass = getattr(lm_models, model + 'Model')
            minst = mclass(prefix=prefix)

        panel = GridPanel(self.mod_nb, ncols=1, nrows=1, pad=1, itemstyle=CEN)

        def SLabel(label, size=(80, -1), **kws):
            return SimpleText(panel,
                              label,
                              size=size,
                              style=wx.ALIGN_LEFT,
                              **kws)

        usebox = Check(panel, default=True, label='Use?', size=(75, -1))
        delbtn = Button(panel,
                        'Delete Model',
                        size=(120, -1),
                        action=partial(self.onDeleteComponent, prefix=prefix))
        pick2msg = SimpleText(panel, "    ", size=(75, -1))
        pick2btn = Button(panel,
                          'Pick Data Range',
                          size=(135, -1),
                          action=partial(self.onPick2Points, prefix=prefix))

        # SetTip(mname,  'Label for the model component')
        SetTip(usebox, 'Use this component in fit?')
        SetTip(delbtn, 'Delete this model component')
        SetTip(pick2btn, 'Select X range on Plot to Guess Initial Values')

        panel.Add(HLine(panel, size=(520, 3)), style=wx.ALIGN_CENTER, dcol=6)

        panel.Add(SLabel(label, size=(200, -1), colour='#0000AA'),
                  dcol=3,
                  newrow=True)
        panel.AddMany((usebox, pick2msg, pick2btn))

        panel.Add(SLabel("Parameter"), newrow=True)
        panel.AddMany((SLabel("Value"), SLabel("Type"), SLabel("Min"),
                       SLabel("Max"), SLabel("Expression")))

        parwids = OrderedDict()

        parnames = sorted(minst.param_names)

        for a in minst._func_allargs:
            pname = "%s%s" % (prefix, a)
            if (pname not in parnames and a in minst.param_hints
                    and a not in minst.independent_vars):
                parnames.append(pname)

        for pname in parnames:
            sname = pname[len(prefix):]
            hints = minst.param_hints.get(sname, {})

            par = Parameter(name=pname, value=0, vary=True)
            if 'min' in hints:
                par.min = hints['min']
            if 'max' in hints:
                par.max = hints['max']
            if 'value' in hints:
                par.value = hints['value']
            if 'expr' in hints:
                par.expr = hints['expr']

            pwids = ParameterWidgets(panel,
                                     par,
                                     name_size=80,
                                     expr_size=175,
                                     float_size=80,
                                     prefix=prefix,
                                     widgets=('name', 'value', 'minval',
                                              'maxval', 'vary', 'expr'))
            parwids[par.name] = pwids
            panel.Add(pwids.name, newrow=True)
            panel.AddMany((pwids.value, pwids.vary, pwids.minval, pwids.maxval,
                           pwids.expr))

        for sname, hint in minst.param_hints.items():
            pname = "%s%s" % (prefix, sname)
            if 'expr' in hint and pname not in parnames:
                par = Parameter(name=pname, value=0, expr=hint['expr'])

                pwids = ParameterWidgets(panel,
                                         par,
                                         name_size=80,
                                         expr_size=275,
                                         float_size=80,
                                         prefix=prefix,
                                         widgets=('name', 'value', 'vary',
                                                  'expr'))
                parwids[par.name] = pwids
                panel.Add(pwids.name, newrow=True)
                panel.AddMany((pwids.value, pwids.vary))
                panel.Add(pwids.expr, dcol=3, style=wx.ALIGN_RIGHT)
                pwids.value.Disable()
                pwids.vary.Disable()

        panel.Add(HLine(panel, size=(90, 3)),
                  style=wx.ALIGN_CENTER,
                  newrow=True)
        panel.Add(delbtn, dcol=2)
        panel.Add(HLine(panel, size=(250, 3)), dcol=3, style=wx.ALIGN_CENTER)

        fgroup = Group(prefix=prefix,
                       title=title,
                       mclass=mclass,
                       mclass_kws=mclass_kws,
                       usebox=usebox,
                       panel=panel,
                       parwids=parwids,
                       float_size=65,
                       expr_size=150,
                       pick2_msg=pick2msg)

        self.fit_components[prefix] = fgroup
        panel.pack()

        self.mod_nb.AddPage(panel, title, True)
        sx, sy = self.GetSize()
        self.SetSize((sx, sy + 1))
        self.SetSize((sx, sy))
示例#9
0
    def __init__(self, parent, controller, **kws):

        self.parent = parent
        self.controller = controller
        self.dgroup = self.controller.get_group()
        groupnames = list(self.controller.file_groups.keys())

        self.data = [self.dgroup.energy[:], self.dgroup.norm[:]]

        title = "Correct Over-absorption"

        wx.Dialog.__init__(self, parent, wx.ID_ANY, size=(550, 275), title=title)

        panel = GridPanel(self, ncols=3, nrows=4, pad=2, itemstyle=LCEN)

        self.grouplist = Choice(panel, choices=groupnames, size=(250, -1),
                                action=self.on_groupchoice)
        self.grouplist.SetStringSelection(self.dgroup.filename)

        self.wids = wids = {}
        opts  = dict(size=(90, -1), precision=1, act_on_losefocus=True,
                     minval=-90, maxval=180)

        wids['phi_in']  = FloatCtrl(panel, value=45, **opts)
        wids['phi_out'] = FloatCtrl(panel, value=45, **opts)

        opts = dict(size=(75, -1), action=self.on_correct)

        wids['elem'] = Choice(panel, choices=ELEM_LIST, **opts)
        wids['edge'] = Choice(panel, choices=EDGE_LIST, **opts)

        wids['formula'] = wx.TextCtrl(panel, -1, '',  size=(350, -1))
        wids['formula'].Bind(wx.EVT_TEXT_ENTER, self.on_correct)
        wids['formula'].Bind(wx.EVT_KILL_FOCUS, self.on_correct)

        self.set_default_elem_edge(self.dgroup)

        for wname in ('phi_in', 'phi_out'):
            wids[wname].SetAction(self.on_correct)

        apply_one = Button(panel, 'Save Arrays for this Group', size=(175, -1),
                           action=self.on_apply_one)
        apply_one.SetToolTip('Save corrected data, overwrite current arrays')

        # apply_sel = Button(panel, 'Apply to Selected Groups', size=(175, -1),
        #                    action=self.on_apply_sel)
        #apply_sel.SetToolTip('''Apply SA Correction to the Selected Groups
        # in XAS GUI, overwriting current arrays''')

        done = Button(panel, 'Done', size=(125, -1), action=self.on_done)

        panel.Add(SimpleText(panel, ' Correction for Group: '), dcol=1)
        panel.Add(self.grouplist, dcol=5)

        panel.Add(SimpleText(panel, ' Absorbing Element: '), newrow=True)
        panel.Add(wids['elem'])
        panel.Add(SimpleText(panel, ' Edge: '))
        panel.Add(wids['edge'])


        panel.Add(SimpleText(panel, ' Material Formula: '), newrow=True)
        panel.Add(wids['formula'], dcol=3)

        panel.Add(SimpleText(panel, ' Incident Angle: '), newrow=True)
        panel.Add(wids['phi_in'])
        panel.Add(SimpleText(panel, 'degrees'))
        panel.Add(SimpleText(panel, ' Exit Angle: '), newrow=True)
        panel.Add(wids['phi_out'])
        panel.Add(SimpleText(panel, 'degrees'))

        panel.Add(apply_one, dcol=4, newrow=True)

        panel.Add(HLine(panel, size=(550, 3)), dcol=7, newrow=True)
        panel.Add(done, dcol=4, newrow=True)
        panel.pack()
示例#10
0
    def settings_page(self):
        "create fit and background settings"
        mca = self.parent.mca
        conf = self.parent.conf
        wids = self.wids

        width = getattr(mca, 'bgr_width', 4)
        compr = getattr(mca, 'bgr_compress', 2)
        expon = getattr(mca, 'bgr_exponent', 2)

        p = GridPanel(self, itemstyle=LEFT)
        wids.bgr_use = Check(p,
                             label='Fit Background-Subtracted Spectra',
                             default=True)
        wids.bgr_width = FloatCtrl(p,
                                   value=width,
                                   minval=0,
                                   maxval=10,
                                   precision=1,
                                   size=(70, -1))
        wids.bgr_compress = Choice(p,
                                   choices=['1', '2', '4', '8', '16'],
                                   size=(70, -1),
                                   default=1)
        wids.bgr_exponent = Choice(p,
                                   choices=['2', '4', '6'],
                                   size=(70, -1),
                                   default=0)

        sopts = {'vary': True, 'precision': 5}
        sig_offset = Parameter(value=0.050, name=self.gsig_offset, vary=True)
        sig_slope = Parameter(value=0.005, name=self.gsig_slope, vary=True)
        sig_quad = Parameter(value=0.000, name=self.gsig_quad, vary=False)

        setattr(self.paramgroup, self.gsig_offset, sig_offset)
        setattr(self.paramgroup, self.gsig_slope, sig_slope)
        setattr(self.paramgroup, self.gsig_quad, sig_quad)

        wids.sig_offset = ParameterPanel(p, sig_offset, vary=True, precision=5)
        wids.sig_slope = ParameterPanel(p, sig_slope, vary=True, precision=5)
        wids.sig_quad = ParameterPanel(p, sig_quad, vary=False, precision=5)

        wids.xray_en = FloatCtrl(p,
                                 value=20.0,
                                 size=(70, -1),
                                 minval=0,
                                 maxval=1000,
                                 precision=3)

        wids.fit_emin = FloatCtrl(p,
                                  value=conf.e_min,
                                  size=(70, -1),
                                  minval=0,
                                  maxval=1000,
                                  precision=3)
        wids.fit_emax = FloatCtrl(p,
                                  value=conf.e_max,
                                  size=(70, -1),
                                  minval=0,
                                  maxval=1000,
                                  precision=3)
        wids.flyield_use = Check(
            p, label='Account for Absorption, Fluorescence Efficiency')

        p.AddText(' General Settings ', colour='#880000', dcol=3)

        p.AddText(' X-ray Energy (keV): ', newrow=True)
        p.Add(wids.xray_en)
        p.AddText(' Min Energy (keV): ', newrow=True)
        p.Add(wids.fit_emin)
        p.AddText(' Max Energy (keV): ', newrow=False)
        p.Add(wids.fit_emax)

        wids.det_mat = Choice(p,
                              choices=self.Detector_Materials,
                              size=(55, -1),
                              default=0)
        wids.det_thk = FloatCtrl(p,
                                 value=0.40,
                                 size=(70, -1),
                                 minval=0,
                                 maxval=100,
                                 precision=3)
        wids.det_use = Check(p, label='Account for Detector Thickness')

        p.AddText(' Detector Material:  ', newrow=True)
        p.Add(wids.det_mat)
        p.AddText(' Thickness (mm): ', newrow=False)
        p.Add(wids.det_thk)
        p.Add(wids.det_use, dcol=4, newrow=True)
        p.Add(wids.flyield_use, dcol=4, newrow=True)

        p.Add(HLine(p, size=(600, 3)), dcol=5, newrow=True)

        p.AddText(' Energy Dependence of Peak Width:',
                  colour='#880000',
                  newrow=True,
                  dcol=2)
        # p.AddText(' ', newrow=True)
        p.AddText(' sigma = offset + slope * Energy + quad * Energy^2 (keV)',
                  dcol=3)
        p.AddText(' Offset: ', newrow=True)
        p.Add(wids.sig_offset, dcol=3)
        p.AddText(' Slope: ', newrow=True)
        p.Add(wids.sig_slope, dcol=3)
        p.AddText(' Quad: ', newrow=True)
        p.Add(wids.sig_quad, dcol=3)
        p.Add(HLine(p, size=(600, 3)), dcol=5, newrow=True)

        p.AddText(" Background Parameters: ",
                  colour='#880000',
                  dcol=2,
                  newrow=True)
        p.Add(wids.bgr_use, dcol=2)

        p.AddText(" Exponent:", newrow=True)
        p.Add(wids.bgr_exponent)
        p.AddText(" Energy Width (keV): ", newrow=False)
        p.Add(wids.bgr_width)

        p.AddText(" Compression: ", newrow=True)
        p.Add(wids.bgr_compress)
        p.Add(Button(p,
                     'Show Background',
                     size=(130, -1),
                     action=self.onShowBgr),
              dcol=2)

        p.Add(HLine(p, size=(600, 3)), dcol=5, newrow=True)
        p.pack()
        return p
示例#11
0
    def __init__(self):

        wx.Frame.__init__(self,
                          None,
                          -1,
                          'wxutil demo',
                          style=wx.DEFAULT_FRAME_STYLE | wx.RESIZE_BORDER
                          | wx.TAB_TRAVERSAL)
        self.SetTitle('wxutil demo')

        self.SetFont(Font(11))

        self.set_menu()
        self.statusbar = self.CreateStatusBar(2, 1)
        self.statusbar.SetStatusWidths([-2, -1])
        statusbar_fields = ['Initializing....', ' ']
        for i in range(len(statusbar_fields)):
            self.statusbar.SetStatusText(statusbar_fields[i], i)

        self.Bind(wx.EVT_CLOSE, self.onExit)

        panel = GridPanel(self, nrows=8, ncols=4)

        tctrl_name = TextCtrl(panel,
                              value='',
                              action=self.onName,
                              size=(250, -1))

        lctrl_addr = LabeledTextCtrl(self,
                                     value='<>',
                                     action=self.onAddr,
                                     labeltext=' Address: ',
                                     size=(250, -1))

        lab3 = HyperText(panel,
                         ' FloatCtrl: ',
                         size=(100, -1),
                         action=self.onHyperText)

        val3 = FloatCtrl(panel,
                         '3',
                         action=self.onFloat1,
                         precision=2,
                         minval=0,
                         maxval=1000,
                         size=(250, -1))

        lab4 = HyperText(panel,
                         ' FloatSpin: ',
                         size=(100, -1),
                         action=self.onHyperText)
        val4 = FloatSpin(panel,
                         '12.2',
                         action=self.onFloatSpin,
                         digits=2,
                         increment=0.1,
                         size=(250, -1))

        labx = HyperText(panel,
                         ' NumericCombo: ',
                         size=(100, -1),
                         action=self.onHyperText)

        steps = make_steps(prec=1, tmin=0, tmax=100)
        valx = NumericCombo(panel, steps, precision=1)

        self.choice1 = Choice(panel, size=(200, -1), action=self.onChoice)
        self.choice1.SetChoices(['Apple', 'Banana', 'Cherry'])

        yesno = YesNo(panel)

        check1 = Check(panel, label='enable? ', action=self.onCheck)

        btn1 = Button(panel,
                      label='Start',
                      size=(100, -1),
                      action=self.onStart)

        pinbtn = BitmapButton(panel,
                              get_icon('pin'),
                              size=(50, -1),
                              action=partial(self.onBMButton, opt='pin1'),
                              tooltip='use last point selected from plot')

        togbtn = ToggleButton(panel,
                              'Press Me',
                              action=self.onToggleButton,
                              size=(100, -1),
                              tooltip='do it, do it now, you will like it')

        browse_btn = Button(panel,
                            'Open File',
                            action=self.onFileOpen,
                            size=(150, -1))

        okcancel = OkCancel(panel, onOK=self.onOK, onCancel=self.onCancel)

        ptable_btn = Button(panel,
                            'Show Periodic Table',
                            action=self.onPTable,
                            size=(175, -1))

        edlist_btn = Button(panel,
                            'Show Editable Listbox',
                            action=self.onEdList,
                            size=(175, -1))

        filelist_btn = Button(panel,
                              'Show File CheckList',
                              action=self.onFileList,
                              size=(175, -1))

        panel.AddText(' Name: ', style=LEFT)

        panel.Add(tctrl_name, dcol=2)
        panel.Add(lctrl_addr.label, newrow=True)
        panel.Add(lctrl_addr, dcol=2)

        panel.Add(lab3, newrow=True)
        panel.Add(val3, dcol=3)

        panel.Add(lab4, newrow=True)
        panel.Add(val4, dcol=3)

        panel.Add(labx, newrow=True)
        panel.Add(valx, dcol=3)

        panel.AddText(' Choice : ', newrow=True)
        panel.Add(check1)
        panel.Add(self.choice1)
        panel.AddText(' Yes or No: ', newrow=True)
        panel.Add(yesno)
        panel.Add(HLine(panel, size=(500, -1)), dcol=3, newrow=True)

        panel.Add(btn1, newrow=True)
        panel.Add(pinbtn)
        panel.Add(togbtn)

        panel.Add(browse_btn, newrow=True)
        panel.Add(ptable_btn)
        panel.Add(edlist_btn, newrow=True)
        panel.Add(filelist_btn)

        panel.Add(okcancel, newrow=True)

        panel.pack()

        self.timer = wx.Timer(self)
        self.last_time = time.time()
        self.Bind(wx.EVT_TIMER, self.onTimer, self.timer)

        fsizer = wx.BoxSizer(wx.VERTICAL)
        fsizer.Add(panel, 0, LEFT | wx.EXPAND)
        wx.CallAfter(self.init_timer)

        psize = panel.GetBestSize()
        self.SetSize((psize[0] + 5, psize[1] + 25))

        pack(self, fsizer)
        self.Refresh()
示例#12
0
    def build_display(self):
        self.SetFont(Font(10))
        titleopts = dict(font=Font(11), colour='#AA0000')

        xas = self.xaspanel = GridPanel(self,
                                        ncols=4,
                                        nrows=4,
                                        pad=2,
                                        itemstyle=LCEN)

        self.plotone_op = Choice(xas,
                                 choices=list(PlotOne_Choices.keys()),
                                 action=self.onPlotOne,
                                 size=(200, -1))
        self.plotsel_op = Choice(xas,
                                 choices=list(PlotSel_Choices.keys()),
                                 action=self.onPlotSel,
                                 size=(200, -1))

        self.plotone_op.SetStringSelection('Normalized')
        self.plotsel_op.SetStringSelection('Normalized')

        plot_one = Button(xas,
                          'Plot This Group',
                          size=(150, -1),
                          action=self.onPlotOne)

        plot_sel = Button(xas,
                          'Plot Selected Groups',
                          size=(150, -1),
                          action=self.onPlotSel)

        self.btns = {}

        opts = dict(action=self.onReprocess)

        self.deconv_ewid = FloatCtrl(xas,
                                     value=0.5,
                                     precision=2,
                                     minval=0,
                                     size=(50, -1),
                                     **opts)

        self.deconv_form = Choice(xas,
                                  choices=DECONV_OPS,
                                  size=(100, -1),
                                  **opts)

        e0opts_panel = wx.Panel(xas)
        self.xas_autoe0 = Check(e0opts_panel,
                                default=True,
                                label='auto?',
                                **opts)
        self.xas_showe0 = Check(e0opts_panel,
                                default=True,
                                label='show?',
                                **opts)
        sx = wx.BoxSizer(wx.HORIZONTAL)
        sx.Add(self.xas_autoe0, 0, LCEN, 4)
        sx.Add(self.xas_showe0, 0, LCEN, 4)
        pack(e0opts_panel, sx)

        self.xas_autostep = Check(xas, default=True, label='auto?', **opts)

        for name in ('e0', 'pre1', 'pre2', 'nor1', 'nor2'):
            bb = BitmapButton(xas,
                              get_icon('plus'),
                              action=partial(self.on_selpoint, opt=name),
                              tooltip='use last point selected from plot')
            self.btns[name] = bb

        opts['size'] = (50, -1)
        self.xas_vict = Choice(xas, choices=('0', '1', '2', '3'), **opts)
        self.xas_nnor = Choice(xas, choices=('0', '1', '2', '3'), **opts)
        self.xas_vict.SetSelection(1)
        self.xas_nnor.SetSelection(1)

        opts.update({'size': (75, -1), 'precision': 1})

        self.xas_pre1 = FloatCtrl(xas, value=-np.inf, **opts)
        self.xas_pre2 = FloatCtrl(xas, value=-30, **opts)
        self.xas_nor1 = FloatCtrl(xas, value=50, **opts)
        self.xas_nor2 = FloatCtrl(xas, value=np.inf, **opts)

        opts = {'size': (75, -1), 'gformat': True}
        self.xas_e0 = FloatCtrl(xas, value=0, action=self.onSet_XASE0, **opts)
        self.xas_step = FloatCtrl(xas,
                                  value=0,
                                  action=self.onSet_XASStep,
                                  **opts)

        saveconf = Button(xas,
                          'Save as Default Settings',
                          size=(200, -1),
                          action=self.onSaveConfigBtn)

        def CopyBtn(name):
            return Button(xas,
                          'Copy',
                          size=(50, -1),
                          action=partial(self.onCopyParam, name))

        xas.Add(SimpleText(xas, ' XAS Pre-edge subtraction and Normalization',
                           **titleopts),
                dcol=6)
        xas.Add(SimpleText(xas, ' Copy to Selected Groups?'),
                style=RCEN,
                dcol=3)

        xas.Add(plot_sel, newrow=True)
        xas.Add(self.plotsel_op, dcol=6)

        xas.Add(plot_one, newrow=True)
        xas.Add(self.plotone_op, dcol=6)
        xas.Add((10, 10))
        xas.Add(CopyBtn('plotone_op'), style=RCEN)

        xas.Add(SimpleText(xas, 'E0 : '), newrow=True)
        xas.Add(self.btns['e0'])
        xas.Add(self.xas_e0)
        xas.Add(e0opts_panel, dcol=4)
        xas.Add((10, 1))
        xas.Add(CopyBtn('xas_e0'), style=RCEN)

        xas.Add(SimpleText(xas, 'Edge Step: '), newrow=True)
        xas.Add((10, 1))
        xas.Add(self.xas_step)
        xas.Add(self.xas_autostep, dcol=3)
        xas.Add((10, 1))
        xas.Add((10, 1))
        xas.Add(CopyBtn('xas_step'), style=RCEN)

        xas.Add(SimpleText(xas, 'Pre-edge range: '), newrow=True)
        xas.Add(self.btns['pre1'])
        xas.Add(self.xas_pre1)
        xas.Add(SimpleText(xas, ':'))
        xas.Add(self.btns['pre2'])
        xas.Add(self.xas_pre2)
        xas.Add(SimpleText(xas, 'Victoreen:'))
        xas.Add(self.xas_vict)
        xas.Add(CopyBtn('xas_pre'), style=RCEN)

        xas.Add(SimpleText(xas, 'Normalization range: '), newrow=True)
        xas.Add(self.btns['nor1'])
        xas.Add(self.xas_nor1)
        xas.Add(SimpleText(xas, ':'))
        xas.Add(self.btns['nor2'])
        xas.Add(self.xas_nor2)
        xas.Add(SimpleText(xas, 'Poly Order:'))
        xas.Add(self.xas_nnor)
        xas.Add(CopyBtn('xas_norm'), style=RCEN)

        xas.Add(SimpleText(xas, ' Deconvolution:'), newrow=True)
        xas.Add(self.deconv_form, dcol=5)
        xas.Add(SimpleText(xas, 'Energy width:'))
        xas.Add(self.deconv_ewid)
        xas.Add(CopyBtn('deconv'), style=RCEN)

        xas.Add(saveconf, dcol=6, newrow=True)
        xas.pack()

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add((5, 5), 0, LCEN, 3)
        sizer.Add(HLine(self, size=(550, 2)), 0, LCEN, 3)
        sizer.Add(xas, 0, LCEN, 3)
        sizer.Add((5, 5), 0, LCEN, 3)
        sizer.Add(HLine(self, size=(550, 2)), 0, LCEN, 3)
        pack(self, sizer)
示例#13
0
    def __init__(self, parent, mca, size=(-1, -1), callback=None):
        self.mca = mca
        self.callback = callback
        wx.Frame.__init__(self,
                          parent,
                          -1,
                          'Calibrate MCA',
                          size=size,
                          style=wx.DEFAULT_FRAME_STYLE)

        opanel = scrolled.ScrolledPanel(self)
        osizer = wx.BoxSizer(wx.VERTICAL)
        panel = GridPanel(opanel)
        self.calib_updated = False
        panel.AddText("Calibrate MCA Energy (Energies in eV)",
                      colour='#880000',
                      dcol=7)
        panel.AddText("ROI", newrow=True, style=CEN)
        panel.AddText("Predicted", style=CEN)
        panel.AddText("Peaks with Current Calibration", dcol=3, style=CEN)
        panel.AddText("Peaks with Refined Calibration", dcol=3, style=CEN)

        panel.AddText("Name", newrow=True, style=CEN)
        panel.AddText("Energy", style=CEN)
        panel.AddText("Center", style=CEN)
        panel.AddText("Difference", style=CEN)
        panel.AddText("FWHM", style=CEN)
        panel.AddText("Center", style=CEN)
        panel.AddText("Difference", style=CEN)
        panel.AddText("FWHM", style=CEN)
        panel.AddText("Use? ", style=CEN)

        panel.Add(HLine(panel, size=(700, 3)), dcol=9, newrow=True)
        self.wids = []

        # find ROI peak positions
        self.init_wids = {}
        for roi in self.mca.rois:
            eknown, ecen, fwhm = 1, 1, 1

            words = roi.name.split()
            elem = words[0].title()
            family = 'ka'
            if len(words) > 1:
                family = words[1]
            try:
                eknown = xray_line(elem, family).energy / 1000.0
            except (AttributeError, ValueError):
                eknown = 0.0001
            mid = (roi.right + roi.left) / 2
            wid = (roi.right - roi.left) / 2
            ecen = mid * mca.slope + mca.offset
            fwhm = 2.354820 * wid * mca.slope

            diff = ecen - eknown
            name = ('   ' + roi.name + ' ' * 10)[:10]
            opts = {'style': CEN, 'size': (75, -1)}
            w_name = SimpleText(panel, name, **opts)
            w_pred = SimpleText(panel, "% .1f" % (1000 * eknown), **opts)
            w_ccen = SimpleText(panel, "% .1f" % (1000 * ecen), **opts)
            w_cdif = SimpleText(panel, "% .1f" % (1000 * diff), **opts)
            w_cwid = SimpleText(panel, "% .1f" % (1000 * fwhm), **opts)
            w_ncen = SimpleText(panel, "-----", **opts)
            w_ndif = SimpleText(panel, "-----", **opts)
            w_nwid = SimpleText(panel, "-----", **opts)
            w_use = Check(panel, label='', size=(40, -1), default=0)
            panel.Add(w_name, style=LEFT, newrow=True)
            panel.AddMany((w_pred, w_ccen, w_cdif, w_cwid, w_ncen, w_ndif,
                           w_nwid, w_use))
            self.init_wids[roi.name] = [
                False, w_pred, w_ccen, w_cdif, w_cwid, w_use
            ]
            self.wids.append(
                (roi.name, eknown, ecen, w_ncen, w_ndif, w_nwid, w_use))

        panel.Add(HLine(panel, size=(700, 3)), dcol=9, newrow=True)
        offset = 1000.0 * self.mca.offset
        slope = 1000.0 * self.mca.slope
        panel.AddText("Current Calibration:", dcol=2, newrow=True)
        panel.AddText("offset(eV):")
        panel.AddText("%.3f" % (offset), dcol=1, style=RIGHT)
        panel.AddText("slope(eV/chan):")
        panel.AddText("%.3f" % (slope), dcol=1, style=RIGHT)

        panel.AddText("Refined Calibration:", dcol=2, newrow=True)
        self.new_offset = FloatCtrl(panel,
                                    value=offset,
                                    precision=3,
                                    size=(80, -1))
        self.new_slope = FloatCtrl(panel,
                                   value=slope,
                                   precision=3,
                                   size=(80, -1))
        panel.AddText("offset(eV):")
        panel.Add(self.new_offset, dcol=1, style=RIGHT)
        panel.AddText("slope(eV/chan):")
        panel.Add(self.new_slope, dcol=1, style=RIGHT)

        self.calib_btn = Button(panel,
                                'Compute Calibration',
                                size=(175, -1),
                                action=self.onCalibrate)
        self.calib_btn.Disable()
        panel.Add(self.calib_btn, dcol=3, newrow=True)
        panel.Add(Button(panel,
                         'Use New Calibration',
                         size=(175, -1),
                         action=self.onUseCalib),
                  dcol=3,
                  style=RIGHT)
        panel.Add(Button(panel, 'Done', size=(125, -1), action=self.onClose),
                  dcol=2,
                  style=RIGHT)
        panel.pack()
        a = panel.GetBestSize()
        self.SetSize((a[0] + 25, a[1] + 50))
        osizer.Add(panel)
        pack(opanel, osizer)
        opanel.SetupScrolling()
        self.Show()
        self.Raise()
        self.init_proc = False
        self.init_t0 = time.time()
        self.init_timer = wx.Timer(self)
        self.Bind(wx.EVT_TIMER, self.onInitTimer, self.init_timer)
        self.init_timer.Start(2)
示例#14
0
    def __init__(self, parent, size=(475, 325), **kws):
        self.parent = parent
        conf = parent.conf
        kws['style'] = wx.DEFAULT_FRAME_STYLE
        wx.Frame.__init__(self,
                          parent,
                          -1,
                          size=size,
                          title='XRF Line Selection',
                          **kws)
        panel = GridPanel(self)
        self.checkbox = {}

        def add_elines(panel, lines, checked):
            for i in lines:
                cb = Check(panel,
                           '%s ' % i,
                           default=i in checked,
                           action=partial(self.onLine, label=i, lines=checked))
                self.checkbox[i] = cb
                panel.Add(cb, style=LEFT)

        hopts = {'size': (125, -1), 'bgcolour': (250, 250, 200)}
        labopts = {'newrow': True, 'style': LEFT}
        self.linedata = {
            'Major K Lines:': self.k1lines,
            'Minor K Lines:': self.k2lines,
            'Major L Lines:': self.l1lines,
            'Minor L Lines:': self.l2lines + self.l3lines,
            'Major M Lines:': self.mlines
        }
        panel.AddText(' Select X-ray Emission Lines', dcol=4, colour='#880000')
        panel.Add(HLine(panel, size=(450, 3)), dcol=5, newrow=True)

        panel.Add(
            HyperText(panel,
                      'Major K Lines:',
                      action=partial(self.ToggleLines, lines=conf.K_major),
                      **hopts), **labopts)
        add_elines(panel, self.k1lines, conf.K_major)

        panel.Add(
            HyperText(panel,
                      'Minor K Lines:',
                      action=partial(self.ToggleLines, lines=conf.K_minor),
                      **hopts), **labopts)
        add_elines(panel, self.k2lines, conf.K_minor)

        panel.Add(
            HyperText(panel,
                      'Major L Lines:',
                      action=partial(self.ToggleLines, lines=conf.L_major),
                      **hopts), **labopts)
        add_elines(panel, self.l1lines, conf.L_major)

        panel.Add(
            HyperText(panel,
                      'Minor L Lines:',
                      action=partial(self.ToggleLines, lines=conf.L_minor),
                      **hopts), **labopts)
        add_elines(panel, self.l2lines, conf.L_minor)

        panel.AddText(' ', **labopts)
        add_elines(panel, self.l3lines, conf.L_minor)

        panel.Add(
            HyperText(panel,
                      'Major M Lines:',
                      action=partial(self.ToggleLines, lines=conf.M_major),
                      **hopts), **labopts)
        add_elines(panel, self.mlines, conf.M_major)

        panel.AddText('Energy Range (keV): ', **labopts)
        fopts = {'minval': 0, 'maxval': 1000, 'precision': 2, 'size': (75, -1)}
        panel.Add(FloatCtrl(panel,
                            value=conf.e_min,
                            action=partial(self.onErange, is_max=False),
                            **fopts),
                  dcol=2,
                  style=LEFT)

        panel.AddText(' : ')
        panel.Add(FloatCtrl(panel,
                            value=conf.e_max,
                            action=partial(self.onErange, is_max=True),
                            **fopts),
                  dcol=2,
                  style=LEFT)

        panel.Add(HLine(panel, size=(450, 3)), dcol=5, newrow=True)
        panel.Add(Button(panel, 'Done', size=(80, -1), action=self.onDone),
                  newrow=True,
                  style=LEFT)
        panel.pack()
        self.Show()
        self.Raise()
示例#15
0
    def __init__(self, parent, mca, larch=None, size=(-1, -1), callback=None):
        self.mca = mca
        self.larch = larch
        self.callback = callback
        wx.Frame.__init__(self,
                          parent,
                          -1,
                          'Calibrate MCA',
                          size=size,
                          style=wx.DEFAULT_FRAME_STYLE)

        self.SetFont(Font(8))
        panel = GridPanel(self)
        self.calib_updated = False
        panel.AddText("Calibrate MCA Energy (Energies in eV)",
                      colour='#880000',
                      dcol=7)
        panel.AddText("ROI", newrow=True, style=CEN)
        panel.AddText("Predicted", style=CEN)
        panel.AddText("Peaks with Current Calibration", dcol=3, style=CEN)
        panel.AddText("Peaks with Refined Calibration", dcol=3, style=CEN)

        panel.AddText("Name", newrow=True, style=CEN)
        panel.AddText("Energy", style=CEN)
        panel.AddText("Center", style=CEN)
        panel.AddText("Difference", style=CEN)
        panel.AddText("FWHM", style=CEN)
        panel.AddText("Center", style=CEN)
        panel.AddText("Difference", style=CEN)
        panel.AddText("FWHM", style=CEN)
        panel.AddText("Use? ", style=CEN)

        panel.Add(HLine(panel, size=(700, 3)), dcol=9, newrow=True)
        self.wids = []

        # find ROI peak positions
        xrf_calib_fitrois(mca, _larch=self.larch)

        for roi in self.mca.rois:
            try:
                eknown, ecen, fwhm, amp, fit = mca.init_calib[roi.name]
            except:
                continue
            diff = ecen - eknown
            name = ('   ' + roi.name + ' ' * 10)[:10]
            opts = {'style': CEN, 'size': (75, -1)}
            w_name = SimpleText(panel, name, **opts)
            w_pred = SimpleText(panel, "% .1f" % (1000 * eknown), **opts)
            w_ccen = SimpleText(panel, "% .1f" % (1000 * ecen), **opts)
            w_cdif = SimpleText(panel, "% .1f" % (1000 * diff), **opts)
            w_cwid = SimpleText(panel, "% .1f" % (1000 * fwhm), **opts)
            w_ncen = SimpleText(panel, "-----", **opts)
            w_ndif = SimpleText(panel, "-----", **opts)
            w_nwid = SimpleText(panel, "-----", **opts)
            w_use = Check(panel,
                          label='use?',
                          size=(40, -1),
                          default=fwhm < 0.50)

            panel.Add(w_name, style=LEFT, newrow=True)
            panel.AddMany((w_pred, w_ccen, w_cdif, w_cwid, w_ncen, w_ndif,
                           w_nwid, w_use))

            self.wids.append(
                (roi.name, eknown, ecen, w_ncen, w_ndif, w_nwid, w_use))

        panel.Add(HLine(panel, size=(700, 3)), dcol=9, newrow=True)
        offset = 1000.0 * self.mca.offset
        slope = 1000.0 * self.mca.slope
        panel.AddText("Current Calibration:", dcol=2, newrow=True)
        panel.AddText("offset(eV):")
        panel.AddText("%.3f" % (offset), dcol=1, style=RIGHT)
        panel.AddText("slope(eV/chan):")
        panel.AddText("%.3f" % (slope), dcol=1, style=RIGHT)

        panel.AddText("Refined Calibration:", dcol=2, newrow=True)
        self.new_offset = FloatCtrl(panel,
                                    value=offset,
                                    precision=3,
                                    size=(80, -1))
        self.new_slope = FloatCtrl(panel,
                                   value=slope,
                                   precision=3,
                                   size=(80, -1))
        panel.AddText("offset(eV):")
        panel.Add(self.new_offset, dcol=1, style=RIGHT)
        panel.AddText("slope(eV/chan):")
        panel.Add(self.new_slope, dcol=1, style=RIGHT)

        panel.Add(Button(panel,
                         'Compute Calibration',
                         size=(125, -1),
                         action=self.onCalibrate),
                  dcol=2,
                  newrow=True)

        panel.Add(Button(panel,
                         'Use New Calibration',
                         size=(125, -1),
                         action=self.onUseCalib),
                  dcol=2,
                  style=RIGHT)

        panel.Add(Button(panel, 'Done', size=(125, -1), action=self.onClose),
                  dcol=2,
                  style=RIGHT)

        panel.pack()
        a = panel.GetBestSize()
        self.SetSize((a[0] + 25, a[1] + 50))
        self.Show()
        self.Raise()
示例#16
0
    def build_display(self):
        self.SetFont(Font(10))
        titleopts = dict(font=Font(11), colour='#AA0000')

        gopts = dict(ncols=4, nrows=4, pad=2, itemstyle=LCEN)
        xas = self.xaspanel = GridPanel(self, **gopts)
        gen = self.genpanel = GridPanel(self, **gopts)
        self.btns = {}
        #gen
        opts  = dict(action=self.UpdatePlot, size=(65, -1), gformat=True)

        self.xshift = FloatCtrl(gen, value=0.0, **opts)
        self.xscale = FloatCtrl(gen, value=1.0, **opts)

        self.yshift = FloatCtrl(gen, value=0.0, **opts)
        self.yscale = FloatCtrl(gen, value=1.0, **opts)

        self.btns['xshift'] = BitmapButton(gen, get_icon('plus'),
                                           action=partial(self.on_selpoint, opt='xshift'),
                                           tooltip='use last point selected from plot')
        self.btns['yshift'] = BitmapButton(gen, get_icon('plus'),
                                           action=partial(self.on_selpoint, opt='yshift'),
                                           tooltip='use last point selected from plot')

        opts  = dict(action=self.onSmoothChoice, size=(30, -1))
        sm_row1 = wx.Panel(gen)
        sm_row2 = wx.Panel(gen)
        sm_siz1= wx.BoxSizer(wx.HORIZONTAL)
        sm_siz2= wx.BoxSizer(wx.HORIZONTAL)

        self.smooth_c0 = FloatCtrl(sm_row1, value=2, precision=0, minval=1, **opts)
        self.smooth_c1 = FloatCtrl(sm_row1, value=1, precision=0, minval=1, **opts)
        self.smooth_msg = SimpleText(sm_row1, label='         ', size=(205, -1))
        opts['size'] =  (65, -1)
        self.smooth_sig = FloatCtrl(sm_row2, value=1, gformat=True, **opts)

        opts['size'] =  (120, -1)
        self.smooth_op = Choice(sm_row1, choices=SMOOTH_OPS, **opts)
        self.smooth_op.SetSelection(0)

        self.smooth_conv = Choice(sm_row2, choices=CONV_OPS, **opts)

        self.smooth_c0.Disable()
        self.smooth_c1.Disable()
        self.smooth_sig.Disable()
        self.smooth_conv.SetSelection(0)
        self.smooth_conv.Disable()

        sm_siz1.Add(self.smooth_op,  0, LCEN, 1)
        sm_siz1.Add(SimpleText(sm_row1, ' n= '), 0, LCEN, 1)
        sm_siz1.Add(self.smooth_c0,  0, LCEN, 1)
        sm_siz1.Add(SimpleText(sm_row1, ' order= '), 0, LCEN, 1)
        sm_siz1.Add(self.smooth_c1,  0, LCEN, 1)
        sm_siz1.Add(self.smooth_msg, 0, LCEN, 1)

        sm_siz2.Add(SimpleText(sm_row2, ' form= '), 0, LCEN, 1)
        sm_siz2.Add(self.smooth_conv,  0, LCEN, 1)
        sm_siz2.Add(SimpleText(sm_row2, ' sigma= '), 0, LCEN, 1)
        sm_siz2.Add(self.smooth_sig,  0, LCEN, 1)
        pack(sm_row1, sm_siz1)
        pack(sm_row2, sm_siz2)

        gen.Add(SimpleText(gen, ' General Data Processing', **titleopts), dcol=8)
        gen.Add(SimpleText(gen, ' X shift:'),  newrow=True)
        gen.Add(self.btns['xshift'])
        gen.Add(self.xshift, dcol=2)
        gen.Add(SimpleText(gen, ' X scale:'))
        gen.Add(self.xscale, dcol=2)

        gen.Add(SimpleText(gen, ' Y shift:'),  newrow=True)
        gen.Add(self.btns['yshift'])
        gen.Add(self.yshift, dcol=2)
        gen.Add(SimpleText(gen, ' Y scale:'))
        gen.Add(self.yscale, dcol=2)

        gen.Add(SimpleText(gen, ' Smoothing:'), newrow=True)
        gen.Add(sm_row1, dcol=8)
        gen.Add(sm_row2, icol=1, dcol=7, newrow=True)

        gen.pack()

        #xas
        opts = {'action': self.UpdatePlot}
        e0opts_panel = wx.Panel(xas)
        self.xas_autoe0   = Check(e0opts_panel, default=True, label='auto?', **opts)
        self.xas_showe0   = Check(e0opts_panel, default=True, label='show?', **opts)
        sx = wx.BoxSizer(wx.HORIZONTAL)
        sx.Add(self.xas_autoe0, 0, LCEN, 4)
        sx.Add(self.xas_showe0, 0, LCEN, 4)
        pack(e0opts_panel, sx)

        self.xas_autostep = Check(xas, default=True, label='auto?', **opts)
        opts['size'] = (250, -1)
        self.xas_op  = Choice(xas, choices=XASOPChoices,  **opts)

        self.xas_op.SetStringSelection('Normalized')

        for name in ('e0', 'pre1', 'pre2', 'nor1', 'nor2'):
            bb = BitmapButton(xas, get_icon('plus'),
                              action=partial(self.on_selpoint, opt=name),
                              tooltip='use last point selected from plot')
            self.btns[name] = bb

        opts = {'size': (65, -1), 'gformat': True}

        self.xas_e0   = FloatCtrl(xas, value=0, action=self.onSet_XASE0, **opts)
        self.xas_step = FloatCtrl(xas, value=0, action=self.onSet_XASStep, **opts)

        opts['precision'] = 1
        opts['action'] =  self.UpdatePlot
        self.xas_pre1 = FloatCtrl(xas, value=-200, **opts)
        self.xas_pre2 = FloatCtrl(xas, value= -30, **opts)
        self.xas_nor1 = FloatCtrl(xas, value=  50, **opts)
        self.xas_nor2 = FloatCtrl(xas, value= -50, **opts)

        opts = {'size': (50, -1),
                'choices': ('0', '1', '2', '3'),
                'action': self.UpdatePlot}
        self.xas_vict = Choice(xas, **opts)
        self.xas_nnor = Choice(xas, **opts)
        self.xas_vict.SetSelection(1)
        self.xas_nnor.SetSelection(1)

        def CopyBtn(name):
            return Button(xas, 'Copy', size=(50, 30),
                          action=partial(self.onCopyParam, name))


        xas.Add(SimpleText(xas, ' XAS Data Processing', **titleopts), dcol=6)
        xas.Add(SimpleText(xas, ' Copy to Selected Groups?'), style=RCEN, dcol=3)
        xas.Add(SimpleText(xas, 'Arrays to Plot: '),  newrow=True)
        xas.Add(self.xas_op,  dcol=6)
        xas.Add((10, 10))
        xas.Add(CopyBtn('xas_op'), style=RCEN)

        xas.Add(SimpleText(xas, 'E0 : '), newrow=True)
        xas.Add(self.btns['e0'])
        xas.Add(self.xas_e0)
        xas.Add(e0opts_panel, dcol=4)
        xas.Add((10, 1))
        xas.Add(CopyBtn('xas_e0'), style=RCEN)

        xas.Add(SimpleText(xas, 'Edge Step: '), newrow=True)
        xas.Add((10, 1))
        xas.Add(self.xas_step)
        xas.Add(self.xas_autostep, dcol=3)
        xas.Add((10, 1))
        xas.Add((10, 1))
        xas.Add(CopyBtn('xas_step'), style=RCEN)

        xas.Add(SimpleText(xas, 'Pre-edge range: '), newrow=True)
        xas.Add(self.btns['pre1'])
        xas.Add(self.xas_pre1)
        xas.Add(SimpleText(xas, ':'))
        xas.Add(self.btns['pre2'])
        xas.Add(self.xas_pre2)
        xas.Add(SimpleText(xas, 'Victoreen:'))
        xas.Add(self.xas_vict)
        xas.Add(CopyBtn('xas_pre'), style=RCEN)

        xas.Add(SimpleText(xas, 'Normalization range: '), newrow=True)
        xas.Add(self.btns['nor1'])
        xas.Add(self.xas_nor1)
        xas.Add(SimpleText(xas, ':'))
        xas.Add(self.btns['nor2'])
        xas.Add(self.xas_nor2)
        xas.Add(SimpleText(xas, 'PolyOrder:'))
        xas.Add(self.xas_nnor)
        xas.Add(CopyBtn('xas_norm'), style=RCEN)

        xas.pack()

        saveconf = Button(self, 'Save as Default Settings',
                          size=(175, 30),
                          action=self.onSaveConfigBtn)

        hxline = HLine(self, size=(550, 2))

        sizer = wx.BoxSizer(wx.VERTICAL)

        sizer.AddMany([((10, 10), 0, LCEN, 10), (gen,      0, LCEN, 10),
                       ((10, 10), 0, LCEN, 10), (hxline,   0, LCEN, 10),
                       ((10, 10), 0, LCEN, 10), (xas,      0, LCEN, 10),
                       ((10, 10), 0, LCEN, 10), (saveconf, 0, LCEN, 10),
                       ])

        xas.Disable()

        pack(self, sizer)
示例#17
0
    def __init__(self, parent, param, precision=4, vary=None, **kws):
        self.param = param
        title = "  Parameter:  %s  " % (param.name)
        wx.Dialog.__init__(self, parent, wx.ID_ANY, title=title)
        panel = GridPanel(self)
        self.SetFont(parent.GetFont())

        if vary is None:
            vary = 0
            if param.vary:
                vary = 1
            elif param.expr is not None:
                vary = 2

        minval, maxval = param.min, param.max
        stderr, expr = param.stderr, param.expr
        sminval = "%s" % minval
        smaxval = "%s" % maxval
        if minval in (None, 'None', -np.inf): minval = -np.inf
        if maxval in (None, 'None', np.inf): maxval = np.inf
        if stderr is None: stderr = ''
        if expr is None: expr = ''

        self.wids = Empty()
        self.wids.vary = Choice(panel,
                                choices=VARY_CHOICES,
                                action=self.onVaryChoice,
                                size=(110, -1))
        self.wids.vary.SetSelection(vary)

        self.wids.val = FloatCtrl(panel,
                                  value=param.value,
                                  size=(100, -1),
                                  precision=precision,
                                  minval=minval,
                                  maxval=maxval)
        self.wids.min = FloatCtrl(panel, value=minval, size=(100, -1))
        self.wids.max = FloatCtrl(panel, value=maxval, size=(100, -1))
        self.wids.expr = wx.TextCtrl(panel, value=expr, size=(300, -1))
        self.wids.err = wx.StaticText(panel, label="%s" % stderr)

        SetTip(self.wids.expr, "Mathematical expression to calcutate value")

        btnsizer = wx.StdDialogButtonSizer()
        ok_btn = wx.Button(panel, wx.ID_OK)
        ok_btn.SetDefault()
        btnsizer.AddButton(ok_btn)
        btnsizer.AddButton(wx.Button(panel, wx.ID_CANCEL))
        btnsizer.Realize()

        panel.AddText(' Name:', style=LEFT)
        panel.AddText(param.name, style=LEFT)
        panel.AddText(' Type:', style=LEFT)
        panel.Add(self.wids.vary, style=LEFT)
        panel.AddText(' Value:', style=LEFT, newrow=True)
        panel.Add(self.wids.val, style=LEFT)
        panel.AddText(' Std Error:', style=LEFT)
        panel.Add(self.wids.err, style=LEFT)
        panel.AddText(' Min Value:', style=LEFT, newrow=True)
        panel.Add(self.wids.min, style=LEFT)
        panel.AddText(' Max Value:', style=LEFT)
        panel.Add(self.wids.max, style=LEFT)
        panel.AddText(' Constraint:', style=LEFT, newrow=True)
        panel.Add(self.wids.expr, style=LEFT, dcol=3)

        panel.Add(HLine(panel, size=(375, 2)), dcol=4, newrow=True)
        panel.Add(btnsizer, dcol=4, newrow=True, style=LEFT)
        panel.pack()

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(panel, 0, 0, 25)
        self.onVaryChoice()
        pack(self, sizer)
        bsize = self.GetBestSize()
        self.SetSize((bsize[0] + 10, bsize[1] + 10))
示例#18
0
    def build_display(self):
        self.mod_nb = flat_nb.FlatNotebook(self, -1, agwStyle=FNB_STYLE)
        self.mod_nb.SetTabAreaColour(wx.Colour(250,250,250))
        self.mod_nb.SetActiveTabColour(wx.Colour(254,254,195))

        self.mod_nb.SetNonActiveTabTextColour(wx.Colour(10,10,128))
        self.mod_nb.SetActiveTabTextColour(wx.Colour(128,0,0))
        self.mod_nb.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, self.onNBChanged)

        pan = self.panel = GridPanel(self, ncols=4, nrows=4, pad=2, itemstyle=LCEN)

        self.btns = {}
        for name in ('ppeak_e0', 'ppeak_elo', 'ppeak_emin', 'ppeak_emax', 'ppeak_ehi'):
            bb = BitmapButton(pan, get_icon('plus'),
                              action=partial(self.on_selpoint, opt=name),
                              tooltip='use last point selected from plot')
            self.btns[name] = bb

        opts = dict(size=(75, -1), gformat=True, precision=1)

        self.ppeak_e0   = FloatCtrl(pan, value=0, **opts)
        self.ppeak_emin = FloatCtrl(pan, value=-30, **opts)
        self.ppeak_emax = FloatCtrl(pan, value=0, **opts)
        self.ppeak_elo = FloatCtrl(pan, value=-15, **opts)
        self.ppeak_ehi = FloatCtrl(pan, value=-5, **opts)

        self.fitbline_btn  = Button(pan,'Fit Baseline', action=self.onFitBaseline,
                                    size=(150, 25))
        self.fitmodel_btn = Button(pan, 'Fit Model',
                                   action=self.onFitModel,  size=(150, 25))
        self.fitsel_btn = Button(pan, 'Fit Selected Groups',
                                 action=self.onFitSelected,  size=(150, 25))
        self.fitmodel_btn.Disable()
        self.fitsel_btn.Disable()

        self.array_choice = Choice(pan, size=(125, -1),
                                   choices=list(Array_Choices.keys()))
        self.array_choice.SetSelection(1)

        models_peaks = Choice(pan, size=(125, -1),
                              choices=ModelChoices['peaks'],
                              action=self.addModel)

        models_other = Choice(pan, size=(125, -1),
                              choices=ModelChoices['other'],
                              action=self.addModel)

        self.plot_choice = Choice(pan, size=(125, -1),
                                  choices=PlotChoices,
                                  action=self.onPlot)

        self.message = SimpleText(pan,
                                 'first fit baseline, then add peaks to fit model.')

        self.msg_centroid = SimpleText(pan, '----')

        opts = dict(default=True, size=(75, -1), action=self.onPlot)
        self.show_centroid  = Check(pan, label='show?', **opts)
        self.show_peakrange = Check(pan, label='show?', **opts)
        self.show_fitrange  = Check(pan, label='show?', **opts)
        self.show_e0        = Check(pan, label='show?', **opts)

        opts = dict(default=False, size=(200, -1), action=self.onPlot)
        self.plot_sub_bline = Check(pan, label='Subtract Baseline?', **opts)

        titleopts = dict(font=Font(11), colour='#AA0000')
        pan.Add(SimpleText(pan, ' Pre-edge Peak Fitting', **titleopts), dcol=7)
        pan.Add(SimpleText(pan, ' Run Fit:'), style=LCEN)

        pan.Add(SimpleText(pan, 'Array to fit: '), newrow=True)
        pan.Add(self.array_choice, dcol=4)
        pan.Add((10, 10), dcol=2)
        pan.Add(self.fitbline_btn)

        pan.Add(SimpleText(pan, 'E0: '), newrow=True)
        pan.Add(self.btns['ppeak_e0'])
        pan.Add(self.ppeak_e0)
        pan.Add((10, 10), dcol=3)
        pan.Add(self.show_e0)
        pan.Add(self.fitmodel_btn)


        pan.Add(SimpleText(pan, 'Fit Energy Range: '), newrow=True)
        pan.Add(self.btns['ppeak_emin'])
        pan.Add(self.ppeak_emin)
        pan.Add(SimpleText(pan, ':'))
        pan.Add(self.btns['ppeak_emax'])
        pan.Add(self.ppeak_emax)
        pan.Add(self.show_fitrange, dcol=1)
        pan.Add(self.fitsel_btn)



        t = SimpleText(pan, 'Pre-edge Peak Range: ')
        t.SetToolTip('Range used as mask for background')

        pan.Add(t, newrow=True)
        pan.Add(self.btns['ppeak_elo'])
        pan.Add(self.ppeak_elo)
        pan.Add(SimpleText(pan, ':'))
        pan.Add(self.btns['ppeak_ehi'])
        pan.Add(self.ppeak_ehi)
        pan.Add(self.show_peakrange, dcol=1)

        pan.Add(SimpleText(pan, 'Peak Centroid: '), newrow=True)
        pan.Add(self.msg_centroid, dcol=5)
        pan.Add(self.show_centroid, dcol=1)


        #  plot buttons
        ts = wx.BoxSizer(wx.HORIZONTAL)
        ts.Add(self.plot_choice)
        ts.Add(self.plot_sub_bline)

        pan.Add(SimpleText(pan, 'Plot: '), newrow=True)
        pan.Add(ts, dcol=7)

        #  add model
        ts = wx.BoxSizer(wx.HORIZONTAL)
        ts.Add(models_peaks)
        ts.Add(models_other)

        pan.Add(SimpleText(pan, 'Add Component: '), newrow=True)
        pan.Add(ts, dcol=7)

        pan.Add(SimpleText(pan, 'Messages: '), newrow=True)
        pan.Add(self.message, dcol=7)


        pan.pack()


        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add((5,5), 0, LCEN, 3)
        sizer.Add(HLine(self, size=(550, 2)), 0, LCEN, 3)
        sizer.Add(pan,   0, LCEN, 3)
        sizer.Add((5,5), 0, LCEN, 3)
        sizer.Add(HLine(self, size=(550, 2)), 0, LCEN, 3)
        sizer.Add((5,5), 0, LCEN, 3)
        sizer.Add(self.mod_nb,  1, LCEN|wx.GROW, 10)

        pack(self, sizer)