TriggerRedMiniFill

Bases: KPFTranslatorFunction

I really hope this is not necessary in the long term.

Source code in kpf/engineering/TriggerRedMiniFill.py
14
15
16
17
18
19
20
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
class TriggerRedMiniFill(KPFTranslatorFunction):
    '''I really hope this is not necessary in the long term.
    '''
    @classmethod
    def pre_condition(cls, args, logger, cfg):
        kpffill = ktl.cache('kpffill')
        if kpffill['REDFILLIP'].read() == 'True':
            raise FailedPreCondition('Red fill already in progress')

    @classmethod
    def perform(cls, args, logger, cfg):
        kpffill = ktl.cache('kpffill')
        # Start fill
        log.warning(f'Starting Red mini fill')
        kpffill['REDSTART'].write(1)
        # Wait
        sleep_time = args.get('duration', 240)
        log.debug(f'Sleeping {sleep_time:.0f} s')
        time.sleep(sleep_time)
        # Stop fill
        if kpffill['REDFILLIP'].read() == 'True':
            log.warning(f'Stopping Red mini fill')
            kpffill['REDSTOP'].write(1)
            time.sleep(5)
        else:
            msg = 'Expected Red mini fill to be in progress.'
            SendEmail.execute({'Subject': 'TriggerRedMiniFill Failed',
                               'Message': f'{msg}'})
            raise KPFException(msg)

    @classmethod
    def post_condition(cls, args, logger, cfg):
        kpffill = ktl.cache('kpffill')
        if kpffill['RedFILLIP'].read() == 'True':
            msg = 'Red still in progress, should be stopped!'
            SendEmail.execute({'Subject': 'TriggerRedMiniFill Failed',
                               'Message': f'{msg}'})
            raise FailedPostCondition(msg)

    @classmethod
    def add_cmdline_args(cls, parser, cfg=None):
        parser.add_argument('duration', type=float,
                            help='The duration of the fill in seconds (240 recommended)')
        return super().add_cmdline_args(parser, cfg)