def createSearchPanel(self): searchpanel = wx.Panel(self, name='Search Panel') labstyle = wx.ALIGN_LEFT|wx.ALIGN_BOTTOM|wx.EXPAND ctrlstyle = wx.ALIGN_LEFT|wx.ALIGN_BOTTOM txtstyle=wx.ALIGN_LEFT|wx.ST_NO_AUTORESIZE|wx.TE_PROCESS_ENTER Font9 = Font(9) Font10 = Font(10) Font11 = Font(11) plttitle = txt(searchpanel, 'XRD Reference Data', font=Font11, size=200) loadpanel = wx.Panel(searchpanel, name='LoadPanel') lsizer = wx.BoxSizer(wx.HORIZONTAL) l1 = Button(loadpanel, 'Search Database', size=(120, 30), action=self.onSearchDB) l2 = Button(loadpanel, 'Load CIF', size=(120, 30), action=self.onLoadCIF) lsizer.Add(l1, 0, wx.EXPAND|wx.ALL, 0) lsizer.Add(l2, 0, wx.EXPAND|wx.ALL, 0) pack(loadpanel, lsizer) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(plttitle, 0, wx.ALIGN_RIGHT|wx.EXPAND|wx.ALL) sizer.Add(lin(searchpanel, 195), 0, labstyle) sizer.Add(loadpanel, 0, wx.ALIGN_RIGHT|wx.EXPAND|wx.ALL) sizer.Add(lin(searchpanel, 195), 0, labstyle) sizer.Add(lin(searchpanel, 195), 0, labstyle) pack(searchpanel, sizer) return searchpanel
def create_detbuttons(self, pane): btnpanel = wx.Panel(pane, name='buttons') btnsizer = wx.GridBagSizer(1, 1) btns = {} sx = 30 sy = int(sx / 2) for i in range(1, self.nmca + 1): b = Button(btnpanel, '%d' % i, size=(sx, sx), action=partial(self.onSelectDet, index=i)) b.SetFont(Font(10)) self.wids['det%i' % i] = b btns[i] = b dtype = self.det_type.lower().replace('-', '').replace(' ', '').replace('_', '') if dtype.startswith('sxd7') and self.nmca == 7: btnsizer.Add((sx, sy), (0, 0), (1, 2), wx.ALIGN_LEFT, 1) btnsizer.Add(btns[4], (1, 0), (2, 2), wx.ALIGN_LEFT, 1) btnsizer.Add(btns[5], (3, 0), (2, 2), wx.ALIGN_LEFT, 1) btnsizer.Add((sx, sy), (5, 0), (1, 2), wx.ALIGN_LEFT, 1) btnsizer.Add(btns[3], (0, 2), (2, 2), wx.ALIGN_LEFT, 1) btnsizer.Add(btns[7], (2, 2), (2, 2), wx.ALIGN_LEFT, 1) btnsizer.Add(btns[6], (4, 2), (2, 2), wx.ALIGN_LEFT, 1) btnsizer.Add((sx, sy), (0, 4), (1, 2), wx.ALIGN_LEFT, 1) btnsizer.Add(btns[2], (1, 4), (2, 2), wx.ALIGN_LEFT, 1) btnsizer.Add(btns[1], (3, 4), (2, 2), wx.ALIGN_LEFT, 1) btnsizer.Add((sx, sy), (5, 4), (1, 2), wx.ALIGN_LEFT, 1) elif dtype.startswith('me7') and self.nmca == 7: btnsizer.Add((sx, sy), (0, 0), (1, 2), wx.ALIGN_LEFT, 1) btnsizer.Add(btns[7], (1, 0), (2, 2), wx.ALIGN_LEFT, 1) btnsizer.Add(btns[6], (3, 0), (2, 2), wx.ALIGN_LEFT, 1) btnsizer.Add((sx, sy), (5, 0), (1, 2), wx.ALIGN_LEFT, 1) btnsizer.Add(btns[2], (0, 2), (2, 2), wx.ALIGN_LEFT, 1) btnsizer.Add(btns[1], (2, 2), (2, 2), wx.ALIGN_LEFT, 1) btnsizer.Add(btns[5], (4, 2), (2, 2), wx.ALIGN_LEFT, 1) btnsizer.Add((sx, sy), (0, 4), (1, 2), wx.ALIGN_LEFT, 1) btnsizer.Add(btns[3], (1, 4), (2, 2), wx.ALIGN_LEFT, 1) btnsizer.Add(btns[4], (3, 4), (2, 2), wx.ALIGN_LEFT, 1) btnsizer.Add((sx, sy), (5, 4), (1, 2), wx.ALIGN_LEFT, 1) elif dtype.startswith('me4') and self.nmca == 4: btnsizer.Add(btns[1], (0, 0), (1, 1), wx.ALIGN_LEFT, 1) btnsizer.Add(btns[2], (1, 0), (1, 1), wx.ALIGN_LEFT, 1) btnsizer.Add(btns[3], (1, 1), (1, 1), wx.ALIGN_LEFT, 1) btnsizer.Add(btns[4], (0, 1), (1, 1), wx.ALIGN_LEFT, 1) else: NPERROW = 4 icol, irow = 0, 0 for nmca in range(1, self.nmca + 1): btnsizer.Add(btns[nmca], (irow, icol), (1, 1), wx.ALIGN_LEFT, 1) icol += 1 if icol > NPERROW - 1: icol = 0 irow += 1 pack(btnpanel, btnsizer) return btnpanel
def __init__(self, parent, size=(675, 525)): self.parent = parent self.larch = parent.larch self.mca = parent.mca conf = parent.conf self.paramgroup = Group() if not hasattr(self.mca, 'init_calib'): xrf_calib_fitrois(self.mca, _larch=self.larch) wx.Frame.__init__(self, parent, -1, 'Fit XRF Spectra', size=size, style=wx.DEFAULT_FRAME_STYLE) if not hasattr(self.parent, 'filters_data'): self.parent.filters_data = read_filterdata(self.Filter_Materials, _larch=self.larch) self.wids = Empty() self.SetFont(Font(9)) self.panels = {} self.nb = flat_nb.FlatNotebook(self, wx.ID_ANY, agwStyle=FNB_STYLE) self.nb.SetBackgroundColour('#FBFBF8') self.SetBackgroundColour('#F6F6F0') self.nb.AddPage(self.settings_page(), 'Fit & Background Settings') self.nb.AddPage(self.filters_page(), 'Filters and Attenuation') self.nb.AddPage(self.fitpeaks_page(), 'XRF Peaks') self.nb.SetSelection(0) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(self.nb, 1, wx.ALL | wx.EXPAND) sizer.Add((5, 5)) sizer.Add(HLine(self, size=(675, 3)), 0, CEN | LEFT | wx.TOP | wx.GROW) sizer.Add((5, 5)) bpanel = RowPanel(self) bpanel.Add(Button(bpanel, 'Fit Peaks', action=self.onFitPeaks), 0, LEFT) bpanel.Add(Button(bpanel, 'Done', action=self.onClose), 0, LEFT) bpanel.pack() sizer.Add(bpanel, 0, CEN) pack(self, sizer) self.Show() self.Raise()
def CustomConfig(self, panel, sizer, irow): """config panel for left-hand-side of frame""" conf = self.panel.conf lpanel = panel lsizer = sizer labstyle = wx.ALIGN_LEFT|wx.LEFT|wx.TOP|wx.EXPAND self.zoom_mode = wx.RadioBox(panel, -1, "Cursor Mode:", wx.DefaultPosition, wx.DefaultSize, ('Zoom to Rectangle', 'Pick Area for XRF Spectrum', 'Show Line Profile'), 1, wx.RA_SPECIFY_COLS) self.zoom_mode.Bind(wx.EVT_RADIOBOX, self.onCursorMode) sizer.Add(self.zoom_mode, (irow, 0), (1, 4), labstyle, 3) if self.save_callback is not None: self.pos_name = wx.TextCtrl(panel, -1, '', size=(175, -1), style=wx.TE_PROCESS_ENTER) self.pos_name.Bind(wx.EVT_TEXT_ENTER, self.onSavePixel) label = SimpleText(panel, label='Save Position:', size=(-1, -1)) # sbutton = Button(panel, 'Save Position', size=(100, -1), # action=self.onSavePixel) sizer.Add(label, (irow+1, 0), (1, 2), labstyle, 3) sizer.Add(self.pos_name, (irow+1, 2), (1, 2), labstyle, 3) # sizer.Add(sbutton, (irow+2, 0), (1, 2), labstyle, 3) if self.move_callback is not None: mbutton = Button(panel, 'Move to Position', size=(100, -1), action=self.onMoveToPixel) irow = irow + 2 sizer.Add(mbutton, (irow+1, 0), (1, 2), labstyle, 3)
def createBkgdPanel(self): bkgdpanel = wx.Panel(self, name='Background Panel') labstyle = wx.ALIGN_LEFT|wx.ALIGN_BOTTOM|wx.EXPAND ctrlstyle = wx.ALIGN_LEFT|wx.ALIGN_BOTTOM txtstyle=wx.ALIGN_LEFT|wx.ST_NO_AUTORESIZE|wx.TE_PROCESS_ENTER Font9 = Font(9) Font10 = Font(10) Font11 = Font(11) plttitle = txt(bkgdpanel, 'Background Options', font=Font11, size=200) l1 = Check(bkgdpanel, 'Show background', action=self.onShowBkgd, default=False) l2 = Button(bkgdpanel, 'Subtract background', size=(90, 30), action=self.onSubBkgd) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(plttitle, 0, wx.ALIGN_RIGHT|wx.EXPAND|wx.ALL) sizer.Add(lin(bkgdpanel, 195), 0, labstyle) sizer.Add(l1, 0, wx.EXPAND|wx.ALL, 0) sizer.Add(l2, 0, wx.EXPAND|wx.ALL, 0) sizer.Add(lin(bkgdpanel, 195), 0, labstyle) sizer.Add(lin(bkgdpanel, 195), 0, labstyle) pack(bkgdpanel, sizer) return bkgdpanel
def createMainPanel(self): panel = wx.Panel(self) sizer = wx.GridBagSizer(5, 4) lab_roi = SimpleText(panel, ' Element / ROI Name') lab_out = SimpleText(panel, ' Output Folder:') lab_bad = SimpleText(panel, ' Bad Channels:') lab_sel = SimpleText(panel, ' Select Files:') self.roi_wid = wx.TextCtrl(panel, -1, '', size=(200, -1)) self.dir_wid = wx.TextCtrl(panel, -1, 'DT_Corrected', size=(200, -1)) self.badchans_wid = wx.TextCtrl(panel, -1, ' ', size=(200, -1)) self.sel_wid = Button(panel, 'Browse', size=(100, -1), action=self.onBrowse) ir = 0 sizer.Add(lab_roi, (ir, 0), (1, 1), LCEN, 2) sizer.Add(self.roi_wid, (ir, 1), (1, 1), LCEN, 2) ir += 1 sizer.Add(lab_out, (ir, 0), (1, 1), LCEN, 2) sizer.Add(self.dir_wid, (ir, 1), (1, 1), LCEN, 2) ir += 1 sizer.Add(lab_bad, (ir, 0), (1, 1), LCEN, 2) sizer.Add(self.badchans_wid, (ir, 1), (1, 1), LCEN, 2) ir += 1 sizer.Add(lab_sel, (ir, 0), (1, 1), LCEN, 2) sizer.Add(self.sel_wid, (ir, 1), (1, 1), LCEN, 2) pack(panel, sizer) wx.CallAfter(self.init_larch) return
def __init__(self, parent, group, on_ok=None): self.group = group self.on_ok = on_ok wx.Frame.__init__(self, None, -1, 'Edit Array Names', style=wx.DEFAULT_FRAME_STYLE | wx.TAB_TRAVERSAL) self.SetFont(Font(10)) sizer = wx.GridBagSizer(4, 4) self.SetMinSize((600, 600)) self.wids = {} cind = SimpleText(self, label='Column') cold = SimpleText(self, label='Current Name') cnew = SimpleText(self, label='Enter New Name') cret = SimpleText(self, label=' Result ', size=(150, -1)) cinfo = SimpleText(self, label=' Data Range') ir = 0 sizer.Add(cind, (ir, 0), (1, 1), LCEN, 3) sizer.Add(cold, (ir, 1), (1, 1), LCEN, 3) sizer.Add(cnew, (ir, 2), (1, 1), LCEN, 3) sizer.Add(cret, (ir, 3), (1, 1), LCEN, 3) sizer.Add(cinfo, (ir, 4), (1, 1), LCEN, 3) for i, name in enumerate(group.array_labels): ir += 1 cind = SimpleText(self, label=' %i ' % (i + 1)) cold = SimpleText(self, label=' %s ' % name) cret = SimpleText(self, label=fix_varname(name), size=(150, -1)) cnew = wx.TextCtrl(self, value=name, size=(150, -1)) cnew.Bind(wx.EVT_KILL_FOCUS, partial(self.update, index=i)) cnew.Bind(wx.EVT_CHAR, partial(self.update_char, index=i)) cnew.Bind(wx.EVT_TEXT_ENTER, partial(self.update, index=i)) # cnew.Bind(wx.EVT_TEXT, partial(self.update3, index=i)) arr = group.data[i, :] info_str = " [ %8g : %8g ] " % (arr.min(), arr.max()) cinfo = SimpleText(self, label=info_str) self.wids[i] = cnew self.wids["ret_%i" % i] = cret sizer.Add(cind, (ir, 0), (1, 1), LCEN, 3) sizer.Add(cold, (ir, 1), (1, 1), LCEN, 3) sizer.Add(cnew, (ir, 2), (1, 1), LCEN, 3) sizer.Add(cret, (ir, 3), (1, 1), LCEN, 3) sizer.Add(cinfo, (ir, 4), (1, 1), LCEN, 3) sizer.Add(Button(self, 'OK', action=self.onOK), (ir + 1, 1), (1, 2), LCEN, 3) pack(self, sizer) self.Show() self.Raise()
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
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()
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()
def createMainPanel(self): panel = wx.Panel(self) sizer = wx.GridBagSizer(5, 4) lab_roi = SimpleText(panel, ' Element / ROI Name:') lab_dir = SimpleText(panel, ' Output Folder:') lab_ath = SimpleText(panel, ' Athena Project File:') lab_bad = SimpleText(panel, ' Bad Channels:') lab_sel = SimpleText(panel, ' Select Files:') self.wid_roi = wx.TextCtrl(panel, -1, '', size=(200, -1)) self.wid_dir = wx.TextCtrl(panel, -1, 'DT_Corrected', size=(200, -1)) self.wid_ath = wx.TextCtrl(panel, -1, 'Athena_001.prj', size=(200, -1)) self.wid_bad = wx.TextCtrl(panel, -1, ' ', size=(200, -1)) self.wid_autoname = Check(panel, default=True, size=(150, -1), label='auto-increment?') self.sel_wid = Button(panel, 'Browse', size=(100, -1), action=self.onBrowse) ir = 0 sizer.Add(lab_roi, (ir, 0), (1, 1), LCEN, 2) sizer.Add(self.wid_roi, (ir, 1), (1, 1), LCEN, 2) ir += 1 sizer.Add(lab_dir, (ir, 0), (1, 1), LCEN, 2) sizer.Add(self.wid_dir, (ir, 1), (1, 1), LCEN, 2) ir += 1 sizer.Add(lab_ath, (ir, 0), (1, 1), LCEN, 2) sizer.Add(self.wid_ath, (ir, 1), (1, 1), LCEN, 2) sizer.Add(self.wid_autoname, (ir, 2), (1, 1), LCEN, 2) ir += 1 sizer.Add(lab_bad, (ir, 0), (1, 1), LCEN, 2) sizer.Add(self.wid_bad, (ir, 1), (1, 1), LCEN, 2) ir += 1 sizer.Add(lab_sel, (ir, 0), (1, 1), LCEN, 2) sizer.Add(self.sel_wid, (ir, 1), (1, 1), LCEN, 2) pack(panel, sizer) wx.CallAfter(self.init_larch) return
def CreateFitPanel(self, parent): panel = wx.Panel(parent) tpan = wx.Panel(panel) self.fit_model = Choice(tpan, size=(100, -1), choices=('Gaussian', 'Lorentzian', 'Voigt', 'Linear', 'Quadratic', 'Step', 'Rectangle', 'Exponential')) self.fit_bkg = Choice(tpan, size=(100, -1), choices=('None', 'constant', 'linear', 'quadratic')) self.fit_step = Choice(tpan, size=(100, -1), choices=('linear', 'error function', 'arctan')) tsizer = wx.GridBagSizer(10, 4) tsizer.Add(SimpleText(tpan, 'Fit Model: '), (0, 0), (1, 1), LCEN) tsizer.Add(self.fit_model, (0, 1), (1, 1), LCEN) tsizer.Add(SimpleText(tpan, 'Background: '), (0, 2), (1, 1), LCEN) tsizer.Add(self.fit_bkg, (0, 3), (1, 1), LCEN) tsizer.Add( Button(tpan, 'Show Fit', size=(100, -1), action=self.onFitPeak), (1, 1), (1, 1), LCEN) tsizer.Add(SimpleText(tpan, 'Step Form: '), (1, 2), (1, 1), LCEN) tsizer.Add(self.fit_step, (1, 3), (1, 1), LCEN) pack(tpan, tsizer) self.fit_report = RichTextCtrl(panel, size=(525, 250), style=wx.VSCROLL | wx.NO_BORDER) self.fit_report.SetEditable(False) self.fit_report.SetFont(Font(9)) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(tpan, 0, wx.GROW | wx.ALL, 2) sizer.Add(self.fit_report, 1, LCEN | wx.GROW, 2) pack(panel, sizer) return panel
def __init__(self, parent, group, on_ok=None): self.parent = parent self.group = group self.on_ok = on_ok wx.Frame.__init__(self, None, -1, 'Edit Array Names', style=wx.DEFAULT_FRAME_STYLE | wx.TAB_TRAVERSAL) self.SetFont(Font(10)) sizer = wx.GridBagSizer(2, 2) panel = scrolled.ScrolledPanel(self) self.SetMinSize((675, 450)) self.wids = {} ir = 0 sizer.Add( Button(panel, 'Apply Changes', size=(200, -1), action=self.onOK), (0, 1), (1, 2), LEFT, 3) sizer.Add( Button(panel, 'Use Column Number', size=(200, -1), action=self.onColNumber), (0, 3), (1, 2), LEFT, 3) sizer.Add(HLine(panel, size=(550, 2)), (1, 1), (1, 5), LEFT, 3) cind = SimpleText(panel, label='Column') cold = SimpleText(panel, label='Current Name') cnew = SimpleText(panel, label='Enter New Name') cret = SimpleText(panel, label=' Result ', size=(150, -1)) cinfo = SimpleText(panel, label=' Data Range') cplot = SimpleText(panel, label=' Plot') ir = 2 sizer.Add(cind, (ir, 0), (1, 1), LEFT, 3) sizer.Add(cold, (ir, 1), (1, 1), LEFT, 3) sizer.Add(cnew, (ir, 2), (1, 1), LEFT, 3) sizer.Add(cret, (ir, 3), (1, 1), LEFT, 3) sizer.Add(cinfo, (ir, 4), (1, 1), LEFT, 3) sizer.Add(cplot, (ir, 5), (1, 1), LEFT, 3) for i, name in enumerate(group.array_labels): ir += 1 cind = SimpleText(panel, label=' %i ' % (i + 1)) cold = SimpleText(panel, label=' %s ' % name) cret = SimpleText(panel, label=fix_varname(name), size=(150, -1)) cnew = wx.TextCtrl(panel, value=name, size=(150, -1)) cnew.Bind(wx.EVT_KILL_FOCUS, partial(self.update, index=i)) cnew.Bind(wx.EVT_CHAR, partial(self.update_char, index=i)) cnew.Bind(wx.EVT_TEXT_ENTER, partial(self.update, index=i)) arr = group.data[i, :] info_str = " [ %8g : %8g ] " % (arr.min(), arr.max()) cinfo = SimpleText(panel, label=info_str) cplot = Button(panel, 'Plot', action=partial(self.onPlot, index=i)) self.wids["%d" % i] = cnew self.wids["ret_%d" % i] = cret sizer.Add(cind, (ir, 0), (1, 1), LEFT, 3) sizer.Add(cold, (ir, 1), (1, 1), LEFT, 3) sizer.Add(cnew, (ir, 2), (1, 1), LEFT, 3) sizer.Add(cret, (ir, 3), (1, 1), LEFT, 3) sizer.Add(cinfo, (ir, 4), (1, 1), LEFT, 3) sizer.Add(cplot, (ir, 5), (1, 1), LEFT, 3) 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()
def __init__(self, parent, filename=None, read_ok_cb=None, size=(725, 450), _larch=None): self.parent = parent self.filename = filename self.larch = _larch self.read_ok_cb = read_ok_cb self.colors = GUIColors() wx.Frame.__init__(self, parent, -1, size=size, style=FRAMESTYLE) splitter = wx.SplitterWindow(self, style=wx.SP_LIVE_UPDATE) splitter.SetMinimumPaneSize(200) leftpanel = wx.Panel(splitter) ltop = wx.Panel(leftpanel) sel_none = Button(ltop, 'Select None', size=(100, 30), action=self.onSelNone) sel_all = Button(ltop, 'Select All', size=(100, 30), action=self.onSelAll) sel_imp = Button(ltop, 'Import Selected Groups', size=(200, 30), action=self.onOK) self.select_imported = sel_imp self.select_imported.Disable() self.grouplist = FileCheckList(leftpanel, select_action=self.onShowGroup) self.grouplist.SetBackgroundColour(wx.Colour(255, 255, 255)) tsizer = wx.GridBagSizer(2, 2) tsizer.Add(sel_all, (0, 0), (1, 1), LCEN, 0) tsizer.Add(sel_none, (0, 1), (1, 1), LCEN, 0) tsizer.Add(sel_imp, (1, 0), (1, 2), LCEN, 0) pack(ltop, tsizer) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(ltop, 0, LCEN | wx.GROW, 1) sizer.Add(self.grouplist, 1, LCEN | wx.GROW | wx.ALL, 1) pack(leftpanel, sizer) # right hand side rightpanel = wx.Panel(splitter) self.SetTitle("Reading Athena Project '%s'" % self.filename) self.title = SimpleText(rightpanel, self.filename, font=Font(13), colour=self.colors.title, style=LCEN) self.plotpanel = PlotPanel(rightpanel, messenger=self.plot_messages) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(self.title, 0, LCEN, 2) sizer.Add(self.plotpanel, 0, LCEN, 2) pack(rightpanel, sizer) splitter.SplitVertically(leftpanel, rightpanel, 1) self.statusbar = self.CreateStatusBar(2, 0) self.statusbar.SetStatusWidths([-3, -1]) statusbar_fields = [self.filename, ""] for i in range(len(statusbar_fields)): self.statusbar.SetStatusText(statusbar_fields[i], i) self.all = read_athena(self.filename, do_bkg=False, do_fft=False, with_journal=False, _larch=_larch) for item in dir(self.all): self.grouplist.Append(item) self.Show() self.Raise()
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()
def __init__(self, parent, group, on_ok=None): self.parent = parent self.group = group self.on_ok = on_ok wx.Frame.__init__(self, None, -1, 'Add Selected Columns', style=wx.DEFAULT_FRAME_STYLE | wx.TAB_TRAVERSAL) self.SetFont(Font(10)) sizer = wx.GridBagSizer(2, 2) panel = scrolled.ScrolledPanel(self) self.SetMinSize((550, 550)) self.wids = {} lab_aname = SimpleText(panel, label=' Save Array Name:') lab_range = SimpleText(panel, label=' Use column index:') lab_regex = SimpleText(panel, label=' Use column label:') wids = self.wids = {} wids['arrayname'] = wx.TextCtrl(panel, value='sum', size=(175, -1)) wids['tc_nums'] = wx.TextCtrl(panel, value='1,3-10', size=(175, -1)) wids['tc_regex'] = wx.TextCtrl(panel, value='*fe*', size=(175, -1)) savebtn = Button(panel, 'Save', action=self.onOK) plotbtn = Button(panel, 'Plot Sum', action=self.onPlot) sel_nums = Button(panel, 'Select by Index', action=self.onSelColumns) sel_re = Button(panel, 'Select by Pattern', action=self.onSelRegex) sizer.Add(lab_aname, (0, 0), (1, 2), LEFT, 3) sizer.Add(wids['arrayname'], (0, 2), (1, 1), LEFT, 3) sizer.Add(plotbtn, (0, 3), (1, 1), LEFT, 3) sizer.Add(savebtn, (0, 4), (1, 1), LEFT, 3) sizer.Add(lab_range, (1, 0), (1, 2), LEFT, 3) sizer.Add(wids['tc_nums'], (1, 2), (1, 1), LEFT, 3) sizer.Add(sel_nums, (1, 3), (1, 2), LEFT, 3) sizer.Add(lab_regex, (2, 0), (1, 2), LEFT, 3) sizer.Add(wids['tc_regex'], (2, 2), (1, 1), LEFT, 3) sizer.Add(sel_re, (2, 3), (1, 2), LEFT, 3) sizer.Add(HLine(panel, size=(550, 2)), (3, 0), (1, 5), LEFT, 3) ir = 4 cind = SimpleText(panel, label=' Index ') csel = SimpleText(panel, label=' Select ') cname = SimpleText(panel, label=' Array Name ') sizer.Add(cind, (ir, 0), (1, 1), LEFT, 3) sizer.Add(csel, (ir, 1), (1, 1), LEFT, 3) sizer.Add(cname, (ir, 2), (1, 3), LEFT, 3) for i, name in enumerate(group.array_labels): ir += 1 cind = SimpleText(panel, label=' %i ' % (i + 1)) cname = SimpleText(panel, label=' %s ' % name) csel = Check(panel, label='', default=False) self.wids["col_%d" % i] = csel sizer.Add(cind, (ir, 0), (1, 1), LEFT, 3) sizer.Add(csel, (ir, 1), (1, 1), LEFT, 3) sizer.Add(cname, (ir, 2), (1, 3), LEFT, 3) 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()
def __init__(self, parent, filename=None, groupname=None, last_array_sel=None, read_ok_cb=None, edit_groupname=True, _larch=None): self.parent = parent self._larch = _larch self.path = filename group = self.initgroup = self.read_column_file(self.path) self.subframes = {} self.workgroup = Group(raw=group) for attr in ('path', 'filename', 'groupname', 'datatype', 'array_labels'): setattr(self.workgroup, attr, getattr(group, attr, None)) arr_labels = [l.lower() for l in self.initgroup.array_labels] if self.workgroup.datatype is None: self.workgroup.datatype = 'raw' if ('energ' in arr_labels[0] or 'energ' in arr_labels[1]): self.workgroup.datatype = 'xas' self.read_ok_cb = read_ok_cb self.array_sel = { 'xpop': '', 'xarr': None, 'ypop': '', 'yop': '/', 'yarr1': None, 'yarr2': None, 'use_deriv': False } if last_array_sel is not None: self.array_sel.update(last_array_sel) if self.array_sel['yarr2'] is None and 'i0' in arr_labels: self.array_sel['yarr2'] = 'i0' if self.array_sel['yarr1'] is None: if 'itrans' in arr_labels: self.array_sel['yarr1'] = 'itrans' elif 'i1' in arr_labels: self.array_sel['yarr1'] = 'i1' message = "Data Columns for %s" % group.filename wx.Frame.__init__(self, None, -1, 'Build Arrays from Data Columns for %s' % group.filename, style=FRAMESTYLE) self.SetFont(Font(10)) panel = wx.Panel(self) self.SetMinSize((600, 600)) self.colors = GUIColors() # title row title = SimpleText(panel, message, font=Font(13), colour=self.colors.title, style=LCEN) opts = dict(action=self.onUpdate, size=(120, -1)) yarr_labels = self.yarr_labels = arr_labels + ['1.0', '0.0', ''] xarr_labels = self.xarr_labels = arr_labels + ['_index'] self.xarr = Choice(panel, choices=xarr_labels, **opts) self.yarr1 = Choice(panel, choices=arr_labels, **opts) self.yarr2 = Choice(panel, choices=yarr_labels, **opts) self.yerr_arr = Choice(panel, choices=yarr_labels, **opts) self.yerr_arr.Disable() self.datatype = Choice(panel, choices=DATATYPES, **opts) self.datatype.SetStringSelection(self.workgroup.datatype) opts['size'] = (50, -1) self.yop = Choice(panel, choices=ARR_OPS, **opts) opts['size'] = (120, -1) self.use_deriv = Check(panel, label='use derivative', default=self.array_sel['use_deriv'], **opts) self.xpop = Choice(panel, choices=XPRE_OPS, **opts) self.ypop = Choice(panel, choices=YPRE_OPS, **opts) opts['action'] = self.onYerrChoice self.yerr_op = Choice(panel, choices=YERR_OPS, **opts) self.yerr_op.SetSelection(0) self.yerr_const = FloatCtrl(panel, value=1, precision=4, size=(90, -1)) ylab = SimpleText(panel, 'Y = ') xlab = SimpleText(panel, 'X = ') yerr_lab = SimpleText(panel, 'Yerror = ') self.xsuf = SimpleText(panel, '') self.ysuf = SimpleText(panel, '') self.xpop.SetStringSelection(self.array_sel['xpop']) self.ypop.SetStringSelection(self.array_sel['ypop']) self.yop.SetStringSelection(self.array_sel['yop']) if '(' in self.array_sel['ypop']: self.ysuf.SetLabel(')') ixsel, iysel, iy2sel = 0, 1, len(yarr_labels) - 1 if self.array_sel['xarr'] in xarr_labels: ixsel = xarr_labels.index(self.array_sel['xarr']) if self.array_sel['yarr1'] in arr_labels: iysel = arr_labels.index(self.array_sel['yarr1']) if self.array_sel['yarr2'] in yarr_labels: iy2sel = yarr_labels.index(self.array_sel['yarr2']) self.xarr.SetSelection(ixsel) self.yarr1.SetSelection(iysel) self.yarr2.SetSelection(iy2sel) bpanel = wx.Panel(panel) bsizer = wx.BoxSizer(wx.HORIZONTAL) _ok = Button(bpanel, 'OK', action=self.onOK) _cancel = Button(bpanel, 'Cancel', action=self.onCancel) _edit = Button(bpanel, 'Edit Array Names', action=self.onEditNames) bsizer.Add(_ok) bsizer.Add(_cancel) bsizer.Add(_edit) _ok.SetDefault() pack(bpanel, bsizer) sizer = wx.GridBagSizer(4, 8) sizer.Add(title, (0, 0), (1, 7), LCEN, 5) ir = 1 sizer.Add(xlab, (ir, 0), (1, 1), LCEN, 0) sizer.Add(self.xpop, (ir, 1), (1, 1), CEN, 0) sizer.Add(self.xarr, (ir, 2), (1, 1), CEN, 0) sizer.Add(self.xsuf, (ir, 3), (1, 1), CEN, 0) ir += 1 sizer.Add(ylab, (ir, 0), (1, 1), LCEN, 0) sizer.Add(self.ypop, (ir, 1), (1, 1), CEN, 0) sizer.Add(self.yarr1, (ir, 2), (1, 1), CEN, 0) sizer.Add(self.yop, (ir, 3), (1, 1), CEN, 0) sizer.Add(self.yarr2, (ir, 4), (1, 1), CEN, 0) sizer.Add(self.ysuf, (ir, 5), (1, 1), CEN, 0) sizer.Add(self.use_deriv, (ir, 6), (1, 1), LCEN, 0) ir += 1 sizer.Add(yerr_lab, (ir, 0), (1, 1), LCEN, 0) sizer.Add(self.yerr_op, (ir, 1), (1, 1), CEN, 0) sizer.Add(self.yerr_arr, (ir, 2), (1, 1), CEN, 0) sizer.Add(SimpleText(panel, 'Value:'), (ir, 3), (1, 1), CEN, 0) sizer.Add(self.yerr_const, (ir, 4), (1, 2), CEN, 0) ir += 1 sizer.Add(SimpleText(panel, 'Data Type:'), (ir, 0), (1, 1), LCEN, 0) sizer.Add(self.datatype, (ir, 1), (1, 2), LCEN, 0) ir += 1 self.wid_groupname = wx.TextCtrl(panel, value=group.groupname, size=(240, -1)) if not edit_groupname: self.wid_groupname.Disable() sizer.Add(SimpleText(panel, 'Group Name:'), (ir, 0), (1, 1), LCEN, 0) sizer.Add(self.wid_groupname, (ir, 1), (1, 2), LCEN, 0) ir += 1 sizer.Add(bpanel, (ir, 0), (1, 5), LCEN, 3) pack(panel, sizer) self.nb = fnb.FlatNotebook(self, -1, agwStyle=FNB_STYLE) self.nb.SetTabAreaColour(wx.Colour(248, 248, 240)) self.nb.SetActiveTabColour(wx.Colour(254, 254, 195)) self.nb.SetNonActiveTabTextColour(wx.Colour(40, 40, 180)) self.nb.SetActiveTabTextColour(wx.Colour(80, 0, 0)) self.plotpanel = PlotPanel(self, messenger=self.plot_messages) textpanel = wx.Panel(self) ftext = wx.TextCtrl(textpanel, style=wx.TE_MULTILINE | wx.TE_READONLY, size=(400, 250)) ftext.SetValue(group.text) ftext.SetFont(Font(10)) textsizer = wx.BoxSizer(wx.VERTICAL) textsizer.Add(ftext, 1, LCEN | wx.GROW, 1) pack(textpanel, textsizer) self.nb.AddPage(textpanel, ' Text of Data File ', True) self.nb.AddPage(self.plotpanel, ' Plot of Selected Arrays ', True) mainsizer = wx.BoxSizer(wx.VERTICAL) mainsizer.Add(panel, 0, wx.GROW | wx.ALL, 2) mainsizer.Add(self.nb, 1, LCEN | wx.GROW, 2) pack(self, mainsizer) self.statusbar = self.CreateStatusBar(2, 0) self.statusbar.SetStatusWidths([-1, -1]) statusbar_fields = [group.filename, ""] for i in range(len(statusbar_fields)): self.statusbar.SetStatusText(statusbar_fields[i], i) self.Show() self.Raise() self.onUpdate(self)
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)
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))
def CopyBtn(name): return Button(xas, 'Copy', size=(50, 30), action=partial(self.onCopyParam, name))
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)
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()
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)
def createEpicsPanel(self): pane = wx.Panel(self, name='epics panel') psizer = wx.GridBagSizer(4, 12) # wx.BoxSizer(wx.HORIZONTAL) btnpanel = wx.Panel(pane, name='buttons') nmca = self.nmca NPERROW = 6 self.SetFont(Font(9)) if self.det_type.lower().startswith('me-4') and nmca < 5: btnsizer = wx.GridBagSizer(2, 2) else: btnsizer = wx.GridBagSizer( int((nmca + NPERROW - 2) / (1.0 * NPERROW)), NPERROW) style = wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL rstyle = wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL bkg_choices = ['None'] psizer.Add(SimpleText(pane, ' MCAs: '), (0, 0), (1, 1), style, 1) for i in range(1, 1 + nmca): bkg_choices.append("%i" % i) b = Button(btnpanel, '%i' % i, size=(30, 25), action=partial(self.onSelectDet, index=i)) self.wids['det%i' % i] = b loc = divmod(i - 1, NPERROW) if self.det_type.lower().startswith('me-4') and nmca < NPERROW - 1: loc = self.me4_layout[i - 1] btnsizer.Add(b, loc, (1, 1), style, 1) pack(btnpanel, btnsizer) nrows = 1 + loc[0] if self.det_type.lower().startswith('me-4') and nmca < 5: nrows = 2 psizer.Add(btnpanel, (0, 1), (nrows, 1), style, 1) self.wids['det_status'] = SimpleText(pane, ' ', size=(120, -1), style=style) self.wids['deadtime'] = SimpleText(pane, ' ', size=(120, -1), style=style) self.wids['bkg_det'] = Choice(pane, size=(75, -1), choices=bkg_choices, action=self.onSelectDet) self.wids['dwelltime'] = FloatCtrl(pane, value=0.0, precision=1, minval=0, size=(80, -1), act_on_losefocus=True, action=self.onSetDwelltime) self.wids['elapsed'] = SimpleText(pane, ' ', size=(80, -1), style=style) b1 = Button(pane, 'Start', size=(90, 25), action=self.onStart) b2 = Button(pane, 'Stop', size=(90, 25), action=self.onStop) b3 = Button(pane, 'Erase', size=(90, 25), action=self.onErase) b4 = Button(pane, 'Continuous', size=(90, 25), action=partial(self.onStart, dtime=0)) bkg_lab = SimpleText(pane, 'Background MCA:', size=(150, -1)) pre_lab = SimpleText(pane, 'Preset Time (s):', size=(125, -1)) ela_lab = SimpleText(pane, 'Elapsed Time (s):', size=(125, -1)) sta_lab = SimpleText(pane, 'Status :', size=(100, -1)) dea_lab = SimpleText(pane, '% Deadtime:', size=(100, -1)) psizer.Add(bkg_lab, (0, 2), (1, 1), style, 1) psizer.Add(self.wids['bkg_det'], (1, 2), (1, 1), style, 1) psizer.Add(pre_lab, (0, 3), (1, 1), style, 1) psizer.Add(ela_lab, (1, 3), (1, 1), style, 1) psizer.Add(self.wids['dwelltime'], (0, 4), (1, 1), style, 1) psizer.Add(self.wids['elapsed'], (1, 4), (1, 1), style, 1) psizer.Add(b1, (0, 5), (1, 1), style, 1) psizer.Add(b4, (0, 6), (1, 1), style, 1) psizer.Add(b2, (1, 5), (1, 1), style, 1) psizer.Add(b3, (1, 6), (1, 1), style, 1) psizer.Add(sta_lab, (0, 7), (1, 1), style, 1) psizer.Add(self.wids['det_status'], (0, 8), (1, 1), style, 1) psizer.Add(dea_lab, (1, 7), (1, 1), style, 1) psizer.Add(self.wids['deadtime'], (1, 8), (1, 1), style, 1) pack(pane, psizer) # pane.SetMinSize((500, 53)) self.det.connect_displays(status=self.wids['det_status'], elapsed=self.wids['elapsed'], deadtime=self.wids['deadtime']) wx.CallAfter(self.onSelectDet, index=1, init=True) self.timer_counter = 0 self.mca_timer = wx.Timer(self) self.Bind(wx.EVT_TIMER, self.UpdateData, self.mca_timer) self.mca_timer.Start(100) return pane
def createControlPanel(self): ctrlpanel = wx.Panel(self, name='Ctrl Panel') ptable = PeriodicTablePanel(ctrlpanel, onselect=self.onShowLines, tooltip_msg='Select Element for KLM Lines') self.wids['ptable'] = ptable labstyle = wx.ALIGN_LEFT|wx.ALIGN_BOTTOM|wx.EXPAND ctrlstyle = wx.ALIGN_LEFT|wx.ALIGN_BOTTOM txtstyle=wx.ALIGN_LEFT|wx.ST_NO_AUTORESIZE|wx.TE_PROCESS_ENTER Font9 = Font(9) Font10 = Font(10) Font11 = Font(11) # arrowpanel = wx.Panel(ctrlpanel) ssizer = wx.BoxSizer(wx.HORIZONTAL) for wname, dname in (('uparrow', 'up'), ('leftarrow', 'left'), ('rightarrow', 'right'), ('downarrow', 'down')): self.wids[wname] = wx.BitmapButton(arrowpanel, -1, get_icon(wname), size=(25, 25), style=wx.NO_BORDER) self.wids[wname].Bind(wx.EVT_BUTTON, partial(ptable.onKey, name=dname)) ssizer.Add(self.wids[wname], 0, wx.EXPAND|wx.ALL) self.wids['kseries'] = Check(arrowpanel, ' K ', action=self.onKLM) self.wids['lseries'] = Check(arrowpanel, ' L ', action=self.onKLM) self.wids['mseries'] = Check(arrowpanel, ' M ', action=self.onKLM) self.wids['holdbtn'] = wx.ToggleButton(arrowpanel, -1, 'Hold ', size=(65, 25)) self.wids['holdbtn'].Bind(wx.EVT_TOGGLEBUTTON, self.onToggleHold) ssizer.Add(txt(arrowpanel, ' '), 0, wx.EXPAND|wx.ALL, 0) ssizer.Add(self.wids['holdbtn'], 0, wx.EXPAND|wx.ALL, 2) ssizer.Add(self.wids['kseries'], 0, wx.EXPAND|wx.ALL, 0) ssizer.Add(self.wids['lseries'], 0, wx.EXPAND|wx.ALL, 0) ssizer.Add(self.wids['mseries'], 0, wx.EXPAND|wx.ALL, 0) pack(arrowpanel, ssizer) # roi section... rsizer = wx.GridBagSizer(4, 6) roipanel = wx.Panel(ctrlpanel, name='ROI Panel') self.wids['roilist'] = wx.ListBox(roipanel, size=(135, 120)) self.wids['roilist'].Bind(wx.EVT_LISTBOX, self.onROI) self.wids['roilist'].SetMinSize((135, 120)) self.wids['roiname'] = wx.TextCtrl(roipanel, -1, '', size=(150, -1)) # roibtns= wx.Panel(roipanel, name='ROIButtons') zsizer = wx.BoxSizer(wx.HORIZONTAL) z1 = Button(roibtns, 'Add', size=(70, 30), action=self.onNewROI) z2 = Button(roibtns, 'Delete', size=(70, 30), action=self.onConfirmDelROI) z3 = Button(roibtns, 'Rename', size=(70, 30), action=self.onRenameROI) zsizer.Add(z1, 0, wx.EXPAND|wx.ALL, 0) zsizer.Add(z2, 0, wx.EXPAND|wx.ALL, 0) zsizer.Add(z3, 0, wx.EXPAND|wx.ALL, 0) pack(roibtns, zsizer) rt1 = txt(roipanel, ' Channels:', size=75, font=Font9) rt2 = txt(roipanel, ' Energy:', size=75, font=Font9) rt3 = txt(roipanel, ' Cen/Wid:', size=75, font=Font9) m = '' self.wids['roi_msg1'] = txt(roipanel, m, size=135, font=Font9) self.wids['roi_msg2'] = txt(roipanel, m, size=135, font=Font9) self.wids['roi_msg3'] = txt(roipanel, m, size=135, font=Font9) rsizer.Add(txt(roipanel, ' Regions of Interest:', size=125, font=Font11), (0, 0), (1, 3), labstyle) rsizer.Add(self.wids['roiname'], (1, 0), (1, 3), labstyle) rsizer.Add(roibtns, (2, 0), (1, 3), labstyle) rsizer.Add(rt1, (3, 0), (1, 1), LEFT) rsizer.Add(rt2, (4, 0), (1, 1), LEFT) rsizer.Add(rt3, (5, 0), (1, 1), LEFT) rsizer.Add(self.wids['roi_msg1'], (3, 1), (1, 2), labstyle) rsizer.Add(self.wids['roi_msg2'], (4, 1), (1, 2), labstyle) rsizer.Add(self.wids['roi_msg3'], (5, 1), (1, 2), labstyle) rsizer.Add(self.wids['roilist'], (0, 3), (6, 1), wx.EXPAND|wx.ALL|wx.ALIGN_RIGHT) rsizer.SetHGap(1) pack(roipanel, rsizer) # end roi section # y scale yscalepanel = wx.Panel(ctrlpanel, name='YScalePanel') ysizer = wx.BoxSizer(wx.HORIZONTAL) ytitle = txt(yscalepanel, ' Y Axis:', font=Font10, size=80) yspace = txt(yscalepanel, ' ', font=Font10, size=20) ylog = Choice(yscalepanel, size=(80, 30), choices=['log', 'linear'], action=self.onLogLinear) yaxis = Check(yscalepanel, ' Show Y Scale ', action=self.onYAxis, default=False) self.wids['show_yaxis'] = yaxis ysizer.Add(ytitle, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 0) ysizer.Add(ylog, 0, wx.EXPAND|wx.ALL, 0) ysizer.Add(yspace, 0, wx.EXPAND|wx.ALL, 0) ysizer.Add(yaxis, 0, wx.EXPAND|wx.ALL, 0) pack(yscalepanel, ysizer) # zoom buttons zoompanel = wx.Panel(ctrlpanel, name='ZoomPanel') zsizer = wx.BoxSizer(wx.HORIZONTAL) z1 = Button(zoompanel, 'Zoom In', size=(80, 30), action=self.onZoomIn) z2 = Button(zoompanel, 'Zoom Out', size=(80, 30), action=self.onZoomOut) p1 = Button(zoompanel, 'Pan Lo', size=(75, 30), action=self.onPanLo) p2 = Button(zoompanel, 'Pan Hi', size=(75, 30), action=self.onPanHi) zsizer.Add(p1, 0, wx.EXPAND|wx.ALL, 0) zsizer.Add(p2, 0, wx.EXPAND|wx.ALL, 0) zsizer.Add(z1, 0, wx.EXPAND|wx.ALL, 0) zsizer.Add(z2, 0, wx.EXPAND|wx.ALL, 0) pack(zoompanel, zsizer) # self.wids['xray_lines'] = None if HAS_DV: dvstyle = dv.DV_SINGLE|dv.DV_VERT_RULES|dv.DV_ROW_LINES xlines = dv.DataViewListCtrl(ctrlpanel, style=dvstyle) self.wids['xray_lines'] = xlines xlines.AppendTextColumn('Line ', width=55) xlines.AppendTextColumn('Energy(keV) ', width=110) xlines.AppendTextColumn('Strength ', width=85) xlines.AppendTextColumn('Levels ', width=75) for col in (0, 1, 2, 3): this = xlines.Columns[col] this.Sortable = True align = RIGHT if col in (0, 3): align = wx.ALIGN_LEFT this.Alignment = this.Renderer.Alignment = align xlines.SetMinSize((300, 240)) xlines.Bind(dv.EVT_DATAVIEW_SELECTION_CHANGED, self.onSelectXrayLine) # main layout # may have to adjust comparison.... store = xlines.GetStore() sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(roipanel, 0, labstyle) sizer.Add(lin(ctrlpanel, 195), 0, labstyle) sizer.Add(yscalepanel, 0, wx.ALIGN_RIGHT|wx.EXPAND|wx.ALL) sizer.Add(zoompanel, 0, wx.ALIGN_RIGHT|wx.EXPAND|wx.ALL) sizer.Add(lin(ctrlpanel, 195), 0, labstyle) sizer.Add(ptable, 0, wx.ALIGN_RIGHT|wx.EXPAND|wx.ALL, 4) sizer.Add(arrowpanel, 0, labstyle) sizer.Add(lin(ctrlpanel, 195), 0, labstyle) if self.wids['xray_lines'] is not None: sizer.Add(xlines, 0, wx.ALIGN_CENTER|wx.GROW|wx.ALL|wx.EXPAND) pack(ctrlpanel, sizer) return ctrlpanel
def Btn(msg, x, act): b = Button(ltop, msg, size=(x, 30), action=act) b.SetFont(Font(10)) return b
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) self.param_panel = AllParamsPanel(self, controller=self.controller) # self.mod_nb.AddPage(self.param_panel, 'Parameters', True) range_row = wx.Panel(self) rsizer = wx.BoxSizer(wx.HORIZONTAL) xmin_sel = BitmapButton(range_row, get_icon('plus'), action=partial(self.on_selpoint, opt='xmin'), tooltip='use last point selected from plot') xmax_sel = BitmapButton(range_row, get_icon('plus'), action=partial(self.on_selpoint, opt='xmax'), tooltip='use last point selected from plot') opts = {'size': (70, -1), 'gformat': True} self.xmin = FloatCtrl(range_row, value=-np.inf, **opts) self.xmax = FloatCtrl(range_row, value=np.inf, **opts) rsizer.Add(SimpleText(range_row, 'Fit Range X=[ '), 0, LCEN, 3) rsizer.Add(xmin_sel, 0, LCEN, 3) rsizer.Add(self.xmin, 0, LCEN, 3) rsizer.Add(SimpleText(range_row, ' : '), 0, LCEN, 3) rsizer.Add(xmax_sel, 0, LCEN, 3) rsizer.Add(self.xmax, 0, LCEN, 3) rsizer.Add(SimpleText(range_row, ' ] '), 0, LCEN, 3) rsizer.Add( Button(range_row, 'Full Data Range', size=(150, -1), action=self.onResetRange), 0, LCEN, 3) pack(range_row, rsizer) action_row = wx.Panel(self) rsizer = wx.BoxSizer(wx.HORIZONTAL) self.plot_comps = Check(action_row, label='Plot Components?', default=True, size=(150, -1)) rsizer.Add( Button(action_row, 'Run Fit', size=(100, -1), action=self.onRunFit), 0, RCEN, 3) savebtn = Button(action_row, 'Save Fit', size=(100, -1), action=self.onSaveFit) savebtn.Disable() rsizer.Add(savebtn, 0, LCEN, 3) rsizer.Add( Button(action_row, 'Plot Current Model', size=(150, -1), action=self.onShowModel), 0, LCEN, 3) rsizer.Add(self.plot_comps, 0, LCEN, 3) pack(action_row, rsizer) models_row = wx.Panel(self) rsizer = wx.BoxSizer(wx.HORIZONTAL) self.model_choice = Choice(models_row, size=(200, -1), choices=ModelChoices['peaks'], action=self.addModel) rsizer.Add(SimpleText(models_row, ' Add Model Type: '), 0, LCEN, 3) rsizer.Add( Choice(models_row, size=(100, -1), choices=ModelTypes, action=self.onModelTypes), 0, LCEN, 3) rsizer.Add(SimpleText(models_row, ' Model: '), 0, LCEN, 3) rsizer.Add(self.model_choice, 0, LCEN, 3) pack(models_row, rsizer) sizer = wx.BoxSizer(wx.VERTICAL) sizer.AddMany([(range_row, 0, LCEN, 4), ((9, 9), 0, LCEN, 4), (models_row, 0, LCEN, 4), ((9, 9), 0, LCEN, 4), (action_row, 0, LCEN, 4), ((9, 9), 0, LCEN, 4), (HLine(self, size=(550, 3)), 0, LCEN, 4), ((10, 10), 0, LCEN, 2), (self.mod_nb, 1, LCEN | wx.GROW, 10)]) pack(self, sizer)
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
def createDetailsPanel(self, parent): mainpanel = wx.Panel(parent) mainsizer = wx.BoxSizer(wx.VERTICAL) panel = wx.Panel(mainpanel) sizer = wx.GridBagSizer(8, 7) self.title = SimpleText(panel, 'initializing...') ir = 0 sizer.Add(self.title, (ir, 0), (1, 6), LCEN, 2) # x-axis self.xarr = Choice(panel, choices=[], action=self.onColumnChoices, size=(120, -1)) self.xop = Choice(panel, choices=('', 'log'), action=self.onColumnChoices, size=(90, -1)) ir += 1 sizer.Add(SimpleText(panel, 'X = '), (ir, 0), (1, 1), CEN, 0) sizer.Add(self.xop, (ir, 1), (1, 1), CEN, 0) sizer.Add(SimpleText(panel, '('), (ir, 2), (1, 1), CEN, 0) sizer.Add(self.xarr, (ir, 3), (1, 1), RCEN, 0) sizer.Add(SimpleText(panel, ')'), (ir, 4), (1, 1), CEN, 0) self.yops = [] self.yarr = [] opts = { 'choices': [], 'size': (120, -1), 'action': self.onColumnChoices } for i in range(3): self.yarr.append(Choice(panel, **opts)) for opts, sel, siz in ((PRE_OPS, 0, 90), (ARR_OPS, 3, 50), (ARR_OPS, 3, 50)): w1 = Choice(panel, choices=opts, action=self.onColumnChoices, size=(siz, -1)) w1.SetSelection(sel) self.yops.append(w1) ir += 1 label = 'Y = ' sizer.Add(SimpleText(panel, label), (ir, 0), (1, 1), CEN, 0) sizer.Add(self.yops[0], (ir, 1), (1, 1), CEN, 0) sizer.Add(SimpleText(panel, '[('), (ir, 2), (1, 1), CEN, 0) sizer.Add(self.yarr[0], (ir, 3), (1, 1), CEN, 0) sizer.Add(self.yops[1], (ir, 4), (1, 1), CEN, 0) sizer.Add(self.yarr[1], (ir, 5), (1, 1), CEN, 0) sizer.Add(SimpleText(panel, ')'), (ir, 6), (1, 1), LCEN, 0) ir += 1 sizer.Add(self.yops[2], (ir, 4), (1, 1), CEN, 0) sizer.Add(self.yarr[2], (ir, 5), (1, 1), CEN, 0) sizer.Add(SimpleText(panel, ']'), (ir, 6), (1, 1), LCEN, 0) self.use_deriv = Check(panel, default=False, label='Use Derivative?', action=self.onColumnChoices) self.dtcorr = Check(panel, default=True, label='correct deadtime?', action=self.onColumnChoices) ir += 1 sizer.Add(self.use_deriv, (ir, 0), (1, 3), LCEN, 0) sizer.Add(self.dtcorr, (ir, 3), (1, 3), LCEN, 0) pack(panel, sizer) self.nb = flat_nb.FlatNotebook(mainpanel, -1, agwStyle=FNB_STYLE) self.nb.SetTabAreaColour(wx.Colour(248, 248, 240)) self.nb.SetActiveTabColour(wx.Colour(254, 254, 195)) self.nb.SetNonActiveTabTextColour(wx.Colour(40, 40, 180)) self.nb.SetActiveTabTextColour(wx.Colour(80, 0, 0)) self.xas_panel = self.CreateXASPanel(self.nb) # mainpanel) self.fit_panel = self.CreateFitPanel(self.nb) # mainpanel) self.nb.AddPage(self.fit_panel, ' General Analysis ', True) self.nb.AddPage(self.xas_panel, ' XAS Processing ', True) mainsizer.Add(panel, 0, LCEN | wx.EXPAND, 2) btnbox = wx.Panel(mainpanel) btnsizer = wx.BoxSizer(wx.HORIZONTAL) for ttl, opt in (('New Plot', 'new'), ('Over Plot (left)', 'left'), ('Over Plot (right)', 'right')): btnsizer.Add( Button(btnbox, ttl, size=(135, -1), action=partial(self.onPlot, opt=opt)), LCEN, 1) pack(btnbox, btnsizer) mainsizer.Add(btnbox, 0, LCEN, 2) mainsizer.Add(self.nb, 1, LCEN | wx.EXPAND, 2) pack(mainpanel, mainsizer) return mainpanel
class XRFCalibrationFrame(wx.Frame): 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) def onInitTimer(self, evt=None): """initial calibration""" if self.init_proc: # print("skipping in init_proc...") return nextroi = None if time.time() - self.init_t0 > 20: self.init_timer.Stop() self.init_proc = False self.calib_btn.Enable() for roiname, wids in self.init_wids.items(): if not wids[0]: nextroi = roiname break if nextroi is None: self.init_timer.Stop() self.init_proc = False self.calib_btn.Enable() else: self.init_proc = True xrf_calib_init_roi(self.mca, roiname) s, w_pred, w_ccen, w_cdif, w_cwid, w_use = self.init_wids[roiname] if roiname in self.mca.init_calib: eknown, ecen, fwhm, amp, fit = self.mca.init_calib[roiname] diff = ecen - eknown opts = {'style': CEN, 'size': (75, -1)} w_pred.SetLabel("% .1f" % (1000 * eknown)) w_ccen.SetLabel("% .1f" % (1000 * ecen)) w_cdif.SetLabel("% .1f" % (1000 * diff)) w_cwid.SetLabel("% .1f" % (1000 * fwhm)) if fwhm > 0.001 and fwhm < 2.00 and fit is not None: w_use.SetValue(1) self.init_wids[roiname][0] = True self.init_proc = False def onCalibrate(self, event=None): x, y = [], [] mca = self.mca # save old calib old_calib = mca.offset, mca.slope init_calib = copy.deepcopy(mca.init_calib) for roiname, eknown, ecen, w_ncen, w_ndif, w_nwid, w_use in self.wids: if not w_use.IsChecked(): mca.init_calib.pop(roiname) w_ncen.SetLabel("-----") w_ndif.SetLabel("-----") w_nwid.SetLabel("-----") xrf_calib_compute(mca, apply=True) offset, slope = mca.new_calib self.calib_updated = True self.new_offset.SetValue("% .3f" % (1000 * offset)) self.new_slope.SetValue("% .3f" % (1000 * slope)) # find ROI peak positions using this new calibration xrf_calib_fitrois(mca) for roi in self.mca.rois: try: eknown, ecen, fwhm, amp, fit = mca.init_calib[roi.name] except: continue diff = ecen - eknown for roiname, eknown, ocen, w_ncen, w_ndif, w_nwid, w_use in self.wids: if roiname == roi.name and w_use.IsChecked(): w_ncen.SetLabel("%.1f" % (1000 * ecen)) w_ndif.SetLabel("% .1f" % (1000 * diff)) w_nwid.SetLabel("%.1f" % (1000 * fwhm)) break # restore calibration to old values until new values are accepted xrf_calib_apply(mca, offset=old_calib[0], slope=old_calib[1]) mca.init_calib = init_calib tsize = self.GetSize() self.SetSize((tsize[0] + 1, tsize[1])) self.SetSize((tsize[0], tsize[1])) def onUseCalib(self, event=None): mca = self.mca offset = 0.001 * float(self.new_offset.GetValue()) slope = 0.001 * float(self.new_slope.GetValue()) mca.new_calib = offset, slope xrf_calib_apply(mca, offset=offset, slope=slope) if callable(self.callback): self.callback(mca) self.Destroy() def onClose(self, event=None): self.Destroy()