Source code for process.bube.io.outputs

'''fits outputs for bube

Created on 21 february 2019

@author: Catalano Camille, APC
'''


from astropy.io import fits
import astropy.table as astt

from common.io import fits_tools
from process.bube.core.BubeProcesses import DetectorImages
from common.mission.observation import EclairsObservation
from common.instru.array_convention import yzegp_to_ijdet_array


[docs]def save_detector_images(det_image : DetectorImages, tstart, tstop, file_path, creator='BUBE?', proc_id="01"): """save detector images in two fits files : ECL-DET-IMA and ECL-DET-UBC This function call save_detector_raw_image and save_detector_corrected_image common keywords are used filenames are ('ECL-DET-IMA-' + proc_id + '.fits') and ('ECL-DET-UBC-' + proc_id + '.fits') :param det_image: detector image to save :type det_image: DetectorImages :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 file_path: PATH to the directory where to write the file :type file_path: string :param creator: program that has generated the file. Default='BUBE?'. :type creator: string :param proc_id: id of the process. Default="01". :type proc_id: string """ save_detector_raw_image(det_image, tstart, tstop, file_path, creator, proc_id) save_detector_corrected_image(det_image, tstart, tstop, file_path, creator, proc_id)
[docs]def save_detector_raw_image(det_image : DetectorImages, tstart, tstop, file_path, creator='BUBE?', proc_id="01"): """save detector raw images in a fits file : ECL-DET-IMA common keywords are used filename is ('ECL-DET-IMA-' + proc_id + '.fits') :param det_image: detector image to save :type det_image: DetectorImages :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 file_path: PATH to the directory where to write the file :type file_path: string :param creator: program that has generated the file. Default='BUBE?'. :type creator: string :param proc_id: id of the process. Default="01". :type proc_id: string """ prihdr = fits.Header() prihdu = fits.PrimaryHDU(header=prihdr) hdu_list = [prihdu] hdu_images = [] grp_table = astt.Table([[],[],[],[],[],[],[],[],[],[],[]],names=('member_xtension', 'member_name', 'member_version', 'member_position', 'member_location', 'member_uri_type', 'imatype', 'chanmin', 'chanmax', 'e_min', 'e_max'), dtype=('S20', 'S20', 'u1', 'u1', 'S20', 'S20', 'S20', 'f4', 'f4', 'f4', 'f4')) for shadow_idx in range(len(det_image.shadowgrams)): chanmin = det_image.energy_ranges[shadow_idx][0] chanmax = det_image.energy_ranges[shadow_idx][1] e_min = chanmin e_max = chanmax grp_table.add_row(['IMAGE ', 'Shadowgram', '1', shadow_idx*2+2, '', '', 'intensity', chanmin, chanmax, e_min, e_max]) grp_table.add_row(['IMAGE ', 'Variance', '1', shadow_idx*2+3, '', '', 'variance', chanmin, chanmax, e_min, e_max]) hdu_shadowgram = fits.ImageHDU(yzegp_to_ijdet_array(det_image.shadowgrams[shadow_idx])) hdu_var = fits.ImageHDU(yzegp_to_ijdet_array(det_image.shadowgrams_var[shadow_idx])) fits_tools.common_keyword(hdu_shadowgram, tstart, tstop, creator, 1.0, proc_id) fits_tools.common_keyword(hdu_var, tstart, tstop, creator, 1.0, proc_id) fits_tools.energy_keywords(hdu_shadowgram, chanmin, chanmax, e_min, e_max) fits_tools.energy_keywords(hdu_var, chanmin, chanmax, e_min, e_max) hdu_shadowgram.name = 'Shadowgram' hdu_shadowgram.header['comment'] = "Shadowgram Image" hdu_shadowgram.header['BUNIT'] = 'cts.s^-1.cm^-2' hdu_shadowgram.header['IMATYPE'] = ("Intensity", "Type of image") hdu_var.name = 'Variance' hdu_var.header['comment'] = "Shadowgram Variance Image" hdu_var.header['BUNIT'] = 'cts^2.s^-2.cm^-4' hdu_var.header['IMATYPE'] = ("Variance", "Type of image") hdu_images.extend([hdu_shadowgram, hdu_var]) hdu_grp = fits.table_to_hdu(grp_table) hdu_grp.header['comment'] = 'ECLAIRs detector images' fits_tools.grouphdu_keyword(hdu_grp, 'ECL-DET-IMA-IDX') hdu_list.append(hdu_grp) hdu_list.extend(hdu_images) thdulist = fits.HDUList(hdu_list) thdulist.writeto(file_path + '/ECL-DET-IMA-' + proc_id + '.fits', overwrite=True, checksum=True)
[docs]def save_detector_corrected_image(det_image : DetectorImages, tstart, tstop, file_path, creator='BUBE?', proc_id="01"): """save detector corrected images in a fits file : ECL-DET-UBC common keywords are used filename is ('ECL-DET-UBC-' + proc_id + '.fits') :param det_image: detector image to save :type det_image: DetectorImages :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 file_path: PATH to the directory where to write the file :type file_path: string :param creator: program that has generated the file. Default='BUBE?'. :type creator: string :param proc_id: id of the process. Default="01". :type proc_id: string """ prihdr = fits.Header() prihdu = fits.PrimaryHDU(header=prihdr) hdu_list = [prihdu] hdu_images = [] grp_table = astt.Table([[],[],[],[],[],[],[],[],[],[],[]],names=('member_xtension', 'member_name', 'member_version', 'member_position', 'member_location', 'member_uri_type', 'imatype', 'chanmin', 'chanmax', 'e_min', 'e_max'), dtype=('S20', 'S20', 'u1', 'u1', 'S20', 'S20', 'S20', 'f4', 'f4', 'f4', 'f4')) for shadow_idx in range(len(det_image.shadowgrams)): chanmin = det_image.energy_ranges[shadow_idx][0] chanmax = det_image.energy_ranges[shadow_idx][1] e_min = chanmin e_max = chanmax grp_table.add_row(['IMAGE ', 'ShadowgramCorr', '1', shadow_idx+2, '', '', 'intensity', chanmin, chanmax, e_min, e_max]) hdu_shadowgram_corrected = fits.ImageHDU(yzegp_to_ijdet_array(det_image.shadowgrams_bgcorrected[shadow_idx])) fits_tools.common_keyword(hdu_shadowgram_corrected, tstart, tstop, creator, 1.0, proc_id) fits_tools.energy_keywords(hdu_shadowgram_corrected, chanmin, chanmax, e_min, e_max) hdu_shadowgram_corrected.name = 'ShadowgramCorr' hdu_shadowgram_corrected.header['comment'] = "Shadowgram Corrected Image" hdu_shadowgram_corrected.header['BUNIT'] = 'cts.s^-1.cm^-2' hdu_shadowgram_corrected.header['IMATYPE'] = ("Intensity", "Type of image") hdu_images.append(hdu_shadowgram_corrected) hdu_grp = fits.table_to_hdu(grp_table) hdu_grp.header['comment'] = 'ECLAIRs detector images corrected from uniformity, background and earth occultation/albedo' fits_tools.grouphdu_keyword(hdu_grp, 'ECL-DET-UBC-IDX') fits_tools.common_keyword(hdu_grp, tstart, tstop, creator, 1.0, proc_id) hdu_list.append(hdu_grp) hdu_list.extend(hdu_images) thdulist = fits.HDUList(hdu_list) thdulist.writeto(file_path + '/ECL-DET-UBC-' + proc_id + '.fits', overwrite=True, checksum=True)
[docs]def save_gti(obs : EclairsObservation, file_path, creator='BUBE?', proc_id="01"): """save GTI table into a fits file common keywords are used filename is 'ECL-GTI-3-' + proc_id + '.fits' :param obs: observation parameters :type obs: EclairsObservation :param file_path: PATH to the directory where to write the file :type file_path: string :param creator: program that has generated the file. Default='BUBE?'. :type creator: string :param proc_id: id of the process. Default="01". :type proc_id: string """ if isinstance(obs.gti_table, int): obs.gti_compute() tbhdu = fits.table_to_hdu(obs.gti_table) prihdr = fits.Header() prihdu = fits.PrimaryHDU(header=prihdr) fits_tools.common_keyword(tbhdu, obs.start_time, obs.end_time, creator, 1.0, proc_id) thdulist = fits.HDUList([prihdu, tbhdu]) thdulist[1].header['comment'] = "Good Time Intervals for ECLAIRs data analysis" thdulist[1].name = 'Eclairs Good Time Intervals' thdulist.writeto(file_path + '/ECL-GTI-3-' + proc_id + '.fits', overwrite=True, checksum=True)