irfpy.cena.cena_mass2

Class handling CENA mass mode data.

CENA mass mode module. Better implementation than cena_mass from the memory leak point of view as mass2 module uses ring-cache.

The memory cache is only valid for reading a CENA data file, which is an orbit base. Packet based cache is not supported in module level. Thus, getter methods (getdataE16(), getdata() or whaterver) are rather time consuming if the request is repeated. In such a case, user may use cache by their own, or consider using cena_mass_time module.

irfpy.cena.cena_mass2.getobstime(timerange=None, orbit=None)[source]

Get the observation time of CENA as array of datetime instances.

Returned is an array of datetime instance.

irfpy.cena.cena_mass2.getdata(t, filter=None)[source]

Get CENA mass mode date for the specified time t.

Parameters
  • t (datetime.datetime) – Time

  • filter – Filter(s) to apply the data. Not supported.

Returns

JdObject that includes data of (8,7,128) shaped numpy.array

Return type

irfpy.util.julday.JdObject

>>> jddat = getdata(datetime.datetime(2009,4,18,1,30,0))
>>> dat = jddat.getData()    # jddat is an instance of JdObject
>>> print(jddat.getJd().juld())   
2454939.56251...
>>> print(dat.sum())
5.0
>>> print(dat.shape)
(8, 7, 128)
irfpy.cena.cena_mass2.getSvTable(t)[source]

Return the SV table.

>>> import dateutil.parser
>>> t0 = dateutil.parser.parse('2009-02-06 05:13:11.078000')
>>> print(numpy.array(getSvTable(t0).getData()))
[2 2 2 2]
>>> t0 = dateutil.parser.parse('2009-02-06 05:13:11.078000')
>>> print(numpy.array(getSvTable(t0).getData()))
[2 2 2 2]
>>> t0 = dateutil.parser.parse('2009-07-29 06:21:07.265000')
>>> print(numpy.array(getSvTable(t0).getData()))
[1 1 1 1]
>>> t0 = dateutil.parser.parse('2009-07-29 06:42:05.303000')
>>> print(numpy.array(getSvTable(t0).getData()))
[3 3 3 3]
>>> t0 = dateutil.parser.parse('2009-07-29 08:29:11.415000')
>>> print(numpy.array(getSvTable(t0).getData()))
[3 3 3 3]
>>> t0 = dateutil.parser.parse('2009-07-29 08:50:00.121000')
>>> print(numpy.array(getSvTable(t0).getData()))
[2 2 2 2]
irfpy.cena.cena_mass2.getHvMain(t)[source]

Return the high voltage.

>>> print(getHvMain(datetime.datetime(2009, 6, 13, 8, 0, 0)).getData())
0
>>> print(getHvMain(datetime.datetime(2009, 6, 13, 8, 2, 24)).getData())
807
>>> print(getHvMain(datetime.datetime(2009, 6, 13, 8, 4, 52)).getData())
2957
irfpy.cena.cena_mass2.getdataE16(t, filter=None, validation=None)[source]

Get CENA mass mode data in generic energy level (E16).

Parameters
  • t (datetime.datetime) – Time

  • filter – Filter to apply. Not supported.

  • validation – Validation to apply. See also invalid_mask class.

Returns

masked_array of the count rate data. Count rate data is an instance of numpy.np.MaskedArray with (16, 7, 128) shape.

Return type

irfpy.util.julday.JdObject

The method returns the masked ndarray that includes the energy and directional spectra in generic 16 energy step mode.

This is very frequently used function, but rather time consuming. Thus, it is recommended to use a cache by user, or use cena_mass_time module that returns the “list” of the data.

>>> jddat = getdataE16(datetime.datetime(2009, 4, 18, 1, 30, 0))
>>> dat = jddat.getData()
>>> print(jddat.getJd().juld())    
2454939.56251...
>>> print(dat.sum())
5.0
>>> print(dat.shape)
(16, 7, 128)
>>> print(dat[:,:,:64].sum(2).sum(1))
[-- -- -- -- 0.0 0.0 0.0 0.0 1.0 1.0 2.0 1.0 -- -- -- --]

Validation may exclude suspicious data by machine. An example is shown.

Try to examine the data near 2009-07-13T11:17:00.

>>> t0 = datetime.datetime(2009, 7, 13, 11, 17, 00)

Usual data can get via getdataE16 function. You can get masked array with a shape of 16 x 7 x 128.

>>> rawcount = getdataE16(t0).getData()  # getData() is for extracting JdObject
>>> rawcount.shape
(16, 7, 128)

Total count you can get, as this case, 140. (May be changeable for future database change)

>>> rawcount.sum()
140.0

Average counts with data which has not masked is ~0.0195

>>> print('%.4f' % rawcount.mean())
0.0195

Then, the number of ‘non-masked’ bin is 140.0 / 0.0195 = 7168.0

>>> rawcount.sum() / rawcount.mean()
7168.0

This is consistent with the number of the data 8x7x128 = 7168.

Ok. Now we try a suspicious data. You can get less suspicious data with validation keyword. Simplest example (and most robust now) is to exclude >100 cnts hydrogen count or 10 times more oxygen count. This is too much strong criteria, probably, but well, we go with it.

>>> proccount = getdataE16(t0, validation=[invalid_mask.high_heavy_mask, invalid_mask.high_count_mask]).getData()

Shape does not change.

>>> proccount.shape
(16, 7, 128)

However, the total count should change.

>>> proccount.sum()
79.0

This probably means most of the data is rejected. Let’s check it. Ok, now the average count rate can be calculated as

>>> print('%.6f' % proccount.mean())
0.015430

and thus, the number of valid bins are 79.0 / 0.015430 = 5120.

>>> proccount.sum() / proccount.mean()
5120.0

This means that 2048 data is rejected in this case.

Ok, let’s check also directly. You can use compressed() function.

>>> print(len(proccount.compressed()))
5120
irfpy.cena.cena_mass2.getHdefluxE16(t, filter=None, validation=None)[source]

Calculate the differential flux (#/eV sr cm2 s) of H-ENA from CENA data.

Calculate the differential flux of the H-ENA. The flux is calucalted by the help of cena_flux module.

Simple to call this function. Returned is the masked array-data JdObject.

>>> f = getHdefluxE16(datetime.datetime(2009, 7, 13, 11, 17))
>>> f = f.getData()   # To extract JdObject.
>>> f.shape
(16, 7)

The valid data is only 8x7 due to the energy table. >>> len(f.compressed()) # Number of valid data 56

What is validation? Validation is to exclude the suspective data set. See also invalid_mask class.

>>> f = getHdefluxE16(datetime.datetime(2009, 7, 13, 11, 17),
...      validation=[invalid_mask.high_heavy_mask, invalid_mask.high_count_mask])

This returns the masked dataset in which the low mass channel data with >100 cnts or counts in high mass channel has >10% of the low mass channel is masked.

>>> f = f.getData()   # Just to extract JdObject
>>> f.shape
(16, 7)
>>> len(f.compressed())   # Number of valid data
40

You can change the threshold, if you want.

>>> mask1 = invalid_mask.make_high_heavy_mask(0.05)   # Remove data if O counts has >5% of H.
>>> mask2 = invalid_mask.make_high_count_mask(10)     # Remove data if H counts has >10 cnts.
>>> f = getHdefluxE16(datetime.datetime(2009, 7, 13, 11, 17), validation=[mask1, mask2])
>>> len(f.getData().compressed())
24
class irfpy.cena.cena_mass2.invalid_mask[source]

Bases: object

A collection of validation routines.

Validation routine should get a count rate data with a shape of (16, 7, 128), and returns a boolean array with a shape of (16, 7, 128). If the data is invalid, True is set. (Thus it is used for masked_array.mask.)

It is recommended to use the following set: [high_heavy_mask, high_count_mask]

classmethod allok(data)[source]

All the data is validated.

All the data is validated, thus 16x7x128 False array is returned. This does not change the data. For debug purpose, mainly.

>>> import random
>>> dat = numpy.array([random.randint(0, 100) for i in range(16*7*128)])
>>> dat = dat.reshape((16, 7, 128))
>>> inval = invalid_mask.allok(dat)
>>> print(inval.shape)
(16, 7, 128)
>>> print(inval.any())   # All the inval is False.  (=No any inval is True.)
False
classmethod allng(data)[source]

All the data is invalid.

By some reason, all the data obtained in the moment is set to invalid. All the elements is set to True, i.e. invalid. Mainly for debugging purpose.

classmethod high_heavy_mask(data)[source]

Mask the data with count rate (O/H) is >10%.

In case heavy channel has more than 10% of the counts, the channel is rejected.

classmethod make_high_heavy_mask(threshold)[source]

Return the similar mask filter of high_heavy_mask with specific threshold.

classmethod high_count_mask(data)[source]

Mask the data with count rate of H is >100 cnts. `

classmethod make_high_count_mask(threshold)[source]

Return the mask filder to maks the channel with very high count rate.