Exemplo n.º 1
0
def fluo_corr(energy, mu, formula, elem, group=None, edge='K', anginp=45,
              angout=45,  _larch=None, **pre_kws):
    """correct over-absorption (self-absorption) for fluorescene XAFS
    using the FLUO alogrithm of D. Haskel.

    Arguments
    ---------
      energy    array of energies
      mu        uncorrected fluorescence mu
      formula   string for sample stoichiometry
      elem      atomic symbol or Z of absorbing element
      group     output group [default None]
      edge      name of edge ('K', 'L3', ...) [default 'K']
      anginp    input angle in degrees  [default 45]
      angout    output angle in degrees  [default 45]

    Additional keywords will be passed to pre_edge(), which will be used
    to ensure consistent normalization.

    Returns
    --------
       None, writes `mu_corr` and `norm_corr` (normalized `mu_corr`)
       to output group.

    Notes
    -----
       Support First Argument Group convention, requiring group
       members 'energy' and 'mu'
    """
    energy, mu, group = parse_group_args(energy, members=('energy', 'mu'),
                                         defaults=(mu,), group=group,
                                         fcn_name='fluo_corr')

    # generate normalized mu for correction
    preinp   = preedge(energy, mu, **pre_kws)
    mu_inp   = preinp['norm']

    anginp   = max(1.e-7, np.deg2rad(anginp))
    angout   = max(1.e-7, np.deg2rad(angout))

    # find edge energies and fluorescence line energy
    e_edge   = xray_edge(elem, edge, _larch=_larch)[0]
    e_fluor  = xray_line(elem, edge, _larch=_larch)[0]

    # calculate mu(E) for fluorescence energy, above, below edge
    energies = np.array([e_fluor, e_edge-10.0, e_edge+10.0])
    muvals   = material_mu(formula, energies, density=1, _larch=_larch)

    mu_fluor = muvals[0] * np.sin(anginp)/np.sin(angout)
    mu_below = muvals[1]
    mu_celem = muvals[2] - muvals[1]

    alpha    = (mu_fluor + mu_below)/mu_celem
    mu_corr  = mu_inp*alpha/(alpha + 1 - mu_inp)
    preout   = preedge(energy, mu_corr, **pre_kws)

    if group is not None:
        group = set_xafsGroup(group, _larch=_larch)
        group.mu_corr = mu_corr
        group.norm_corr = preout['norm']
Exemplo n.º 2
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))
Exemplo n.º 3
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))
Exemplo n.º 4
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))
Exemplo n.º 5
0
def fluo_corr(energy,
              mu,
              formula,
              elem,
              group=None,
              edge='K',
              anginp=45,
              angout=45,
              _larch=None,
              **pre_kws):
    """correct over-absorption (self-absorption) for fluorescene XAFS
    using the FLUO alogrithm of D. Haskel.

    Arguments
    ---------
      energy    array of energies
      mu        uncorrected fluorescence mu
      formula   string for sample stoichiometry
      elem      atomic symbol or Z of absorbing element
      group     output group [default None]
      edge      name of edge ('K', 'L3', ...) [default 'K']
      anginp    input angle in degrees  [default 45]
      angout    output angle in degrees  [default 45]

    Additional keywords will be passed to pre_edge(), which will be used
    to ensure consistent normalization.

    Returns
    --------
       None, writes `mu_corr` and `norm_corr` (normalized `mu_corr`)
       to output group.

    Notes
    -----
       Support First Argument Group convention, requiring group
       members 'energy' and 'mu'
    """
    energy, mu, group = parse_group_args(energy,
                                         members=('energy', 'mu'),
                                         defaults=(mu, ),
                                         group=group,
                                         fcn_name='fluo_corr')

    # generate normalized mu for correction
    preinp = preedge(energy, mu, **pre_kws)
    mu_inp = preinp['norm']

    anginp = max(1.e-7, np.deg2rad(anginp))
    angout = max(1.e-7, np.deg2rad(angout))

    # find edge energies and fluorescence line energy
    e_edge = xray_edge(elem, edge, _larch=_larch)[0]
    e_fluor = xray_line(elem, edge, _larch=_larch)[0]

    # calculate mu(E) for fluorescence energy, above, below edge
    energies = np.array([e_fluor, e_edge - 10.0, e_edge + 10.0])
    muvals = material_mu(formula, energies, density=1, _larch=_larch)

    mu_fluor = muvals[0] * np.sin(anginp) / np.sin(angout)
    mu_below = muvals[1]
    mu_celem = muvals[2] - muvals[1]

    alpha = (mu_fluor + mu_below) / mu_celem
    mu_corr = mu_inp * alpha / (alpha + 1 - mu_inp)
    preout = preedge(energy, mu_corr, **pre_kws)

    if group is not None:
        group = set_xafsGroup(group, _larch=_larch)
        group.mu_corr = mu_corr
        group.norm_corr = preout['norm']
Exemplo n.º 6
0
 def calc_mu(self, energy):
     self.mu_total = material_mu(self.material, energy, kind='total')
     self.mu_photo = material_mu(self.material, energy, kind='photo')