# $Header: https://oberon.oapd.inaf.it/shins/trunk/shins/src/scripts/templates/tpl/SHARKNIR_gen_cal_StarCenter.py 3952 2022-05-19 08:30:53Z depa $

from shinsapp import SHINSApp
from util.shinsLogger import logger
from util import variables as uvars
from util import exception
from util import functions as ufun

from SHARKNIR_gen_base import SHARKNIR_gen_base

class SHARKNIR_gen_cal_StarCenter(SHINSApp):
    '''Template for star centering with waffle mode on M2 (SHARKNIR-SCI-008);
    template steps:
    . waffle activation
    . setup + exposure

    This calibration is performed to calibrate the target star center
    with respect to the detector in order to provide a reference input
    for frame derotation and quadrant combination.  ASM modes applied
    on target acquisition to produce waffle image. Find the center of
    the four first order diffraction peaks (cross geometry) to deduce
    the pixel corresponding to the center field.
    '''
    
    @exception.handler_for_run
    def run(self, ins_s=None, det_s=None, tel_s=None, rtc_s=None, **kwargs):

        logger.info(__name__)
        obsController = self.obsController
        self.status = uvars.EXIT_SUCCESS

        self.gen_base = SHARKNIR_gen_base();        gen_base = self.gen_base

        # #####################
        # # Waffle activation #
        # #####################
        
        # logger.info("Template: Activate waffle mode on LBT ASM")
        # obsController.ApplyWaffleAO(tel_s)

        #################
        # Setup + image #
        #################
        
        gen_base.main(ins_s=ins_s, det_s=det_s)
