Source code for irfpy.vels.bible.kfactor

''' Implementation of K-factor.  Section 4 of :ref:`vexelsbible`.

This is an energy-averaged k-factor.
'''

import numpy as np

[docs]def kfactors(): ''' Return the list of k-factor. It refers to Table 1 in the bible. :returns: The k-factors of the specified anode in eV/V :rtype: ``nparray`` ''' return np.array([10.490, 10.627, 10.824, 10.956, 11.077, 11.192, 11.310, 11.397, 11.315, 11.193, 11.007, 11.808, 10.558, 10.419, 10.355, 10.363])
[docs]def fit_kfactor(): ''' Return the function of the k-factor. It refers to the equation (1) in bible. :returns: Function of k-factor. The function will take 1 argument specifying anode. >>> func_kfactor = fit_kfactor() # Return the function of k-factor >>> k10 = func_kfactor(10) # Return the k-factor of anode 10. >>> print('%.3f' % k10) 11.012 ''' func = lambda x: (((0.000323 * x - 0.00889) * x + 0.0573) * x + 0.0424 ) * x + 10.518 return func
[docs]def kfactor(anode, src="table"): ''' Return the k-factor of the specified anode. :param anode: The number of anode. :keyword src: The source, ``"table"`` or ``"fit"``. ``"table"`` refers to :func:`kfactor` and ``"fit"`` referes to :func:`fit_kfactor`. >>> print(kfactor(5)) 11.192 >>> print("%.3f" % kfactor(5, src="fit")) 11.253 ''' if src == "table": return kfactors()[anode] elif src == "fit": return (fit_kfactor())(anode) else: raise ValueError("Unknown source for kfactor")
import unittest,doctest
[docs]def doctests(): return unittest.TestSuite(( doctest.DocTestSuite(), ))
if __name__=='__main__': unittest.main(defaultTest='doctests')