Bases: KPFFunction
Return the program ID (e.g. E123) of the program that is currently
scheduled. Note that this will only return a program if we are between the
start and end times on the schedule. Officially, the night starts and ends
at 12 degree twilight), so it is possible for observing to be happening
before there is an officially scheduled program.
Source code in kpf/observatoryAPIs/GetCurrentScheduledProgram.py
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 | class GetCurrentScheduledProgram(KPFFunction):
'''Return the program ID (e.g. E123) of the program that is currently
scheduled. Note that this will only return a program if we are between the
start and end times on the schedule. Officially, the night starts and ends
at 12 degree twilight), so it is possible for observing to be happening
before there is an officially scheduled program.
'''
@classmethod
def pre_condition(cls, args):
pass
@classmethod
def perform(cls, args):
'''Returns the currently scheduled program ID.
'''
if args.get('datetime', 'now') == 'now':
inputdateUT = datetime.datetime.utcnow()
else:
inputdateHST = datetime.datetime.strptime(args.get('datetime'), '%Y-%m-%dT%H:%M:%S')
inputdateUT = inputdateHST + datetime.timedelta(hours=10)
startdate = inputdateUT - datetime.timedelta(days=1)
UTdecimal_hour = inputdateUT.hour + inputdateUT.minute/60
params = {'date': startdate.strftime('%Y-%m-%d'),
'numdays': 1,
'telnr': args.get('telnr', 1),
'instrument': 'KPF'}
all_programs = query_observatoryAPI('schedule', 'getSchedule', params)
progname = None
for program in all_programs:
prog_start = string_time_to_decimal(program.get('StartTime'))
prog_end = string_time_to_decimal(program.get('EndTime'))
if UTdecimal_hour >= prog_start and UTdecimal_hour <= prog_end:
progname = program.get('ProjCode')
return progname
@classmethod
def post_condition(cls, args):
pass
@classmethod
def add_cmdline_args(cls, parser):
parser.add_argument('datetime', type=str, default='now',
help='The HST date and time to retrieve (%Y-%m-%dT%H:%M:%S).')
return super().add_cmdline_args(parser)
|
Returns the currently scheduled program ID.
Source code in kpf/observatoryAPIs/GetCurrentScheduledProgram.py
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 | @classmethod
def perform(cls, args):
'''Returns the currently scheduled program ID.
'''
if args.get('datetime', 'now') == 'now':
inputdateUT = datetime.datetime.utcnow()
else:
inputdateHST = datetime.datetime.strptime(args.get('datetime'), '%Y-%m-%dT%H:%M:%S')
inputdateUT = inputdateHST + datetime.timedelta(hours=10)
startdate = inputdateUT - datetime.timedelta(days=1)
UTdecimal_hour = inputdateUT.hour + inputdateUT.minute/60
params = {'date': startdate.strftime('%Y-%m-%d'),
'numdays': 1,
'telnr': args.get('telnr', 1),
'instrument': 'KPF'}
all_programs = query_observatoryAPI('schedule', 'getSchedule', params)
progname = None
for program in all_programs:
prog_start = string_time_to_decimal(program.get('StartTime'))
prog_end = string_time_to_decimal(program.get('EndTime'))
if UTdecimal_hour >= prog_start and UTdecimal_hour <= prog_end:
progname = program.get('ProjCode')
return progname
|