WaitForReadout

Bases: KPFFunction

Waits for the kpfexpose.EXPOSE keyword to be "Readout". This will block until the camera enters the readout state.

ARGS:

None

Source code in kpf/spectrograph/WaitForReadout.py
11
12
13
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
58
59
60
61
62
63
64
65
66
67
68
class WaitForReadout(KPFFunction):
    '''Waits for the `kpfexpose.EXPOSE` keyword to be "Readout".  This will
    block until the camera enters the readout state.

    ARGS:
    =====
    None
    '''
    @classmethod
    def pre_condition(cls, args):
        pass

    @classmethod
    def perform(cls, args):
        kpfexpose = ktl.cache('kpfexpose')
        exptime = kpfexpose['EXPOSURE'].read(binary=True)
        starting_status = kpfexpose['EXPOSE'].read(binary=True)

        detectors = kpfexpose['TRIG_TARG'].read()
        detector_list = detectors.split(',')

        buffer_time = cfg.getfloat('times', 'readout_buffer_time', fallback=10)
        wait_time = exptime+buffer_time if starting_status < 3 else buffer_time

        wait_logic_steps = ['($kpfexpose.EXPOSE == 4)']
        if 'Green' in detector_list:
            wait_logic_steps.append("($kpfgreen.EXPSTATE == 4)")
        if 'Red' in detector_list:
            wait_logic_steps.append("($kpfred.EXPSTATE == 4)")
        if 'Ca_HK' in detector_list:
            wait_logic_steps.append("($kpf_hk.EXPSTATE == 4)")
        wait_logic = ' and '.join(wait_logic_steps)

        log.debug(f"Waiting ({wait_time:.0f}s max) for readout to begin")
        success = ktl.waitFor(wait_logic, timeout=wait_time)
        if success is True:
            log.debug(f'kpfexpose is {kpfexpose["EXPOSE"].read()}')
            if 'Green' in detector_list:
                nextfile = ktl.cache('kpfgreen', 'NEXTFILE')
                log.debug(f"Green nextfile: {nextfile.read()}")
            if 'Red' in detector_list:
                nextfile = ktl.cache('kpfred', 'NEXTFILE')
                log.debug(f"Red nextfile: {nextfile.read()}")
        else:
            log.warning('WaitForReadout failed to reach expected state')
            log.debug(f'kpfexpose is {kpfexpose["EXPOSE"].read()}')
            log.debug(f'kpfexpose EXPLAINR = {kpfexpose["EXPLAINR"].read()}')
            log.debug(f'kpfexpose EXPLAINNR = {kpfexpose["EXPLAINNR"].read()}')
            RecoverDetectors.execute({})

    @classmethod
    def post_condition(cls, args):
        expr = "($kpfexpose.EXPOSE == 'Ready') or ($kpfexpose.EXPOSE == 'Readout')"
        timeout = cfg.getfloat('times', 'kpfexpose_reset_time', fallback=10)
        ok = ktl.waitFor(expr, timeout=timeout)
        if ok is not True:
            expose = ktl.cache('kpfexpose', 'EXPOSE')
            raise FailedPostCondition(f"kpfexpose.EXPOSE={expose.read()} is not Ready or Readout")