Calibration

class curie.Calibration(filename=None)[source]

Calibration for HPGe spectra

Provides methods for calculating and fitting energy, efficiency and resolution calibrations for HPGe spectra. Each Spectrum class contains a Calibration, which can be loaded from a file, or fit to calibration spectra from known sources.

Parameters:
filenamestr, optional

Path to a .json file storing calibration data. The .json file can be produced by calling cb.saveas(‘example_calib.json’) after performing a calibration fit with the cb.calibrate() function. This allows past calibrations to be recalled without needing to re-perform the calibration fits.

Examples

>>> cb = Calibration()
>>> cb.engcal = [0.0, 0.25, 0.001]
>>> print(cb.engcal)
[0.0 0.3]
>>> print(cb.effcal)
[0.02 8.3 2.1 1.66 0.4]
>>> cb.saveas('test_calib.json')
>>> cb = Calibration('test_calib.json')
>>> print(cb.engcal)
[0.0 0.25 0.001]
Attributes:
engcalnp.ndarray

Energy calibration parameters. length 2 or 3 array, depending on whether the calibration is linear or quadratic.

effcalnp.ndarray

Efficiency calibration parameters. length 3 or 5 array, depending on whether the efficiency fit includes a “dead-layer term”.

unc_effcalnp.ndarray

Efficiency calibration covariance matrix. shape 3x3 or 5x5, depending on the length of effcal.

rescalnp.ndarray

Resolution calibration parameters. length 2 array if resolution calibration is of the form R = a + b*chan (default), or length 1 if R = a*sqrt(chan).

Methods

calibrate(spectra, sources)

Generate calibration parameters from spectra

eff(energy[, effcal])

Efficiency calibration function

eng(channel[, engcal])

Energy calibration function

map_channel(energy[, engcal])

Energy to channel calibration

plot(**kwargs)

Plots energy, resolution and efficiency calibrations

plot_effcal(**kwargs)

Plot the efficiency calibration

plot_engcal(**kwargs)

Plot the energy calibration

plot_rescal(**kwargs)

Plot the resolution calibration

res(channel[, rescal])

Resolution calibration

saveas(filename)

Save the calibration as a .json file

unc_eff(energy[, effcal, unc_effcal])

Uncertainty in the efficiency

calibrate(spectra, sources)[source]

Generate calibration parameters from spectra

Performs an energy, resolution and efficiency calibration on peak fits to a given list of spectra. Reference activities _MUst be given for the efficiency calibration. Spectra are allowed to have isotopes that are not in sources, but these will not be included in the efficiency calibration.

Parameters:
spectralist of sp.Spectrum

List of calibration spectra. Must have sp.isotopes defined, and matching the isotopes given in sources.

sourcesstr, list, dict or pd.DataFrame

Datatype or (if str) file that can be converted into a pandas DataFrame. Required keys are ‘isotope’, ‘A0’ (reference activity), and ‘ref_date’ (reference date).

Examples

>>> sp = ci.Spectrum('eu_calib_7cm.Spe')
>>> sp.isotopes = ['152EU']
>>> cb = ci.Calibration()
>>> cb.calibrate([sp], sources=[{'isotope':'152EU', 'A0':3.5E4, 'ref_date':'01/01/2009 12:00:00'}])
>>> print(cb.effcal)
[4.33742771 2.28579733 0.15337749]
>>> cb.plot()
eff(energy, effcal=None)[source]

Efficiency calibration function

Returns the calculated (absolute) efficiency given an input array of energies. The effcal can be supplied, or if effcal=None, the calibration object’s internal efficiency calibration (cb.effcal) is used.

The functional form of the efficiency used is a modified version of the semi-empirical formula proposed by Vidmar (2001): eff(E) = c[0]*(1.0-exp(-mu(eng)*c[1]))*(tau(eng)+sigma(eng)*(1.0-exp(-(mu(eng)*c[3])**c[2]))*c[4])/mu(eng) if the effcal is length 5 or eff(E) = c[0]*exp(-mu_w(eng)*c[5])*exp(-mu(eng)*c[6])*(1.0-exp(-mu(eng)*c[1]))*(tau(eng)+sigma(eng)*(1.0-exp(-(mu(eng)*c[3])**c[2]))*c[4])/mu(eng) if the effcal is length 7.

Parameters:
energyarray_like

Peak energy in keV.

effcalarray_like, optional

Efficiency calibration parameters. length 5 or 7 array, depending on whether the efficiency fit includes the low-energy components.

Returns:
efficiencynp.ndarray

Absolute efficiency at the given energies.

Examples

>>> cb = ci.Calibration()
>>> print(cb.effcal)
[0.02 8.3 2.1 1.66 0.4]
>>> print(cb.eff(50*np.arange(1,10)))
[0.04152215 0.06893742 0.07756411 0.07583971 0.07013108 0.06365222
 0.05762826 0.05236502 0.0478359 ]
eng(channel, engcal=None)[source]

Energy calibration function

Returns the calculated energy given an input array of channel numbers. The engcal can be supplied, or if engcal=None the Calibration object’s energy calibration is used (cb.engcal).

Parameters:
channelarray_like

Spectrum channel number. The maxi_MUm channel number should be the length of the spectrum.

engcalarray_like, optional

Optional energy calibration. If a length 2 array, calibration will be engcal[0] + engcal[1]*channel. If length 3, then engcal[0] + engcal[1]*channel + engcal[2]*channel**2

Returns:
energy: np.ndarray

Calibrated energy corresponding to the given channels.

Examples

>>> cb = ci.Calibration()
>>> print(cb.engcal)
[0.  0.3]
>>> print(cb.eng(np.arange(10)))
[0.  0.3 0.6 0.9 1.2 1.5 1.8 2.1 2.4 2.7]
>>> cb.engcal = [0.1, 0.2, 0.003]
>>> print(cb.eng(np.arange(10)))
[0.1   0.303 0.512 0.727 0.948 1.175 1.408 1.647 1.892 2.143]
map_channel(energy, engcal=None)[source]

Energy to channel calibration

Calculates the spectrum channel number corresponding to a given energy array. This should return the inverse of the energy calibration, but as an integer-type channel number.

Parameters:
energyarray_like

Peak energy in keV

engcalarray_like, optional

Energy calibration parameters. length 2 or 3 array, depending on whether the calibration is linear or quadratic.

Returns:
channelnp.ndarray

Calculated channel number given the input energy array

Examples

>>> cb = ci.Calibration()
>>> print(cb.engcal)
[0.  0.3]
>>> print(cb.map_channel(300))
1000
>>> print(cb.eng(cb.map_channel(300)))
300.0
plot(**kwargs)[source]

Plots energy, resolution and efficiency calibrations

Draws all three of energy, resolution and efficiency calibrations on a single figure, and shows measured values from peak data, if available.

Other Parameters:
**kwargs

Optional keyword arguments for plotting. See the plotting section of the curie API for a complete list of kwargs.

Examples

>>> sp = ci.Spectrum('eu_calib_7cm.Spe')
>>> sp.isotopes = ['152EU']
>>> cb = ci.Calibration()
>>> cb.calibrate([sp], sources=[{'isotope':'152EU', 'A0':3.5E4, 'ref_date':'01/01/2009 12:00:00'}])
>>> cb.plot()
plot_effcal(**kwargs)[source]

Plot the efficiency calibration

Draws the efficiency calibration, with measurements from peak fit data if available.

Other Parameters:
**kwargs

Optional keyword arguments for plotting. See the plotting section of the curie API for a complete list of kwargs.

Examples

>>> sp = ci.Spectrum('eu_calib_7cm.Spe')
>>> sp.isotopes = ['152EU']
>>> cb = ci.Calibration()
>>> cb.calibrate([sp], sources=[{'isotope':'152EU', 'A0':3.5E4, 'ref_date':'01/01/2009 12:00:00'}])
>>> cb.plot_effcal()
plot_engcal(**kwargs)[source]

Plot the energy calibration

Draws the energy calibration, with measurements from peak fit data if available.

Other Parameters:
**kwargs

Optional keyword arguments for plotting. See the plotting section of the curie API for a complete list of kwargs.

Examples

>>> sp = ci.Spectrum('eu_calib_7cm.Spe')
>>> sp.isotopes = ['152EU']
>>> cb = ci.Calibration()
>>> cb.calibrate([sp], sources=[{'isotope':'152EU', 'A0':3.5E4, 'ref_date':'01/01/2009 12:00:00'}])
>>> cb.plot_engcal()
plot_rescal(**kwargs)[source]

Plot the resolution calibration

Draws the resolution calibration, with measurements from peak fit data if available.

Other Parameters:
**kwargs

Optional keyword arguments for plotting. See the plotting section of the curie API for a complete list of kwargs.

Examples

>>> sp = ci.Spectrum('eu_calib_7cm.Spe')
>>> sp.isotopes = ['152EU']
>>> cb = ci.Calibration()
>>> cb.calibrate([sp], sources=[{'isotope':'152EU', 'A0':3.5E4, 'ref_date':'01/01/2009 12:00:00'}])
>>> cb.plot_rescal()
res(channel, rescal=None)[source]

Resolution calibration

Calculates the expected 1-sigma peak widths for a given input array of channel numbers. If rescal is given, it is used instead of the calibration object’s internal value (cb.rescal).

Parameters:
channelarray_like

Spectrum channel number. The maxi_MUm channel number should be the length of the spectrum.

rescalarray_like, optional

Resolution calibration parameters. length 2 array if resolution calibration is of the form R = a + b*chan (default), or length 1 if R = a*sqrt(chan).

Returns:
resolutionnp.ndarray

Calculated 1-sigma width of the peaks given the input channel numbers.

Examples

>>> cb = ci.Calibration()
>>> print(cb.rescal)
[2.e+00 4.e-04]
>>> print(cb.res(100*np.arange(1,10)))
[2.04 2.08 2.12 2.16 2.2  2.24 2.28 2.32 2.36]
saveas(filename)[source]

Save the calibration as a .json file

Saves the energy, resolution and efficiency calibration to a .json file, which can be recalled by a new calibration object by passing the ‘filename’ keyword to Calibration() upon construction.

Parameters:
filenamestr

Complete filename to save the calibration. Must end in ‘.json’.

Examples

>>> sp = ci.Spectrum('eu_calib_7cm.Spe')
>>> sp.isotopes = ['152EU']
>>> cb = ci.Calibration()
>>> cb.calibrate([sp], sources=[{'isotope':'152EU', 'A0':3.5E4, 'ref_date':'01/01/2009 12:00:00'}])
>>> print(cb.effcal)
[4.33742771 2.28579733 0.15337749]
>>> cb.saveas('example_calib.json')
>>> cb = ci.Calibration('example_calib.json')
>>> print(cb.effcal)
[4.33742771 2.28579733 0.15337749]
unc_eff(energy, effcal=None, unc_effcal=None)[source]

Uncertainty in the efficiency

Returns the calculated uncertainty in efficiency for an input array of energies. If effcal or unc_effcal are not none, they are used instead of the calibration object’s internal values. (cb.unc_effcal) unc_effcal _MUst be a covariance matrix of the same dimension as effcal.

Parameters:
energyarray_like

Peak energy in keV.

effcalarray_like, optional

Efficiency calibration parameters. length 5 or 7 array, depending on whether the efficiency fit includes the low-energy components.

unc_effcalarray_like, optional

Efficiency calibration covariance matrix. shape 5x5 or 7x7, depending on the length of effcal.

Returns:
unc_efficiencynp.ndarray

Absolute uncertainty in efficiency for the given energies.

Examples

>>> cb = ci.Calibration()
>>> print(cb.effcal)
[0.02 8.3 2.1 1.66 0.4]
>>> print(cb.unc_effcal)
[[ 5.038e-02  3.266e-02 -2.151e-02 -4.869e-05 -7.748e-03]
 [ 3.266e-02  2.144e-02 -1.416e-02 -3.416e-05 -4.137e-03]
 [-2.151e-02 -1.416e-02  9.367e-03  2.294e-05  2.569e-03]
 [-4.869e-05 -3.416e-05  2.294e-05  5.411e-07 -1.165e-04]
 [-7.748e-03 -4.137e-03  2.569e-03 -1.165e-04  3.332e-02]]
>>> print(cb.eff(50*np.arange(1,10)))
[0.04152215 0.06893742 0.07756411 0.07583971 0.07013108 0.06365222
 0.05762826 0.05236502 0.0478359 ]
>>> print(cb.unc_eff(50*np.arange(1,10)))
[0.00453714 0.00795861 0.00705099 0.00514765 0.00453579 0.00433504
 0.00394935 0.00347228 0.00304041]