Bases: KPFTranslatorFunction
Look up the telescope schedule and try to determine the observer names
based on the current date and the scheduled programs.
If only one KPF program is on the schedule, the script will use that to set
the observer names. If multiple programs are on the schedule, it will use
the progname input (see below) or query the user if no progname is given.
ARGS:
:progname: str
The program name to set if a choice is needed.
Source code in kpf/utils/SetObserverFromSchedule.py
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86 | class SetObserverFromSchedule(KPFTranslatorFunction):
'''Look up the telescope schedule and try to determine the observer names
based on the current date and the scheduled programs.
If only one KPF program is on the schedule, the script will use that to set
the observer names. If multiple programs are on the schedule, it will use
the progname input (see below) or query the user if no progname is given.
ARGS:
=====
:progname: `str` The program name to set if a choice is needed.
'''
@classmethod
def pre_condition(cls, args, logger, cfg):
pass
@classmethod
def perform(cls, args, logger, cfg):
utnow = datetime.utcnow()
date = utnow-timedelta(days=1)
date_str = date.strftime('%Y-%m-%d')
KPF_programs = [s for s in get_schedule(date_str, 1)
if s['Instrument'] in ['KPF', 'KPF-CC']]
nKPFprograms = len(KPF_programs)
log.debug(f"Found {nKPFprograms} KPF programs in schedule for tonight")
project_codes = [p['ProjCode'] for p in KPF_programs]
ToO_project_codes, ToO_PIs = get_ToO_programs()
print()
print(f"########################################")
print(f" Found {nKPFprograms} KPF programs scheduled for tonight:")
for project_code in project_codes:
print(f" {project_code}")
print(f" Found {len(ToO_project_codes)} ToO programs:")
for i,project_code in enumerate(ToO_project_codes):
print(f" {project_code} (PI {ToO_PIs[i]})")
print(f" Please enter the program ID for your observations:")
print(f"########################################")
print()
progname = input()
if progname.strip() not in project_codes+ToO_project_codes:
log.warning(f"Project code {progname} not on schedule")
if progname is None:
time.sleep(0.5)
print()
print(f" Please enter the program ID for your observations:")
print()
progname = input()
if progname == '':
log.info('No progname specified')
else:
SetProgram.execute({'progname': progname})
this_program = [p for p in KPF_programs if p['ProjCode'] == progname]
if len(this_program) > 0:
observers = this_program[0]['Observers']
else:
print()
print(f" Please enter the observer names:")
print()
observers = input()
log.info(f"Setting observer list: {observers}")
SetObserver.execute({'observer': observers})
@classmethod
def post_condition(cls, args, logger, cfg):
pass
|