Source code for irfpy.jdc.flux0

''' A module to convert between the count rate and the flux for JDC.

A draft g-factor value is used, as in the proposal.
'''
import irfpy.jdc.energy0

[docs]class Flux2Count(): ''' Flux is converted to count rate. ''' def __init__(self): self.gfactor=5.6e-4 self.etbl = irfpy.jdc.energy0.getEnergy()
[docs] def getCounts(self, flux, energy_step): e_eV = self.etbl[energy_step] return self.getCounts_eV(flux, e_eV)
[docs] def getCounts_eV(self, flux, energy_eV): ''' :param flux: DIfferential flux in part. / cm2 sr eV s ''' cps = self.gfactor * flux * energy_eV return cps
[docs]class Count2Flux(): ''' Count rate is converted to flux. ''' def __init__(self): ''' G-factor is constant, independent of anything. 5.6x10^-4 cm2 sr eV/eV. ''' self.gfactor = 5.6e-4 self.etbl = irfpy.jdc.energy0.getEnergy()
[docs] def getFlux(self, cps, energy_step): ''' Depending on energy step, flux is calculated. Energy step is, as for the module consideration, obtained from :mod:`irfpy.jdc.energy0`. >>> c2f = Count2Flux() >>> print('%.3f' % c2f.getFlux(1, 96)) # 1 count level for energy step 96. 0.582 ''' e_eV = self.etbl[energy_step] return self.getFlux_eV(cps, e_eV)
[docs] def getFlux_eV(self, cps, energy_eV): r''' Return the expected flux based on the absolute energy value. Based on the definition of the G-factor, one can get the conversion as .. math:: J = \frac{C}{GE} where ``C`` is the countr ate in c/s, ``G`` is the g-factor in cm2 sr eV/eV, ``E`` is the energy in eV. The returned will be the differential flux in the unit of ``cnts / cm2 sr eV s``. >>> c2f = Count2Flux() >>> print('%.2f' % c2f.getFlux_eV(1, 1000)) # 1 count level for 1000eV channel. 1.79 ''' return cps / self.gfactor / energy_eV
import unittest import doctest
[docs]def doctests(): return unittest.TestSuite(( doctest.DocTestSuite(), ))
if __name__ == '__main__': unittest.main(defaultTest='doctests')