Source code for irfpy.vima.energy

"""Energy table for VEX/IMA.

Energy table for VEX/IMA can be obtained by a function
:func:`get_default_table_for`.
See the description in :func:`get_default_table_for` to read the data and the energy table.

If you know PROM/EEPROM index, you can refer to :func:`get_default_table` function.

.. warning::

    It is known that the energy table has been swapped for the version before 4.1.1a3.
    At the release of v4.2.0, the energy table has been fixed.
"""
import numpy as np


[docs]def get_default_table_for(imadata, keep_negative=True): """ Get the energy table for VEX/IMA :param imadata: Data of VEX/IMA. :class:`irfpy.imacommon.imascipac.CntMatrix` object is expected. :param keep_negative: If *True* (default), negative energy is kept as is. Thus, the returned table will contain negative energy. If *False*, the negative values are proxied by a very small positive energy, in order to confirm the returned array always positive. :return: The energy table in eV/q. (96) shape. Example of getting the energy table: First, to get the IMA data, a preparation is needed. >>> import datetime >>> from irfpy.vima.rawdata import DataCenterCount3d >>> dc = DataCenterCount3d() Then, we get the data. >>> t0 = datetime.datetime(2008, 10, 5, 7, 30) >>> t, ima3d = dc.nextof(t0) # ima3d is an object of irfpy.imacommon.imascipac.CntMatrix >>> print(t) 2008-10-05 07:30:11.709940 >>> print(ima3d) <<class 'irfpy.imacommon.imascipac.CntMatrix'>(VEX/IMA)@2008-10-05T07:30:11.709940:MOD=24 >>25<<:CNTmax=368> Now, you can get the IMA energy table. >>> etbl = get_default_table_for(ima3d) # Getting the energy table >>> print(etbl[0]) # Highest energy 29999.9 For the later part of the mission, another energy table was used. >>> t0 = datetime.datetime(2012, 10, 5, 4, 0, 0) >>> t, ima3d = dc.nextof(t0) >>> etbl = get_default_table_for(ima3d) # Getting the energy table >>> print(etbl[0]) # Highest energy 20003.6 """ promsection = imadata.hk.promsection return get_default_table(promsection, keep_negative=keep_negative)
[docs]def get_default_table(promsection, keep_negative=True): """ Get the default energy table for VEX/IMA. Since the energy table is defined by PROM/EEPROM index, this function requires that index as argument. :param promsection: PROM/EEPROM section. This defines the energy / elevation table. :param keep_negative: If *True* (default), negative energy is kept as is. Thus, the returned table will contain negative energy. If *False*, the negative values are proxied by a very small positive energy, in order to confirm the returned array always positive. :return: The energy table in eV/q. (96) shape. The PROM/EEPROM index can be obtained from the HK in the IMA dataset. If you have an object of :class:`irfpy.imacommon.imascipac.CntMatrix`, the index is accessible via .. code-block:: python print(ima3d.hk.promsection) # ima3d is an object of ``CntMatrix``. """ if promsection == 0: # In practice, 0 (EEPROM) was used for the initial phase, etable = get_default_table_v1(negative=keep_negative) elif promsection in (15, 16): # and 15(RAW) and 16(RAW) was used for the later phase. etable = get_default_table_v3(negative=keep_negative) else: raise ValueError('No EEPROM {} used. It must be either of (0, 15, 16)'.format(promsection)) return etable
[docs]def get_default_table_v1(negative=True): """ Return the default energy table (V1) :keyword negative: If *True*, negative energy is considered as valid (default). If *False*, negative energy is proxied by a very small positive energy, in order to confirm the returned array always positive. NB: The v1 default table does not include negative energy so that this switch does not influence the returned array. :return: Energy table in eV/q. 96 elements. >>> etbl = get_default_table_v1() >>> print(etbl.shape) (96,) """ return np.array([12.0, 13.0, 14.1, 15.4, 16.7, 18.1, 19.7, 21.4, 23.2, 25.2, 27.4, 29.7, 32.2, 35.0, 38.0, 41.3, 44.8, 48.7, 52.8, 57.4, 62.3, 67.6, 73.5, 79.8, 86.6, 93.6, 101.6, 111.0, 120.3, 131.0, 141.7, 153.8, 167.1, 181.9, 197.9, 213.9, 232.7, 252.7, 274.1, 298.2, 323.6, 351.7, 381.1, 414.5, 449.3, 488.0, 530.8, 576.3, 625.8, 679.2, 736.7, 800.9, 869.1, 944.0, 1024.2, 1112.5, 1208.7, 1311.7, 1424.0, 1547.0, 1679.4, 1823.8, 1980.2, 2150.0, 2334.6, 2535.1, 2753.1, 2989.7, 3246.5, 3524.6, 3828.1, 4155.7, 4511.6, 4900.3, 5320.0, 5778.7, 6276.1, 6812.5, 7395.5, 8032.9, 8724.7, 9470.9, 10287.1, 11165.5, 12121.6, 13163.2, 14298.1, 15526.2, 16855.5, 18301.3, 19871.5, 21581.6, 23431.6, 25444.8, 27629.1, 29999.9, ])[::-1]
[docs]def get_default_table_v3(negative=True): """ Return the default energy table (V3) :keyword negative: If *True*, negative energy is considered as valid (default). If *False*, negative energy is proxied by a very small positive energy, in order to confirm the returned array always positive. :return: Energy table in eV/q. 96 elements. >>> etbl = get_default_table_v3() >>> print(etbl.shape) (96,) >>> print(etbl[-4]) # Last 6 energies are indeed negative or zero. -4.0 >>> etbl2 = get_default_table_v3(negative=False) >>> print(etbl2.shape) (96,) >>> print('{:.3e}'.format(etbl2[-4])) # Being negative=False given, the first 6 steps also gives positive value. 9.687e-09 """ etbl = np.array([-10.0, -8.0, -6.0, -4.0, -2.0, 0.0, 2.0, 4.0, 6.0, 8.0, 10.0, 12.0, 13.1, 14.3, 15.6, 17.1, 18.7, 20.4, 22.3, 24.3, 26.6, 29.0, 31.7, 34.6, 37.8, 41.3, 45.1, 49.3, 53.8, 58.8, 64.3, 70.2, 76.7, 84.2, 90.9, 100.3, 109.6, 119.0, 129.7, 141.7, 155.1, 169.8, 185.9, 201.9, 220.6, 242.0, 263.4, 288.8, 315.6, 343.6, 375.7, 410.5, 447.9, 489.4, 534.8, 584.3, 639.1, 698.0, 762.1, 831.7, 909.2, 993.5, 1084.4, 1184.7, 1294.3, 1413.3, 1544.3, 1687.4, 1842.5, 2012.3, 2198.2, 2401.4, 2623.4, 2865.4, 3130.1, 3418.9, 3734.5, 4079.5, 4457.2, 4869.2, 5320.0, 5809.8, 6346.1, 6929.1, 7566.5, 8266.1, 9035.6, 9867.4, 10776.8, 11771.8, 12860.0, 14049.3, 15347.5, 16762.2, 18309.0, 20003.6, ])[::-1] if not negative: etbl_negativeproxy = np.linspace(1e-10, 100e-10, 96) etbl = np.where(etbl > 0, etbl, etbl_negativeproxy) return etbl