WaitForConfigureFIU

Bases: KPFTranslatorFunction

Wait for the FIU to reach specified mode (kpffiu.MODE). This will retry the configure command if the system fails to reach its destination.

Parameters:
  • mode (str) –

    The desired FIU mode. Allowed values: Stowed, Alignment, Acquisition, Observing, Calibration

KTL Keywords Used:

  • kpffiu.MODE

Scripts Called:

  • kpf.calbench.ConfigureFIUOnce
Source code in kpf/fiu/WaitForConfigureFIU.py
 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
class WaitForConfigureFIU(KPFTranslatorFunction):
    '''Wait for the FIU to reach specified mode (kpffiu.MODE). This will retry
    the configure command if the system fails to reach its destination.

    Args:
        mode (str): The desired FIU mode. Allowed values: Stowed, Alignment,
            Acquisition, Observing, Calibration

    KTL Keywords Used:

    - `kpffiu.MODE`

    Scripts Called:

    - `kpf.calbench.ConfigureFIUOnce`
    '''
    @classmethod
    def pre_condition(cls, args, logger, cfg):
        keyword = ktl.cache('kpffiu', 'MODE')
        allowed_values = list(keyword._getEnumerators())
        if 'None' in allowed_values:
            allowed_values.pop(allowed_values.index('None'))
        check_input(args, 'mode', allowed_values=allowed_values)
        return True

    @classmethod
    def perform(cls, args, logger, cfg):
        dest = args.get('mode')
        ntries = cfg.getint('retries', 'fiu_mode_tries', fallback=2)
        shim_time = cfg.getfloat('times', 'fiu_mode_shim_time', fallback=2)
        for i in range(ntries):
            ok = WaitForConfigureFIUOnce.execute({'mode': dest})
            if ok is False:
                log.warning(f'FIU move failed on attempt {i+1} of {ntries}')
                time.sleep(shim_time)
                ConfigureFIUOnce.execute({'mode': dest, 'wait': True})
            else:
                break

    @classmethod
    def post_condition(cls, args, logger, cfg):
        dest = args.get('mode')
        kpffiu = ktl.cache('kpffiu')
        modes = kpffiu['MODE'].read()
        if dest.lower() not in modes.lower().split(','):
            raise FailedToReachDestination(modes, dest)
        else:
            log.info(f"FIU mode is now {dest}")

    @classmethod
    def add_cmdline_args(cls, parser, cfg=None):
        parser.add_argument('mode', type=str,
                            choices=['Stowed', 'Alignment', 'Acquisition',
                                     'Observing', 'Calibration'],
                            help='Desired mode (see kpffiu.MODE)')
        return super().add_cmdline_args(parser, cfg)