SetObject

Bases: KPFTranslatorFunction

Sets the OBJECT keyword for the science detectors in the kpfexpose keyword service.

ARGS:

:Object: str The desired object keyword value.

Source code in kpf/spectrograph/SetObject.py
 9
10
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
class SetObject(KPFTranslatorFunction):
    '''Sets the OBJECT keyword for the science detectors in the kpfexpose
    keyword service.

    ARGS:
    =====
    :Object: `str` The desired object keyword value.
    '''
    @classmethod
    def pre_condition(cls, args, logger, cfg):
        pass

    @classmethod
    def perform(cls, args, logger, cfg):
        kpfexpose = ktl.cache('kpfexpose')
        obj = args.get('Object', '')
        if obj is None:
            obj = ''
        log.debug(f"Setting OBJECT to '{obj}'")
        kpfexpose['OBJECT'].write(obj)
        time_shim = cfg.getfloat('times', 'kpfexpose_shim_time', fallback=0.1)
        time.sleep(time_shim)

    @classmethod
    def post_condition(cls, args, logger, cfg):
        obj = args.get('Object', '')
        if obj is None:
            obj = ''
        timeout = cfg.getfloat('times', 'kpfexpose_response_time', fallback=1)
        expr = f"($kpfexpose.OBJECT == '{obj}')"
        success = ktl.waitFor(expr, timeout=timeout)
        if success is not True:
            objectkw = ktl.cache('kpfexpose', 'OBJECT')
            raise FailedToReachDestination(objectkw.read(), obj)

    @classmethod
    def add_cmdline_args(cls, parser, cfg=None):
        parser.add_argument('Object', type=str,
                            help='The OBJECT keyword')
        return super().add_cmdline_args(parser, cfg)