# irfpy.vels.bible.flux¶

Calculation of flux, see Section 10 in VEX/ELS bible.

The flux conversion is made using following functions.

raw2cps() and raw2cps_np()

Function to convert the raw count to count-per-second.

raw2def() and raw2def_np()

Function to convert the raw count to differential energy flux.

raw2dnf() and raw2dnf_np()

Function to convert the raw count to differential number flux.

raw2psd() and raw2psd_np()

Function to convert the raw count to phase space density.

A sample use of this module can be found in the vels_flux_onecount.

irfpy.vels.bible.flux.anode_area_ratio()[source]

The anode area ratio used to calculate the flux.

According to the VEX/ELS bible, it is defined as the proportion of the anode area that actually measures counts ($$A_A$$). The function always returns 0.87.

>>> print('%.3f' % anode_area_ratio())
0.870

irfpy.vels.bible.flux.raw2cps(raw)[source]

Return “counts-per-sec”.

Parameters

raw (It is normally an integer, but float is also allowed. The float is used for different binning parameter and time compression.) – Raw count

>>> cnt = 1
>>> cps = raw2cps(1)
>>> print('%.3f' % cps)
35.556

irfpy.vels.bible.flux.raw2cps_np(raw_np)[source]

Return the “count-per-sec” for numpy array.

A numpy array version of raw2cps() function.

Parameters

raw_np (numpy.array. Typically 128x16 shaped array, but not restricted.) – numpy.array of the raw count data.

Returns

Count per sec as numpy array.

Return type

numpy.array with the same shape of the raw_np.

>>> cnts = np.array([0,1,2,3,4,5])
>>> cpss = raw2cps_np(cnts)
>>> print(cpss)
0.0
>>> print(cpss.shape)
(6,)
>>> print('%.1f' % cpss)
177.8

irfpy.vels.bible.flux.raw2def(raw, energy, anode)[source]

Return the differential energy flux (DEF). See equation (7) in section 10 in VEX/ELS bible.

Parameters
• raw – Raw count

• energy (float) – Energy in eV. The value should be taken using irfpy.vels.bible.energy module.

• anode (int) – Anode number

Returns

The differential energy flux in the unit of eV/eV cm2 sr s.

>>> cnt = 1
>>> je_1 = raw2def(1, 30, 5)  # one count level for 30 eV, anode 5
>>> print('%.2e' % je_1)
5.56e+06

irfpy.vels.bible.flux.raw2def_np(raw_np, energy_np, anode_np)[source]

Return the DEF. A vectorized version of raw2def().

Parameters
• raw_np (numpy.array of float with shape of (nE, nD)) – Raw count matrix. Shape should be (nE, nD) where nE is the number of energy step, and nD is the number of the anode (direction).

• energy_np (numpy.array of float with shape of (nE,) or (nE, nD)) – Energy step in eV. Shape should be (nE,) or (nE, nD)

• anode_np (numpy.array of int with shape of (nD,)) – Anode number. Shape should be (nD,).

Returns

The differential energy flux in the unit of eV/eV cm2 sr s.

Raises ValueError if the shapes are inconsistent.

>>> etbl = np.array([1., 10, 100, 1000, 10000])   # As a sample, 5 energy steps assumed.
>>> anod = np.array([0, 1, 2, 3])   # As a sample, 4 anode steps assumed.
>>> cnts = np.ones([5, 4])   # Count data should have shape of (*nE*, *nD*).

>>> deflux = raw2def_np(cnts, etbl, anod)
>>> print(deflux.shape)
(5, 4)
>>> print('%.3e' % deflux[3, 2])   # One count level of 1000 eV Anode=2
4.102e+06
>>> print('%.3e' % raw2def(1, 1000., 2))   # Scalar version for confirmation
4.102e+06

irfpy.vels.bible.flux.raw2dnf(raw, energy, anode)[source]

Return the differential number flux (DNF).

Apart from the equation (8) in section 10 in VEX/ELS bible, I used here the unit in /eV cm2 sr s.

Parameters
• raw – Raw count

• energy (float) – Energy in eV

• anode (int) – Anode number

Returns

The differential number flux in the unit of /eV cm2 sr s.

>>> cnt = 1
>>> jn_1 = raw2dnf(1, 30, 5)  # one count level for 30 eV, anode 5
>>> print('%.2e' % jn_1)
1.85e+05

irfpy.vels.bible.flux.raw2dnf_np(raw_np, energy_np, anode_np)[source]

Return the DNF. A vectorized version of raw2dnf().

Parameters
• raw_np (numpy.array of float with shape of (nE, nD)) – Raw count matrix. Shape should be (nE, nD) where nE is the number of energy step, and nD is the number of the anode (direction).

• energy_np (numpy.array of float with shape of (nE,) or (nE, nD)) – Energy step in eV. Shape should be (nE,) or (nE, nD)

• anode_np (numpy.array of int with shape of (nD,)) – Anode number. Shape should be (nD,).

Returns

The differential number flux in the unit of /eV cm2 sr s.

Raises ValueError if the shapes are inconsistent.

>>> etbl = np.array([1., 10, 100, 1000, 10000])   # As a sample, 5 energy steps assumed.
>>> anod = np.arange(16)   # As a sample, 16 anode steps assumed.
>>> cnts = np.ones([5, 16])   # Count data should have shape of (*nE*, *nD*).

>>> dnflux = raw2dnf_np(cnts, etbl, anod)
>>> print(dnflux.shape)
(5, 16)
>>> print('%.3e' % dnflux[2, 8])   # One count level of 100 eV Anode=8
5.086e+04
>>> print('%.3e' % raw2dnf(1, 100., 8))   # Scalar version for confirmation
5.086e+04

irfpy.vels.bible.flux.raw2psd(raw, energy, anode)[source]

Return the phase space density (PSD).

Note

I think the VEX/ELS bible contains error in the equation 10. According to the definition, earray is in eV and E is J/eV. Thus, $$earray \times E$$ should be in J = kg m2 / s2. To use the unit of cm, the term should be changed to be ((1e2)^2 x earray x E). So the right expressions is $$PSD [cm^{-6} s^3] = \frac{raw \times m_e^2} {GF \times accutime \times 2 \times (1e4 \times earray \times E)^2 \times A_A}$$

Parameters
• raw – Raw count

• energy (float) – Energy in eV

• anode (int) – Anode number

Returns

PSD in the unit of cm-6 s3.

>>> cnt = 1
>>> f_1 = raw2psd(1, 30, 5)  # one count level for 30 eV, anode 5
>>> print('%.2e' % f_1)
1.00e-27

irfpy.vels.bible.flux.raw2psd_np(raw_np, energy_np, anode_np)[source]

Return the PSD. A vectorized version of raw2psd().

Parameters
• raw_np (numpy.array of float with shape of (nE, nD)) – Raw count matrix. Shape should be (nE, nD) where nE is the number of energy step, and nD is the number of the anode (direction).

• energy_np (numpy.array of float with shape of (nE,)) – Energy step in eV. Shape should be (nE,)

• anode_np (numpy.array of int with shape of (nD,)) – Anode number. Shape should be (nD,).

Returns

The differential number flux in the unit of s3/cm6.

Raises ValueError if the shapes are inconsistent.

>>> etbl = np.array([30., 300, 3000])   # As a sample, 3 energy steps assumed.
>>> anod = np.arange(8)   # As a sample, 8 anode steps assumed.
>>> cnts = np.ones([3, 8])   # Count data should have shape of (*nE*, *nD*).

>>> psd = raw2psd_np(cnts, etbl, anod)
>>> print(psd.shape)
(3, 8)
>>> print('%.3e' % psd[2, 5])   # One count level of 3000 eV Anode=5
9.917e-32
>>> print('%.3e' % raw2psd(1, 3000., 5))   # Scalar version for confirmation
9.917e-32


Todo

Too slow due to loops. Need implementation of vectorized version like raw2dnf.