"""MOSA products
"""
import logging
import os.path as osp
from inspect import currentframe as cf
from datetime import datetime as dt
import numpy as np
from astropy.time import Time
from json_product_generator.fits_product_builder import product_builder as fpb
logger = logging.getLogger(__name__)
# TODO: look for every instance of create_time_tag_from_t_start
# and place into a lib module
[docs]def create_time_tag_from_t_start(t_start):
"""Creates time tag of scientific products.
:param t_start: starting time of the observation
:type t_start: float
"""
time_isot_tag = Time(t_start / (24 * 3600), scale='tt', format='mjd').isot
time_isot_tag = time_isot_tag.replace("-", "")
time_isot_tag = time_isot_tag.replace(":", "")
return time_isot_tag.split(".")[0]
# TODO: witch the following dummy fonction
[docs]def genfits_ecl_sky_mos(mosa_info, dir_path, creator, proc_id="01"):
pass
# TODO: witch the following dummy fonction
[docs]def genfits_ecl_sop_mos(mosa_info, dir_path, creator, proc_id="01"):
pass
# def genfits_ecl_sky_mos(mosa_info, dir_path, creator, proc_id="01"):
# """save level 1 mosa in fits file ECL-SKY-MOS
# filename is 'ECL-SKY-MOS-' + proc_id + '.fits'
#
# :param mosa_info: list of sources catalogs
# :type mosa_info: dict
# :param dir_path: PATH to the directory where to write the file
# :type dir_path: string
# :param creator: program that has generated the file.
# :type creator: string
# :param proc_id: id of the process. Default="01".
# :type proc_id: string
# """
# for key in mosa_info.keys():
# print(f"Parsing key {key} in mosa_info with value {mosa_info[key]}.")
#
# # unpack observation related variables
# t_start = mosa_info['t_start']
# t_stop = mosa_info['t_stop']
# t_elapse = t_stop - t_start
# time_isot_tag = create_time_tag_from_t_start(t_start)
# creation_date = Time(dt.now(), precision=0).tt.isot
# model = 'ECL-SKY-MOS'
# filename = model + time_isot_tag + '_' + proc_id + '_test.fits'
# fpe = fpb.FitsProductEclairs(model, osp.join(dir_path, filename))
# print(f'######################FITS_output_file_path: {fpe.fits_output_file_path} ############')
# # TODO: Recover the following information :
# # OBS_ID, OBS_TYPE, COMMENT, HISTORY
# fpe.update_common_kw({'TSTART': t_start, 'TSTOP': t_stop, 'TELAPSE': t_elapse, 'CREATOR': cf().f_code.co_name,
# 'DATE': creation_date, 'FSCLEVEL': 'L1',
# 'OBS_ID': 1, 'OBS_TYPE': 1, 'RUN_TYPE': 'QLA',
# 'RA_PNT': mosa_info['radec'][0], 'DEC_PNT': mosa_info['radec'][-1],
# 'CARD': 'LISTS OF FIRST LEVEL GTIS', 'PIPLEVEL': 'MOSA})
# fpe.update_dict_data({'CARD': 'GROUP', 'EXTNAME': 'ECL-GTI-GROUP', 'FSCLEVEL': 'L1'
# }, 1)
# hdu_idx = 2
# first_ext = {}
# for evt, values in mosa_info['mosa'].items():
# if values == []:
# continue
# evt_fill = {}
# # TODO: Verify if it is necessary to have different names for GTI-NSA
# name = evt.upper().replace('_', '-')
# evt_name = 'GTI-' + name
# if 0 <= name.rfind('NSA'):
# evt_type = 'GTI-NSA'
# else:
# evt_type = evt_name
# a_values = np.array(values)
# logger.info(f"GTI [{evt}] found with content [{a_values}]")
# # TODO: convert in SJDTIME
# evt_fill['SJDSTART'] = a_values[:, 0] / (24 * 3600)
# evt_fill['SJDSTOP'] = a_values[:, 1] / (24 * 3600)
# evt_fill['START'] = a_values[:, 0]
# evt_fill['STOP'] = a_values[:, 1]
# # We write the extension Header and Data
# fpe.update_dict_data({'EXTNAME': evt_name}, hdu_idx)
# fpe.update_dict_data(evt_fill, hdu_idx, 'd')
# # We insert this information as a row in the first extension
# fpe.update_dict_data({'GTI_NAME': evt_type, 'MEMBER_XTENSION': 'BINTABLE',
# 'MEMBER_NAME': evt_name, 'MEMBER_VERSION': 1, 'MEMBER_POSITION': hdu_idx}, 1, 'd')
# hdu_idx += 1
#
# fpe.print_dict()
# fpe.fill_fits_product(False, False)
# return True
#
#