irfpy.mima.scidata

MEX/IMA science data, providing the count rate data access

Note

This is quick and dirty implementation; It was copied from irfpy.vima.scidata.

Note

The latest appraoch of implementing scidata accessor is in scidata_util. Consider using that module.

ImaCountFile is the main class. This corresponds to a IMA matlab formatted data file.

get_ima_count_file() will return the data file contents corresponding to the time specified.

A simple way of getting data is as follows. You may use the get_ima_count_file() function.

>>> t = datetime.datetime(2006, 12, 5, 7, 50)
>>> imafile = get_ima_count_file(t)
>>> if imafile is not None:
...     mat = imafile.mat   # Matlab data dictionary.
...     print(os.path.basename(imafile.file))     
20061205070000.mat

If no data is found, you will get None as returned.

>>> t = datetime.datetime(2006, 12, 5, 7)
>>> imafile = get_ima_count_file(t)
>>> print(imafile)
None

How to handle the instance mat? See an independent document (prepared for VEX but can be applied to MEX) How to handle IMA science data?.

The data path should be specified by [mima] imamatbase in .irfpyrc.

class irfpy.mima.scidata.ImaCountFile(filename)[source]

Bases: object

MEX/IMA data file.

>>> imacnt = ImaCountFile(ImaCountFile.get_sample_filename())

Load the matlab count rate file

Parameters

filename – The filename of the file. URI is no more supported (no more maintained.)

rc = <irfpy.util.irfpyrc.Rc object>
classmethod get_sample_filename()[source]
classmethod get_uribase_path()[source]
classmethod get_uri(yr, mo, dy, hr)[source]
classmethod get_base_path()[source]
classmethod get_filename(yr, mo, dy, hr)[source]
logger = <Logger ImaCountFile (DEBUG)>
mat

Matlab formatte data

getobstime()[source]

Return the observation time list.

Returns

Observation time list (component is in datetime.datetime instance) is returned.

>>> imacnt = ImaCountFile(ImaCountFile.get_sample_filename())
>>> print(len(imacnt.getobstime()))
304
gettimerange(start_offset=0, stop_offset=0)[source]

Return the time range of the observation.

Returns

Range of data file time as a list of datetime.datetime instances.

[t0 + start_offset, t1 + stop_offset] is returned, where t0 is the start time (the time of the first packet) and t1 is the end time (the time of the last packet). This means that the end time t1 does not agree with the end of the observation time. The end of the observation time is the end time plus data acquisition time (12 sec or 24 sec, typically). Specifying stop_offset will compensate this issue.

Parameters
  • start_offset – Offset in seconds to be added to the start time.

  • stop_offset – Offset in seconds to be added to the stop time.

>>> imacnt = ImaCountFile(ImaCountFile.get_sample_filename())
>>> print(imacnt.gettimerange())
[datetime.datetime(2010, 11, 9, 14, 0, 40, 323800), datetime.datetime(2010, 11, 9, 15, 1, 16, 823860)]
>>> print(imacnt.gettimerange(stop_offset=12))
[datetime.datetime(2010, 11, 9, 14, 0, 40, 323800), datetime.datetime(2010, 11, 9, 15, 1, 28, 823860)]
irfpy.mima.scidata.isdb()[source]
irfpy.mima.scidata.get_ima_count_file_reduced(time)[source]

Return the ImaCountFile instance covering the specified time, from reduced-HK embedded data.

Parameters

time (datetime.datetime instance.) – Time of the data

Note: This is not yet fully debugged.

irfpy.mima.scidata.get_ima_count_file_full(time)[source]

Return the ImaCountFile instance covering the specified time, from full-HK embedded data.

Parameters

time (datetime.datetime instance.) – Time of the data

Note: This is not yet fully debugged.

irfpy.mima.scidata.get_ima_count_file(time)[source]

Return the ImaCountFile instance covering the specified time.

The dataset is selected either from

Because of slightly different name convention, this function judges which dataset user is referring automatically. Full-HK is prioritized, and definitively recommended to be used.

Parameters

time (datetime.datetime instance.) – Time of the data

Returns

Ima count file.

Return type

ImaCountFile instance.

irfpy.mima.scidata.reshape_mat3d(mat, npol=16)[source]

Reshape the matlab contents into MAEPT order

See also irfpy.vima.scidata.reshape_mat3d().

irfpy.mima.scidata.reshape_mat(mat)[source]

Reshape the matlab contents into MAET order.

MEX has, in nominal, operatied with full mode (MODE24). It has (32, 16, 96, 16) array.

Parameters

mat – Matlab contents.

Returns

(spectra, masslist, azimlist, elevlist, timelist)

Each output has the shape of (32, 16, 96, T) for spectra; (32, 16, T) for timelist; and (2, 32, 16, T) for others. T is the number of time.

>>> f = get_ima_count_file(datetime.datetime(2006, 12, 5, 8, 15))
>>> if f is not None:
...     s, m, a, e, t = reshape_mat_24(f.mat)
... else:
...     s = m = a = e = t = None
>>> print(s.shape)    
(32, 16, 96, 288)
>>> print(m.shape)    
(2, 32, 16, 288)
>>> print(t.shape)    
(32, 16, 288)

## The above results are in 2012-10-11.

irfpy.mima.scidata.reshape_mat_fast24s(mat)[source]

A specific reshape tool for 24s mode. MAEPT order.

Parameters

mat – Input of the matlab formatted data

Returns

A tuple of (spectra, masslist, azimlist, elevlist, timelist). Here spectra is the observed counts with a shape of (M=32, A=16, E=32, P=6, T=<arb.>) masslist, azimlist, elevlist is not yet supported. timelist is the observation time list with a shape of (T=<arb.>).

>>> t0 = datetime.datetime(2013, 12, 29, 7, 50)
>>> f = get_ima_count_file(t0)
>>> s, m, a, e, t = reshape_mat_fast24s(f.mat)
>>> print(s.shape)
(32, 16, 32, 6, 144)

This is the MAEPT order (mass-azimth, energy, polar, time.

>>> print(t.shape)
(144,)
irfpy.mima.scidata.reshape_mat_24(mat)[source]

(Deprecated!) Reshape the matlab contents into MAET order.

Use reshape_mat().