'''
Created on 1 déc. 2020
@author: Colley JM
'''
import logging
import time
import random
import numpy as np
from ecpi.common.instru.model_effect import ECLAIRsDetectorEffectDefault
from ecpi.process.imag.io.outputs import save_sky_images
from ecpi.process.imag.core.mini_pipeline import SkyImages
from ecpi.process.pipeline.lib_ecpi_pipeline import EclairsPipelineForHttpServer
from ecpi.common import add_path_data_ref_eclairs
import ecpi.database.interact_sdb as sdb
logger = logging.getLogger(__name__)
[docs]class EclairsQlaLevel1(EclairsPipelineForHttpServer):
'''QLA level 1 ECPI
'''
def __init__(self, target, id_proc=None):
"""Define file parameters for QLA Level 1
"""
logger.info(f'')
logger.info(f'============ QLA ECLAIRs Level 1 ===========')
logger.info(f'')
logger.info(target)
obs_id = target["orbit"]
logger.info(f'Search last download with OBS_ID={obs_id} in SDB')
f_att = sdb.find_name_last_download(obs_id, "SVO-ATT-CNV")
f_orb = sdb.find_name_last_download(obs_id, "SVO-ORB-CNV")
f_evt = sdb.find_name_last_download(obs_id, "ECL-EVT-SEC")
# define parameters
d_pars = {"general":{}, "sdb": {}, "caldb":{}, "dpco": {}, "bube":{}, "imag":{}}
d_pars["sdb"]["event_files"] = f'["{f_evt}"]'
d_pars["sdb"]["attitude_files"] = f'["{f_att}"]'
d_pars["sdb"]["l1_files"] = f'["{f_orb}"]'
d_pars["caldb"]["arf_file"] = "arf_effarea_2021-01-30_09:06:00.fits"
d_pars["dpco"]["out_files"] = '[]'
d_pars["bube"]["out_files"] = '["ECL-DET-UBC"]'
d_pars["bube"]["bkg_correction_mode"] = 'shape_moretti_earth'
d_pars["bube"]["energy_channels"] = '[[0,39], [40,63],[64,103],[104,223],[224,583]]'
d_pars["imag"]["out_files"] = '["ECL-SKY-IMA","ECL-SOP-IMA"]'
super().__init__(d_pars, id_proc)
#switch on defaulr caldb : self.caldb_dir = add_path_data_ref_eclairs("instru")
# def _get_files_from_sdb(self):
# logger.info("skip SDB downlad.")
# return True
# def _get_files_from_caldb(self):
# logger.info("skip CALDB downlad.")
# return True
#
# def _ecpi_processing_debug(self, only_check=False):
# if only_check:
# return super()._ecpi_processing(only_check)
# super()._ecpi_processing(only_check)
# self.status = 0
# return True
#
# def _after_processing_debug(self):
# logger.info("====create output data DC-2 for upload feature demonstration====")
# # only_check
# # time_dodo = random.randint(3, 20)
# # time.sleep(time_dodo)
# # print("SLEEP ", time_dodo)
# # logger.info(f"SLEEP {time_dodo}")
# ptgori = np.array([ 0., 0., 0.])
# # l'axe Z pointe vers le Nord et l'axe Y pointe vers l'Est
# # en vue au-dessus du détecteur le cadant couvrant le ciel
# # où l'ascension droite et la déclinaison est positive est en haut à droite
# # Dans le code les images ciel sont en convention ECPI, cela se traduit par
# # première composante (axe Y) > 100
# # deuxième composante (axe Z) > 100
# shape_ciel = (199, 199)
# # placons une pseudo source au bord en Y ~ 199
# # et à mi hauteur dans le cadrant Z ~ 150
# im_ref = np.zeros(shape_ciel, dtype=np.float32)
# im_ref[190:195, 140:145] = 100
# im_ref[192, 142] = 120
# var_ref = im_ref.copy()
# # ecrivons cette image avec la fonction utilisée par IMAG save_sky_images()
# exposure = np.ones(shape_ciel, dtype=np.float32)
# sky_image = SkyImages(im_ref, var_ref, 3 , exposure, 1000.0 / 60, ptgori)
# dest_dir = self.working_out
# eded = ECLAIRsDetectorEffectDefault()
# obs_info_dict = {'tstart': 0.0, 'tstop': 1000.0,
# 'energy_ranges': [[10, 10]],
# 'attitude': ptgori}
# creator = 'APC'
# name = save_sky_images([sky_image],
# dest_dir,
# eded,
# obs_info_dict,
# creator,
# self.id_proc)
# super()._after_processing()
# return True