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
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 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, 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 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 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 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)
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 __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 __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, 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, 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()
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()
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, 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 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 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 __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))
def build(self): sizer = wx.GridBagSizer(10, 5) sizer.SetVGap(2) sizer.SetHGap(2) panel = scrolled.ScrolledPanel(self) self.SetMinSize((600, 450)) self.colors = GUIColors() # title row self.wids = wids = {} title = SimpleText(panel, 'Fit Results', font=Font(12), colour=self.colors.title, style=LCEN) wids['data_title'] = SimpleText(panel, '< > ', font=Font(12), colour=self.colors.title, style=LCEN) wids['hist_info'] = SimpleText(panel, ' ___ ', font=Font(12), colour=self.colors.title, style=LCEN) sizer.Add(title, (0, 0), (1, 2), LCEN) sizer.Add(wids['data_title'], (0, 2), (1, 2), LCEN) sizer.Add(wids['hist_info'], (0, 4), (1, 2), LCEN) irow = 1 wids['model_desc'] = SimpleText(panel, '<Model>', font=Font(12), size=(550, 75), style=LCEN) sizer.Add(wids['model_desc'], (irow, 0), (1, 6), LCEN) irow += 1 sizer.Add(HLine(panel, size=(400, 3)), (irow, 0), (1, 5), LCEN) irow += 1 title = SimpleText(panel, '[[Fit Statistics]]', font=Font(12), colour=self.colors.title, style=LCEN) sizer.Add(title, (irow, 0), (1, 4), LCEN) for label, attr in (('Fit method', 'method'), ('# Fit Evaluations', 'nfev'), ('# Data Points', 'ndata'), ('# Fit Variables', 'nvarys'), ('# Free Points', 'nfree'), ('Chi-square', 'chisqr'), ('Reduced Chi-square', 'redchi'), ('Akaike Info Criteria', 'aic'), ('Bayesian Info Criteria', 'bic')): irow += 1 wids[attr] = SimpleText(panel, '?') sizer.Add(SimpleText(panel, " %s = " % label), (irow, 0), (1, 1), LCEN) sizer.Add(wids[attr], (irow, 1), (1, 1), LCEN) irow += 1 sizer.Add(HLine(panel, size=(400, 3)), (irow, 0), (1, 5), LCEN) irow += 1 title = SimpleText(panel, '[[Variables]]', font=Font(12), colour=self.colors.title, style=LCEN) sizer.Add(title, (irow, 0), (1, 1), LCEN) self.wids['copy_params'] = Button(panel, 'Update Model with Best Fit Values', size=(250, -1), action=self.onCopyParams) sizer.Add(self.wids['copy_params'], (irow, 1), (1, 3), LCEN) dvstyle = dv.DV_SINGLE|dv.DV_VERT_RULES|dv.DV_ROW_LINES pview = self.wids['params'] = dv.DataViewListCtrl(panel, style=dvstyle) self.wids['paramsdata'] = [] pview.AppendTextColumn('Parameter', width=150) pview.AppendTextColumn('Best-Fit Value', width=100) pview.AppendTextColumn('Standard Error', width=100) pview.AppendTextColumn('Info ', width=275) for col in (0, 1, 2, 3): this = pview.Columns[col] isort, align = True, wx.ALIGN_LEFT if col in (1, 2): isort, align = False, wx.ALIGN_RIGHT this.Sortable = isort this.Alignment = this.Renderer.Alignment = align pview.SetMinSize((650, 200)) pview.Bind(dv.EVT_DATAVIEW_SELECTION_CHANGED, self.onSelectParameter) irow += 1 sizer.Add(pview, (irow, 0), (1, 5), LCEN) irow += 1 sizer.Add(HLine(panel, size=(400, 3)), (irow, 0), (1, 5), LCEN) irow += 1 title = SimpleText(panel, '[[Correlations]]', font=Font(12), colour=self.colors.title, style=LCEN) self.wids['all_correl'] = Button(panel, 'Show All', size=(100, -1), action=self.onAllCorrel) self.wids['min_correl'] = FloatCtrl(panel, value=MIN_CORREL, minval=0, size=(60, -1), gformat=True) ctitle = SimpleText(panel, 'minimum correlation: ') sizer.Add(title, (irow, 0), (1, 1), LCEN) sizer.Add(ctitle, (irow, 1), (1, 1), LCEN) sizer.Add(self.wids['min_correl'], (irow, 2), (1, 1), LCEN) sizer.Add(self.wids['all_correl'], (irow, 3), (1, 1), LCEN) irow += 1 cview = self.wids['correl'] = dv.DataViewListCtrl(panel, style=dvstyle) cview.AppendTextColumn('Parameter 1', width=150) cview.AppendTextColumn('Parameter 2', width=150) cview.AppendTextColumn('Correlation', width=100) for col in (0, 1, 2): this = cview.Columns[col] isort, align = True, wx.ALIGN_LEFT if col == 1: isort = False if col == 2: align = wx.ALIGN_RIGHT this.Sortable = isort this.Alignment = this.Renderer.Alignment = align cview.SetMinSize((450, 200)) irow += 1 sizer.Add(cview, (irow, 0), (1, 5), LCEN) irow += 1 sizer.Add(HLine(panel, size=(400, 3)), (irow, 0), (1, 5), LCEN) pack(panel, sizer) panel.SetupScrolling() mainsizer = wx.BoxSizer(wx.VERTICAL) mainsizer.Add(panel, 1, wx.GROW|wx.ALL, 1) pack(self, mainsizer) self.Show() self.Raise()