ConfigureForCalibrations

Bases: KPFTranslatorFunction

Script which configures the instrument for Cal OBs.

This must have arguments as input, either from a file using the -f command line tool, or passed in from the execution engine.

Can be called by ddoi_script_functions.configure_for_science.

ARGS:

:OB: dict A fully specified calibration observing block (OB).

Source code in kpf/scripts/ConfigureForCalibrations.py
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
class ConfigureForCalibrations(KPFTranslatorFunction):
    '''Script which configures the instrument for Cal OBs.

    This must have arguments as input, either from a file using the `-f` command
    line tool, or passed in from the execution engine.

    Can be called by `ddoi_script_functions.configure_for_science`.

    ARGS:
    =====
    :OB: `dict` A fully specified calibration observing block (OB).
    '''
    @classmethod
    @obey_scriptrun
    def pre_condition(cls, OB, logger, cfg):
        check_input(OB, 'Template_Name', allowed_values=['kpf_cal'])
        check_input(OB, 'Template_Version', version_check=True, value_min='0.5')

    @classmethod
    def perform(cls, OB, logger, cfg):
        log.info('-------------------------')
        log.info(f"Running {cls.__name__}")
        for key in OB:
            if key not in ['SEQ_Darks', 'SEQ_Calibrations']:
                log.debug(f"  {key}: {OB[key]}")
            else:
                log.debug(f"  {key}:")
                for entry in OB[key]:
                    log.debug(f"    {entry}")
        log.info('-------------------------')

        check_scriptstop()

        # Power up needed lamps
        sequence = OB.get('SEQ_Calibrations', None)
        lamps = set([x['CalSource'] for x in sequence if x['CalSource'] != 'Home'])\
                if sequence is not None else []
        for lamp in lamps:
            if IsCalSourceEnabled.execute({'CalSource': lamp}) == True:
                if lamp in ['Th_daily', 'Th_gold', 'U_daily', 'U_gold',
                            'BrdbandFiber', 'WideFlat']:
                    CalLampPower.execute({'lamp': lamp, 'power': 'on'})

        log.debug(f"Ensuring back illumination LEDs are off")
        CalLampPower.execute({'lamp': 'ExpMeterLED', 'power': 'off'})
        CalLampPower.execute({'lamp': 'CaHKLED', 'power': 'off'})
        CalLampPower.execute({'lamp': 'SciLED', 'power': 'off'})
        CalLampPower.execute({'lamp': 'SkyLED', 'power': 'off'})

        log.info(f"Configuring FIU")
        ConfigureFIU.execute({'mode': 'Calibration'})
        log.info(f"Set Detector List")
        WaitForReady.execute({})
        SetTriggeredDetectors.execute(OB)

    @classmethod
    def post_condition(cls, OB, logger, cfg):
        pass