'''fits outputs for SOEX
Created on 21 february 2019
@author: Catalano Camille, APC
'''
from astropy.io import fits
from ecpi.common.io import fits_tools
[docs]def save_spectrum(file_path, spectrum, tstart, tstop, attitude, creator='SOEX?', 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='SOEX?'
: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(file_path + '/ECL-SPS-S1-' + proc_id + '.fits', overwrite=True, checksum=True)
[docs]def save_lightcurve(file_path, light_curve_table, tstart, tstop,
attitude, creator='SOEX?', 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='SOEX?'
: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(file_path + '/ECL-LCS-S1-' + proc_id + '.fits', overwrite=True, checksum=True)