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) xrf_calib_compute(mca, apply=True, _larch=self.larch) 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, _larch=self.larch) for roi in self.mca.rois: eknown, ecen, fwhm, amp, fit = mca.init_calib[roi.name] diff = ecen - eknown for roiname, eknown, ocen, w_ncen, w_ndif, w_nwid, w_use in self.wids: if roiname == roi.name: 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], _larch=self.larch) mca.init_calib = init_calib tsize = self.GetSize() self.SetSize((tsize[0] + 1, tsize[1])) self.SetSize((tsize[0], tsize[1]))
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 __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 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) xrf_calib_compute(mca, apply=True, _larch=self.larch) 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, _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 for roiname, eknown, ocen, w_ncen, w_ndif, w_nwid, w_use in self.wids: if roiname == roi.name: 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], _larch=self.larch) mca.init_calib = init_calib tsize = self.GetSize() self.SetSize((tsize[0] + 1, tsize[1])) self.SetSize((tsize[0], tsize[1]))
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: eknown, ecen, fwhm, amp, fit = mca.init_calib[roi.name] 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, 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()