irfpy.cena.cena_flux

A module to convert between the flux and count data.

Some classes supporting this algorithm.

Differential flux conversion to count rate

Count rate to differential flux.

class irfpy.cena.cena_flux.Count2Flux(g_factor=None)[source]

Bases: object

Implementation of count to flux conversion.

According to the cena_calibration_issue_1_revision_1.pdf, count to flux conversion is implemented.

It is essential to understand the g-factor (a sort of conversion factor). The g-factor, however, has not been solidly calculated. This means that the values of g-factor and its affecting factors my be changed in the near future.

The Count2Flux class implementation is based on the calibration issue 1 revision 1. In the near future, API would also be changed.

Usage

This class is a factory class. Seveal G-factor implementaions can be set through g-factor class. See irfpy.cena.gfactor for details.

To instance the conversion class, just call the constructor.

>>> c2f = Count2Flux()

The default is to use the g-factor class of irfpy.cena.gfactor.GFactorH_Component.

If one wants to change the gfactor class, for example to irfpy.cena.gfactor.GFactorH_Table, you can specify the instance in the constructor. The instance that has method geometricFactor() can be used.

>>> from irfpy.cena.gfactor import GFactorH_Table
>>> gf = GFactorH_Table()
>>> c2f_tbl = Count2Flux(g_factor=gf)

Todo

  • Support of sigma, the ambiguity.

Parameters

g_factor (None or np.masked_array with a shape of (16, 7).) – G factor matrix. By default (None), the g-factor is obtained from irfpy.cena.gfactor.GFactorH_Component(). If you want to specify the g-factor, it should be a class instance that have a method named geometricFactor that returns a np.masked_array with a shape of (16, 7). See irfpy.cena.gfactor module for details.

getFlux(raw_count_rate, energy_step, sector_nr)[source]

Return the flux from the count rate.

Return the flux.

Parameters
  • raw_count_rate (int) – Raw count rate.

  • sector_nr (int) – Sector number, ranges 0..6.

  • energy_step (int) – General energy step, i.e in terms of E16, ranges 0..15.

Returns

The particle flux, in the unit of #/cm2 sr eV s.

Return type

Float.

The particle flux is calculated as in (3.19):

\[J_{n, i, m} = \frac{C_{n, i, m}}{G_{n, i, m} {\cdot}E_i{\cdot}\Delta t}\]

where n, i and m is the sector number, energy step, and the mass index, respectively.

class irfpy.cena.cena_flux.Flux2Count_Simple(g_factor=None)[source]

Bases: object

Class converting flux to count. Simplest implementation.

This provides inverse functions of Count2Flux.

The flux to count conversion is not simple, because the flux is a 3-D continuous function. This class provides a simple conversion. It assumes 1-D energy spectra for the direction of your interest. The spectra should not be a continuous function, but the sampled value at the central energy of the CENA sensor.

The energy values are obtained from irfpy.cena.energy.getEnergyE16() method.

get_counts(flux_array, sector_nr)[source]

Obtain the expected counts corresponding to the given flux.

Parameters
  • flux_array (np.array) – Differential flux in the unit of [#/cm2 sr eV s]. This parameter should be the np.array with the shape of (16,)

  • sector_nr (int) – Sector number, 0 to 6.

This is a array version of getCount(). Internally just call getCount 16 times.

>>> j = np.ones(16) * 1e5   # A constant flux over energy
>>> f2c = Flux2Count_Simple()
>>> c = f2c.get_counts(j, 3)   # Get an array of counts
>>> c_8 = f2c.getCount(1e5, 8, 3)   # Obtain count rate by each energy
>>> c[8] == c_8
True
getCount(flux, energy_step, sector_nr)[source]

Return the expected count rate for the given flux and energy and sector.

Parameters
  • flux (float) – Flux in #/cm2 sr eV s.

  • energy_step (int) – The energy step, 0 to 15.

  • sector_nr (int) – The sector number, 0 to 6.

Returns

The expected count rate. #/sample.

Return type

float

The count rate will be estimated from (3.19):

\[C_{n, i, m} = J_{n, i, m} {\cdot} G_{n,i,m} {\cdot} E_i {\cdot} \Delta t\]

where n, i, m is the sector number, energy step, and the mass index, respectively.

A sample for understanding.

The energy step for CENA can be found by:

>>> etbl = energy.getEnergyE16()
>>> print('%.1f' % etbl[8])
193.0

We take the central channel (Ch=3).

Then, assuming the flux at the direction 3 at energy of 193 eV as 105 #/cm2 sr eV s, the expected count rate is calculated by the following.

>>> f2c = Flux2Count_Simple()
>>> f = 1e5
>>> c = f2c.getCount(f, 8, 3)
>>> print('%.3g' % c)
6.16

This class is the inversed function of the Count2Flux. Thus, the value can be reverted.

>>> c2f = Count2Flux()
>>> finv = c2f.getFlux(c, 8, 3)
>>> print('%.3e' % finv)
1.000e+05
class irfpy.cena.cena_flux.Flux2Count_Matrix(energy_response_type='simulated')[source]

Bases: object

Class converting flux to count. Matrix implementation.

See also G-factor and its matrix.

dgfactor_matrix

Differential g-factor matrix

static get_differential_gfactor_matrix(g_factor, energy_response_type='simulated')[source]

Return the differential gfactor matrix.

Parameters
Returns

Differential gfactor matrix in np.array with the shape of (ie=16, je=16, 7). Here je defines the beam (particle) energy and ie defines the sensor energy. The unit of the returned array is in cm:sup:^2 sr eV. \(\Delta E\) has already be multiplied.

get_counts(flux_array, sector_nr)[source]

Obtain the expected counts corresponding to the given flux.

Parameters
  • flux_array (np.array) – Differential flux in the unit of [#/cm2 sr eV s]. This parameter should be the np.array with the shape of (16,)

  • sector_nr (int) – Sector number, 0 to 6.

class irfpy.cena.cena_flux.Flux2Count_Integral(energy_response_type='simulated')[source]

Bases: object

Class converting flux to count. Integral implementation.

See also G-factor and its matrix.

Integration is depending on the quad in scipy.integrate, this class is heavy. For my iMac (2007 late), it takes about 1.5 minutes to instance.

calculate_diff_gf(ie, ic)[source]
getCount(flux_function, energy_step, channel_step)[source]

Return the count rate for the given function.

Parameters
  • flux_function (callable) – A function which the differential flux follows. It is a function with an argument of energy in eV returning the differential flux /cm2 sr eV s.

  • energy_step – Energy index

  • channel_step – Channel index.

getCount2(flux_function, energy_step, channel_step)[source]

Same as :meth:getCount:, but faster. Precision would be ok.

Note that all the function should take np.array.