Skip to content
ttrainor edited this page Jan 8, 2012 · 2 revisions

Xrf Data

Important Modules / Packages

  • modules/xrf
  • modules/spectra

Example Working on single data file

Note the data in this example is from a multielement detector
and several 'dead' detectors are excluded. The data from the
good detectors is totaled and aligned.
We also only read in the data within a specified energy range

import the ana module and read file

>>x = ana.xrf_data.read(file='test.xrf',bad_mca_idx=[0,2,13],emin=4.,emax=9.)
>>plot(x.get_energy(),x.get_data(),'or')

Initialize xrf lines. XRF lines are recognized when passed as 'Element line' string. You can also pass a energy value in this case the name of the peak will be the same as the energy. By default the intensity and FWHM of the peaks are guessed from the data

>>x.init_lines(['Fe ka',7.12])
>>x.calc()
>>plot(x.get_energy(),x.predicted,'-ok')

Run fit using default settings

>>x.fit()
>>en = x.get_energy()
>>plot(en,x.predicted,'-b')

Here we can get the calculated values for each individual peak

>>cnts = x.calc_peaks()
>>for j in range(len(x.peaks)):
>>  pyplot.plot(en,cnts[j],'.')
>>#make the plot log
>>pyplot.semilogy()
>># display the xrf object ~ useful summary info
>>print x

Work on a spectra scan

Setup to read in files (this is a spec spectra scan). Note this is a single element detector and we include its deadtime (tau) parameter

>>reader = specfile.reader.Reader(spec='bb405_0405.spc')
>>reader.spectra_params['tau'] = 1.0e-8
>>reader.spectra_params['lines'] = ['Ca ka','Ca kb','Ti ka','Ti kb','Mn ka','Mn kb', 'Fe ka', 'Fe kb']

Read xrf scan

>>s6 = reader.spec_scan(6,xrf=True)

Fit the scan using the 15th point to initialize all the fit parameters (by default these parameters will be used as the seed parameters for all other fits)

>>s6.xrf.fit(fit_init=15)
>>plot s6['Psi'], s6['Mn ka']/s6['io'], 'k.'

Copy the fit parameters to the reader so all future reads will have same init'd parameters

>>npts = len(s6['Psi'])
>>p = s6.xrf.xrf[npts-1].get_params()
>>reader.spectra_params['xrf_params'] = p

Read another scan and fit it

>>s7 = reader.spec_scan(7)
>>s7.xrf.fit()
>>plot s7['Psi'], s7['Mn ka']/s7['io'], 'r.-'

Append the two scans (note this needs to be fixed... broken at the moment)

>>s67 = ana.scan_data.append(s6,s7)

Fitting a deadtime curve

Read the scan and fit it. Note assume that this scan is slit position or something else that will produce a linear change in intensity going into the fluorescence detector. For the 'x-axis' use the io detector, since we assume this will respond linearly to a change in intensity.

>>reader = specfile.reader.Reader(spec='spec_file.spc')
>>data = reader.spec_scan(7,med=True)
>>tau = ana.scan_data.fit_deadtime(data,x='io')

Now you can add these tau values to the reader so they get applied whenever you read a scan with spectra

>>reader.spectra_params['tau'] = tau
>>s7 = reader.spec_scan(7,xrf=True)
Clone this wiki locally