ConfigureForScience

Bases: KPFTranslatorFunction

Script which configures the instrument for Science observations.

  • Sets octagon / simulcal source
  • Sets source select shutters
  • Set triggered detectors

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

ARGS:

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

Source code in kpf/scripts/ConfigureForScience.py
 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
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
class ConfigureForScience(KPFTranslatorFunction):
    '''Script which configures the instrument for Science observations.

    - Sets octagon / simulcal source
    - Sets source select shutters
    - Set triggered detectors

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

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

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

        check_scriptstop()

        matched_PO = VerifyCurrentBase.execute({})
        if matched_PO == False:
            # Check with user
            log.debug('Asking for user input')
            print()
            print("#####################################################")
            print("The dcs.PONAME value is incosistent with CURRENT_BASE")
            print("Please double check that the target object is where you")
            print("want it to be before proceeding.")
            print()
            print("Do you wish to continue executing this OB?")
            print("(y/n) [y]:")
            print("#####################################################")
            print()
            user_input = input()
            log.debug(f'response: "{user_input}"')
            if user_input.lower().strip() in ['n', 'no', 'a', 'abort', 'q', 'quit']:
                raise KPFException("User chose to halt execution")

        check_scriptstop()

        # Set Octagon
        kpfconfig = ktl.cache('kpfconfig')
        calsource = kpfconfig['SIMULCALSOURCE'].read()
        octagon = ktl.cache('kpfcal', 'OCTAGON').read()
        log.debug(f"Current OCTAGON = {octagon}, desired = {calsource}")
        if octagon != calsource:
            log.info(f"Set CalSource/Octagon: {calsource}")
            SetCalSource.execute({'CalSource': calsource, 'wait': False})

        check_scriptstop()

        exposestatus = ktl.cache('kpfexpose', 'EXPOSE')
        if exposestatus.read() != 'Ready':
            log.info(f"Waiting for kpfexpose to be Ready")
            WaitForReady.execute({})
            log.debug(f"kpfexpose is Ready")
        # Set source select shutters
        log.info(f"Set Source Select Shutters")
        SetSourceSelectShutters.execute({'SSS_Science': True,
                                         'SSS_Sky': not OB.get('BlockSky', False),
                                         'SSS_SoCalSci': False,
                                         'SSS_SoCalCal': False,
                                         'SSS_CalSciSky': False})

        # Set Triggered Detectors
        OB['TriggerGuide'] = True
        SetTriggeredDetectors.execute(OB)

        check_scriptstop()

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