Bases: KPFTranslatorFunction
Script which cleans up after Cal OBs.
This must have arguments as input, either from a file using the -f
command
line tool, or passed in from the execution engine.
Can be called by ddoi_script_functions.post_observation_cleanup
.
ARGS:
:OB: dict
A fully specified calibration observing block (OB).
Source code in kpf/scripts/CleanupAfterCalibrations.py
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
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
110
111
112
113
114
115
116
117
118 | class CleanupAfterCalibrations(KPFTranslatorFunction):
'''Script which cleans up after Cal OBs.
This must have arguments as input, either from a file using the `-f` command
line tool, or passed in from the execution engine.
Can be called by `ddoi_script_functions.post_observation_cleanup`.
ARGS:
=====
:OB: `dict` A fully specified calibration observing block (OB).
'''
@classmethod
def pre_condition(cls, OB, logger, cfg):
pass
@classmethod
def perform(cls, OB, logger, cfg):
log.info('-------------------------')
log.info(f"Running {cls.__name__}")
for key in OB:
if key not in ['SEQ_Darks', 'SEQ_Calibrations']:
log.debug(f" {key}: {OB[key]}")
else:
log.debug(f" {key}:")
for entry in OB[key]:
log.debug(f" {entry}")
log.info('-------------------------')
# Power off lamps
if OB.get('leave_lamps_on', False) == True:
log.info('Not turning lamps off because command line option was invoked')
else:
sequence = OB.get('SEQ_Calibrations', None)
lamps = set([x['CalSource'] for x in sequence if x['CalSource'] != 'Home'])\
if sequence is not None else []
for lamp in lamps:
if IsCalSourceEnabled.execute({'CalSource': lamp}) == True:
if lamp in ['Th_daily', 'Th_gold', 'U_daily', 'U_gold',
'BrdbandFiber', 'WideFlat']:
CalLampPower.execute({'lamp': lamp, 'power': 'off'})
if lamp == 'LFCFiber':
try:
SetLFCtoStandbyHigh.execute({})
except Exception as e:
log.error('SetLFCtoStandbyHigh failed')
log.error(e)
try:
SendEmail.execute({'Subject': 'ExecuteCals Failed',
'Message': f'{e}'})
except Exception as email_err:
log.error(f'Sending email failed')
log.error(email_err)
kpfconfig = ktl.cache('kpfconfig')
runagitator = kpfconfig['USEAGITATOR'].read(binary=True)
if runagitator is True:
StopAgitator.execute({})
log.info(f"Stowing FIU")
ConfigureFIU.execute({'mode': 'Stowed'})
# Turn off exposure meter controlled exposure
log.debug('Clearing kpf_expmeter.USETHRESHOLD')
kpf_expmeter = ktl.cache('kpf_expmeter')
kpf_expmeter['USETHRESHOLD'].write('No')
# Set OBJECT back to empty string
log.info('Waiting for readout to finish')
WaitForReady.execute({})
SetObject.execute({'Object': ''})
# Clear target info
SetTargetInfo.execute({})
# Clear script keywords
clear_script_keywords()
# Write L0 file name to log if can
WaitForL0File.execute({})
@classmethod
def post_condition(cls, OB, logger, cfg):
pass
@classmethod
def add_cmdline_args(cls, parser, cfg=None):
parser.add_argument('--leave_lamps_on', dest="leave_lamps_on",
default=False, action="store_true",
help='Leave the lamps on after cleanup phase?')
return super().add_cmdline_args(parser, cfg)
|