irfpy.cena.empirical

Empirical energy and angular spectra

The empirical energy and angular spectra module.

  • Energy spectrum: j() (with unit support) and j2() (no unit support)

  • Angular response: AngularAV13

To avoid the uncertainty of the unit conversion, the irfpy.util.unitq module is used. (https://irfpy.irf.se/projects/util/api/api_irfpy.util.unitq.html)

irfpy.cena.empirical.temperature_ena(velocity)[source]

Calculate the ENA temperature.

Parameters

velocity – Velocity of the solar wind (unitful by irfpy.util.unitq)

Returns

Temperature of the reflected ENAs.

Return type

float with unit of the order of u.K

The ENA temperature model is based on Futaana et al., 2012; 2013.

>>> kT_ena = temperature_ena(300 * u.km / u.s)
>>> print(kT_ena.nr(u.K))    # in Kelvin
912900.0

The result is converted to eV (temperature)

>>> print('{:.2f}'.format(kT_ena.nr(u.eV_asT)))   # in eV (temperature)
78.67
irfpy.cena.empirical.guess_vsw(t_ena)[source]

Calculate the solar wind velocity from the obtained temperatuer.

Inverse function of temperature_ena(). See Futaana et al., 2013 for application.

Parameters

t_ena – ENA temperature. Should have the unit of temperature.

Returns

The guessed velocity of the solar wind.

Return type

float with unit equivalent to speed u.m / u.s.

>>> print(guess_vsw(912900.0 * u.K).nr(u.km / u.s))
300.0
irfpy.cena.empirical.flux_half_maxwell(nena, Tena, E0=array(0.) * J, angular_coefficient=6.283185307179586)[source]

Calculate the flux of half-maxwell distribution function

Parameters
  • nena – ENA full density with unit of the order of /u.cm ** 3

  • Tena – ENA temperature with unit of the order of u.K

  • E0 – Limit in the lower bound of the energy with unit.

  • angular_coefficient – Coefficient of the part of \(\int\int f_ad^2\Omega\) In case of the isotropic distribution, it will be \(2\pi\) which is a default.

>>> n = 1 / u.cm**3
>>> T = 100 * u.eVT
>>> print('%.2e' % flux_half_maxwell(n, T).nr(1/u.cm**2/u.s))
7.81e+06
>>> n = 4.28 / u.cm**3
>>> T = 135.7 * u.eVT
>>> print('%.2e' % flux_half_maxwell(n, T).nr(1/u.cm**2/u.s))
3.89e+07
irfpy.cena.empirical.refrate()[source]

Return the average reflection rate (Futaana et al., 2012).

irfpy.cena.empirical.j(Fsw, vel, ref=None)[source]

Get the empirical function of the differential flux.

See Futaana et al., 2012.

Parameters
  • Fsw – Solar wind flux with unit equivalent to u.cm ** -2 * u.s ** -1. If \(SZA\) (solar zenith angle) plays into the game, the geometric reduction should be compensated prior by multiplying the \(\cos SZA\).

  • vel – Solar wind velocity with unit of speed (e.g, u.m / u.s).

  • ref – Reflection rate. Default is taken from refrate().

Returns

An empirical function is returned. The returned function has the following signature:

  • Input: Energy with unit of energy (e.g., eV)

  • Ouptput: Full-differential flux (i.e., the unit of 1 / u.cm ** 2 / u.s / u.ster / u.eV).

The isotropic distrubition is assumed.

>>> Fsw = 3e8 / u.cm ** 2 / u.s     # The solar wind flux
>>> Vsw = 400 * u.km / u.s          # The solar wind speed
>>> j_empir = j(Fsw, Vsw)           # The empirical function
>>> E = 30 * u.eV_asE               # 30 eV of energy as input
>>> j30 = j_empir(E)                # Differential flux at 30 eV
>>> print('%.1f' % j30.nr(1 / u.eV_asE / u.cm ** 2 / u.s / u.ster))
18383.8
irfpy.cena.empirical.j2(Fsw__cm2s, Vsw_km_s, ref=None)[source]

Equivalent to j() but with float version.

Parameters
  • Fsw__cm2s – The flux of the solar wind in the unit of /cm2 /s

  • Vsw_km_s – The speed of the solar wind in the unit of km/s

>>> Fsw = 3e8
>>> Vsw = 400.
>>> espec = j2(Fsw, Vsw)
>>> j30 = espec(30)  # 30 eV
>>> print('%.1f' % j30)
18383.8
irfpy.cena.empirical.data_maxwellfit(counts, ch, initprm=None)[source]

This is to calculate the best parameters for the obtained data.

Parameters
  • counts (np.ma.masked_array) – Count array with shape of (16,)

  • ch (int) – Channel of CENA

  • initprm – Initial parameter. Tuple of three float.

Returns

Tuple of the fitted results. First element is a tuple of the density and temperature. They are unitfull with irfpy.util.units. The second element is a background. The third element is the log-likeliness calculated during fitting. This can be used for calculating AIC. The foruth element is the fitted function. The function will take float energies (np.array) in eV to return the differential flux in /cm2 sr s eV.

The Maxwell + BG fitting from the given count rate data.

>>> cnts = [float(v) for v in 'nan nan nan nan 0.041152 0.078189 0.164609 0.378601 0.460905 0.547325 0.242798 0.057613 nan nan nan nan'.split()]
>>> fit = data_maxwellfit(cnts, 3)
>>> n = fit[0][0]
>>> print('%.2f' % n.nr(u.cm**-3))
2.44
>>> T = fit[0][1]
>>> print('%.2f' % T.nr(u.eVT))
87.87
irfpy.cena.empirical.maxwell_func(n, T)[source]

Return unitful Maxwell function of differential flux from the given n and T.

>>> n = 2.2 * (u.cm ** -3)
>>> T = 85.3 * (u.eVT)
>>> j_mx = maxwell_func(n, T)   # Return a function.
>>> j100 = j_mx(100 * u.eV_asE)   # Differential flux of 100 eV
>>> print('%.1f' % j100.nr(1 / u.cm ** 2 / u.ster / u.eV_asE / u.s))
10743.2

The maxwell_func() can be used, instead of the function returned by data_maxwellfit(), to plot the fitted differential flux.

class irfpy.cena.empirical.AngularAS11[source]

Bases: object

Implementation of angular response, f_s, in Schaufelberger 2011.

Note

It is better using AngularAV13() as it is more understandable definition

\[J_{ENA}(SZA, \phi, \theta) = J_{SW}\cdot R_{SS} \cdot f_S(SZA, \phi, \theta)\]

This class is for f_S. Note that J_ENA is in the unit of [#/cm2 sr s] and J_SW is [#/cm2 s]

fs(sza_deg, phi_deg, theta_deg)[source]

Return the angular response, fs. The unit is [1/sr].

Parameters
  • sza_deg – Solar zenith angle, in degrees

  • phi_deg – Scattering azimuth angle, in degrees. 0 is for the sun direction

  • theta_deg – Scattering polar angle, in degrees. 0 is for the zenith dirction

Returns

Sattering function fs in 1/steradian

\[f_S(SZA, \phi, \theta) = f_0(SZA) \cdot f_1(SZA, \phi) \cdot f_2(SZA, \phi) \cdot f_3(SZA, \theta)\]

The form is in Schaufelberger et al (2011).

class irfpy.cena.empirical.AngularAV13[source]

Bases: irfpy.cena.empirical.AngularAS11

Implementation of angular response, f_s, in Vorburger 2013.

Note

As of my understanding, the AS11 model and AV13 model definitions are different.

One recommended way to use is to normalize the angular response to re-distribute to the integrated (energy-)differential flux.