예제 #1
0
    def onFitPeaks(self, event=None):
        print( 'Fit Peaks')
        opts = {}
        filters, peaks = [], []
        sig, det, bgr = {}, {}, {}

        opts['flyield']  = self.wids.flyield_use.IsChecked()
        opts['xray_en']  = self.wids.xray_en.GetValue()
        opts['emin']     = self.wids.fit_emin.GetValue()
        opts['emax']     = self.wids.fit_emax.GetValue()

        det['use']       = self.wids.det_use.IsChecked()
        det['thickness'] = self.wids.det_thk.GetValue()
        det['material']  = self.wids.det_mat.GetStringSelection()

        bgr['use']       = self.wids.bgr_use.IsChecked()
        bgr['width']     = self.wids.bgr_width.GetValue()
        bgr['compress']  = int(self.wids.bgr_compress.GetStringSelection())
        bgr['exponent']  = int(self.wids.bgr_exponent.GetStringSelection())

        sig['offset']    = self.wids.sig_offset.param
        sig['slope']     = self.wids.sig_slope.param
        sig['quad']      = self.wids.sig_quad.param

        for k in self.wids.filters:
            f = (k[0].GetStringSelection(), k[1].GetValue(), k[2].param)
            filters.append(f)

        for k in self.wids.peaks:
            p = (k[0].IsChecked(), k[1].param, k[2].param, k[3].param)
            peaks.append(p)

        opts  = {'det': det, 'bgr': bgr, 'sig': sig,
                 'filters': filters, 'peaks': peaks}
        for key, val in opts.items():
            print( key, val)

        mca    = self.mca
        mca.data = mca.counts*1.0
        energy = mca.energy
        _larch = self.parent.larch
        if bgr.pop('use'):
            xrf_background(energy=mca.energy, counts=mca.counts,
                           group=mca, _larch=_larch, **bgr)
            mca.data = mca.data - mca.bgr

        if det.pop('use'):
            # mu in 1/mm, note energy is needed in eV
            mu = material_mu(det['material'], energy*1000.0, _larch=_larch)/10.0
            t = det['thickness']
            mca.det_atten = np.exp(-t*mu)
            mca.data = mca.data / np.maximum(1.e-49, (1.0 - mca.det_atten))
예제 #2
0
    def onShowBgr(self, event=None):
        mca    = self.mca
        parent = self.parent
        width  = self.wids['bgr_width'].GetValue()/1000.0
        expon  = int(self.wids['bgr_expon'].GetStringSelection())

        xrf_background(energy=mca.energy, counts=mca.counts, group=mca,
                       width=width, exponent=expon, _larch=parent.larch)

        mca.bgr_width = width
        mca.bgr_expoent = expon
        parent.plotmca(mca)
        parent.oplot(mca.energy, mca.bgr, label='background',
                     color=parent.conf.bgr_color, linewidth=2, style='--')
예제 #3
0
 def onShowBgr(self, event=None):
     wids     = self.wids
     mca      = self.mca
     parent   = self.parent
     width    = wids.bgr_width.GetValue()
     compress = int(wids.bgr_compress.GetStringSelection())
     exponent = int(wids.bgr_exponent.GetStringSelection())
     xrf_background(energy=mca.energy, counts=mca.counts,
                    group=mca, width=width, compress=compress,
                    exponent=exponent, _larch=parent.larch)
     mca.bgr_width = width
     mca.bgr_compress = compress
     mca.bgr_exponent = exponent
     parent.plotmca(mca)
     parent.oplot(mca.energy, mca.bgr, label='background',
                  color=parent.conf.bgr_color)
예제 #4
0
 def onShowBgr(self, event=None):
     wids     = self.wids
     mca      = self.mca
     parent   = self.parent
     width    = wids.bgr_width.GetValue()
     compress = int(wids.bgr_compress.GetStringSelection())
     exponent = int(wids.bgr_exponent.GetStringSelection())
     xrf_background(energy=mca.energy, counts=mca.counts,
                    group=mca, width=width, compress=compress,
                    exponent=exponent, _larch=parent.larch)
     mca.bgr_width = width
     mca.bgr_compress = compress
     mca.bgr_exponent = exponent
     parent.plotmca(mca)
     parent.oplot(mca.energy, mca.bgr, label='background',
                  color=parent.conf.bgr_color, linewidth=1, style='--')
예제 #5
0
    def onFitPeaks(self, event=None):
        opts = {}
        filters, peaks = [], []
        sig, det, bgr = {}, {}, {}

        opts['flyield'] = self.wids.flyield_use.IsChecked()
        opts['xray_en'] = self.wids.xray_en.GetValue()
        opts['emin'] = self.wids.fit_emin.GetValue()
        opts['emax'] = self.wids.fit_emax.GetValue()

        det['use'] = self.wids.det_use.IsChecked()
        det['thickness'] = self.wids.det_thk.GetValue()
        det['material'] = self.wids.det_mat.GetStringSelection()

        bgr['use'] = self.wids.bgr_use.IsChecked()
        bgr['width'] = self.wids.bgr_width.GetValue()
        bgr['compress'] = int(self.wids.bgr_compress.GetStringSelection())
        bgr['exponent'] = int(self.wids.bgr_exponent.GetStringSelection())

        sig['offset'] = self.wids.sig_offset.param
        sig['slope'] = self.wids.sig_slope.param
        sig['quad'] = self.wids.sig_quad.param

        for k in self.wids.filters:
            f = (k[0].GetStringSelection(), k[1].GetValue(), k[2].param)
            filters.append(f)

        for k in self.wids.peaks:
            use = k[0].IsChecked()
            p = (k[0].IsChecked(), k[1].param, k[2].param, k[3].param)
            peaks.append(p)
            if not use:
                k[1].param.vary = False
                k[2].param.vary = False
                k[3].param.vary = False

        opts['det'] = det
        opts['bgr'] = bgr
        opts['sig'] = sig
        opts['filters'] = filters
        opts['peaks'] = peaks

        mca = self.mca
        mca.data = mca.counts * 1.0
        energy = mca.energy
        _larch = self.parent.larch
        if bgr['use']:
            bgr.pop('use')
            xrf_background(energy=mca.energy,
                           counts=mca.counts,
                           group=mca,
                           _larch=_larch,
                           **bgr)
            opts['use_bgr'] = True
        opts['mca'] = mca
        if det['use']:
            mu = material_mu(det['material'], energy * 1000.0,
                             _larch=_larch) / 10.0
            t = det['thickness']
            mca.det_atten = np.exp(-t * mu)

        fit = Minimizer(xrf_resid,
                        self.paramgroup,
                        toler=1.e-4,
                        _larch=_larch,
                        fcn_kws=opts)
        fit.leastsq()
        parent = self.parent
        parent.oplot(mca.energy,
                     mca.model,
                     label='fit',
                     style='solid',
                     color='#DD33DD')

        print(fitting.fit_report(self.paramgroup, _larch=_larch))
예제 #6
0
    def onFitPeaks(self, event=None):
        opts = {}
        filters, peaks = [], []
        sig, det, bgr = {}, {}, {}

        opts['flyield']  = self.wids.flyield_use.IsChecked()
        opts['xray_en']  = self.wids.xray_en.GetValue()
        opts['emin']     = self.wids.fit_emin.GetValue()
        opts['emax']     = self.wids.fit_emax.GetValue()

        det['use']       = self.wids.det_use.IsChecked()
        det['thickness'] = self.wids.det_thk.GetValue()
        det['material']  = self.wids.det_mat.GetStringSelection()

        bgr['use']       = self.wids.bgr_use.IsChecked()
        bgr['width']     = self.wids.bgr_width.GetValue()
        bgr['compress']  = int(self.wids.bgr_compress.GetStringSelection())
        bgr['exponent']  = int(self.wids.bgr_exponent.GetStringSelection())

        sig['offset']    = self.wids.sig_offset.param
        sig['slope']     = self.wids.sig_slope.param
        sig['quad']      = self.wids.sig_quad.param

        for k in self.wids.filters:
            f = (k[0].GetStringSelection(), k[1].GetValue(), k[2].param)
            filters.append(f)

        for k in self.wids.peaks:
            use = k[0].IsChecked()
            p = (k[0].IsChecked(), k[1].param, k[2].param, k[3].param)
            peaks.append(p)
            if not use:
                k[1].param.vary = False
                k[2].param.vary = False
                k[3].param.vary = False

        opts['det'] = det
        opts['bgr'] = bgr
        opts['sig'] = sig
        opts['filters'] = filters
        opts['peaks'] = peaks

        mca    = self.mca
        mca.data = mca.counts*1.0
        energy = mca.energy
        _larch = self.parent.larch
        if bgr['use']:
            bgr.pop('use')
            xrf_background(energy=mca.energy, counts=mca.counts,
                           group=mca, _larch=_larch, **bgr)
            opts['use_bgr']=True
        opts['mca'] = mca
        if det['use']:
            mu = material_mu(det['material'], energy*1000.0,
                             _larch=_larch)/10.0
            t = det['thickness']
            mca.det_atten = np.exp(-t*mu)

        fit = Minimizer(xrf_resid, self.paramgroup, toler=1.e-4,
                        _larch=_larch, fcn_kws = opts)
        fit.leastsq()
        parent = self.parent
        parent.oplot(mca.energy, mca.model,
                     label='fit', style='solid',
                     color='#DD33DD')

        print( fitting.fit_report(self.paramgroup, _larch=_larch))