SetSimulCalSource

Bases: KPFTranslatorFunction

Set the slew cal and simultaneous calibration source.

Valid names: EtalonFiber, U_gold, U_daily, Th_daily, Th_gold, LFCFiber

ARGS:

:calsource: The calibration source to use (must be one of Etalon, LFC, Th_daily, Th_gold, U_daily, U_gold).

Source code in kpf/utils/SetSimulCalSource.py
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
class SetSimulCalSource(KPFTranslatorFunction):
    '''Set the slew cal and simultaneous calibration source.

    Valid names: EtalonFiber, U_gold, U_daily, Th_daily, Th_gold, LFCFiber

    ARGS:
    =====
    :calsource: The calibration source to use (must be one of Etalon, LFC,
                Th_daily, Th_gold, U_daily, U_gold).
    '''
    @classmethod
    def pre_condition(cls, args, logger, cfg):
        valid_names = ['EtalonFiber', 'U_gold', 'U_daily', 'Th_daily',
                       'Th_gold', 'LFCFiber']
        if args.get('CalSource', None) not in valid_names:
            raise FailedPreCondition(f"calsource '{calsource}' must be one of {valid_names}")

    @classmethod
    def perform(cls, args, logger, cfg):
        log.info(f"Setting simul cal / slew cal source")
        calsource = args.get('CalSource')
        kpfconfig = ktl.cache('kpfconfig')
        slew_cal_file = Path(f'/kroot/rel/default/data/obs/kpf/SlewCal_{calsource}.yaml')
        if slew_cal_file.exists() is False:
            raise KPFException(f'The slew cal file for {calsource} does not exist')
        else:
            log.info(f'Writing kpfconfig.SIMULCALSOURCE = {calsource}')
            kpfconfig['SIMULCALSOURCE'].write(calsource)
            log.info(f'Writing kpfconfig.SLEWCALFILE = {slew_cal_file}')
            kpfconfig['SLEWCALFILE'].write(f"{slew_cal_file}")

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

    @classmethod
    def add_cmdline_args(cls, parser, cfg=None):
        parser.add_argument('CalSource', type=str,
                            choices=['EtalonFiber', 'U_gold', 'U_daily',
                                     'Th_daily', 'Th_gold', 'LFCFiber'],
                            help='Which lamp to use for simultaneous calibration and slew cals')
        return super().add_cmdline_args(parser, cfg)