# $Header: https://oberon.oapd.inaf.it/shins/trunk/shins/src/scripts/templates/tpl/SHARKNIR_ci_mon_DetectorPersistence.py 3828 2022-02-18 17:46:12Z depa $

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

from SHARKNIR_gen_base import SHARKNIR_gen_base

class SHARKNIR_ci_mon_DetectorPersistence(SHINSApp):
    """Expected Accuracy: Accuracy of photometry 10%

    Acquisition procedure: Record a background exposure, then one
    highly saturated exposure; then a long series of exposures with
    source off Set-up: CI B_H, point source

    User defined parameters: Readout modes Calibration Hardware
    Devices: none
    """

    @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

        readout = det_s["READOUT"]

        ######################################
        # Instrument background with DIT=10s #
        ######################################

        ins_s["CAL_FF_LAMP"] = "OFF"

        det_s_dark = {
            "NCOADDS": "1",
            "NDIT"   : "1",
            "DIT"    : "10"
            "READOUT": readout,
        }

        gen_base.main(ins_s=ins_s, det_s=det_s_dark)

        ###########################
        # Setup + saturated image #
        ###########################

        ins_s_fiber = {
            "CAL_FF_LAMP": "ON",
            "SCI_FILT_W1": "HOLE",
            "SCI_FILT_W2": "HOLE",
        }

        det_s_fiber = {
            "NCOADDS": "1",
            "NDIT"   : "1",
            "DIT"    : "30"
            "READOUT": readout,
        }

        gen_base.main(ins_s=ins_s_fiber, det_s=det_s_fiber)

        ##############################################
        # Switching off all lamps + DIT=custom image #
        ##############################################

        ins_s["CAL_FF_LAMP"] = "OFF"

        gen_base.main(ins_s=ins_s, det_s=det_s)
