'''SPEX products
'''
import os.path as osp
from astropy.io import fits
from astropy.time import Time
from ecpi.common.io import fits_tools
# TODO: witch the following dummy fonction
[docs]def genfits_ecl_evs_soe(mosa_info, dir_path, creator, proc_id="01"):
pass
# TODO: witch the following dummy fonction
[docs]def genfits_ecl_lcs_soe(mosa_info, dir_path, creator, proc_id="01"):
pass
# TODO: witch the following dummy fonction
[docs]def genfits_ecl_sps_soe(mosa_info, dir_path, creator, proc_id="01"):
pass
[docs]def save_spectrum(file_path, spectrum, tstart, tstop, attitude, creator='SPEX?', proc_id="01"):
"""write the spectrum into a fits file ECL-SPS-S1
common keywords are included
filename is 'ECL-SPS-S1-' + proc_id + '.fits'
:param file_path: PATH to the directory where to write the file
:type file_path: string
:param spectrum: spectrum of the source
:type spectrum: astropy.table.Table
:param tstart: start time of the observation in s from mjdref
:type tstart: float
:param tstop: end time of the observation in s from mjdref
:type tstop: float
:param attitude: [ra, dec, ori] in degrees
:type attitude: [float, float, float]
:param creator: program that has generated the file. Default='SPEX?'
:type creator: string
:param proc_id: id of the process. Default="01".
:type proc_id: string
"""
# construction of the fits file
tbhdu = fits.table_to_hdu(spectrum)
prihdr = fits.Header()
prihdu = fits.PrimaryHDU(header=prihdr)
obstime = tstop - tstart
fits_tools.pointing_keywords(prihdu, attitude, obstime)
fits_tools.common_keyword(prihdu, tstart, tstop, creator, 1.0, proc_id)
prihdu.header['CARD'] = ("ECL-SPS-S1", "Product type")
fits_tools.common_keyword(tbhdu, tstart, tstop, creator, 1.0, proc_id)
thdulist = fits.HDUList([prihdu, tbhdu])
thdulist[1].header['comment'] = "Count Spectrum"
thdulist[1].name = 'SPS'
thdulist.writeto(osp.join(file_path, f'ECL-SPS-S1-{proc_id}.fits'), overwrite=True, checksum=True)
[docs]def save_lightcurve(file_path, light_curve_table, tstart, tstop,
attitude, creator='SPEX?', proc_id="01"):
"""write the light curve into a fits file ECL-LCS-S1
common keywords are included
filename is 'ECL-LCS-S1-' + proc_id + '.fits'
:param file_path: PATH to the directory where to write the file
:type file_path: string
:param light_curve_table: light curve of the source
:type light_curve_table: astropy.table.Table
:param tstart: start time of the observation in s from mjdref
:type tstart: float
:param tstop: end time of the observation in s from mjdref
:type tstop: float
:param attitude: [ra, dec, ori] in degrees
:type attitude: [float, float, float]
:param creator: program that has generated the file. Default='SPEX?'
:type creator: string
:param proc_id: id of the process. Default="01".
:type proc_id: string
"""
# construction of the fits file
tbhdu = fits.table_to_hdu(light_curve_table)
prihdr = fits.Header()
prihdu = fits.PrimaryHDU(header=prihdr)
obstime = tstop - tstart
fits_tools.pointing_keywords(prihdu, attitude, obstime)
fits_tools.common_keyword(prihdu, tstart, tstop, creator, 1.0, proc_id)
prihdu.header['CARD'] = ("ECL-LCS-S1", "Product type")
fits_tools.common_keyword(tbhdu, tstart, tstop, creator, 1.0, proc_id)
thdulist = fits.HDUList([prihdu, tbhdu])
thdulist[1].header['comment'] = "Light curve"
thdulist[1].name = 'LCS'
thdulist.writeto(osp.join(file_path, f'ECL-LCS-S1-{proc_id}.fits'), overwrite=True, checksum=True)