-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathselect_obs.py
163 lines (124 loc) · 4.85 KB
/
select_obs.py
1
2
3
4
5
6
7
8
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
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import numpy as np
import astropy.units as u
import weights as weights
def _getcalday(instcal, date):
"""
Get index of row for current night in instrument calendar table.
"""
for i in range(len(instcal['date'])):
if instcal['date'][i] in date:
return i
print('\n Date '+date+' not found in instrument configuration calendar.')
raise ValueError('Date '+date+' not found in instrument configuration calendar.')
def _checkinst(inst, disp, fpu, insttable):
"""
Check observation instrument requirements against tonight's instrument configuration.
Parameters
----------
inst : str
Observation instrument
disp : str
Observation instrument disperser (or 'null')
fpu : str
Observation instrument focal plane unit (or 'null')
insttable : '~astropy.table.Table'
Instrument configuration calender.
i_cal : int
Index of row for tonights instrument configuration.
Returns
-------
boolean. True or False if the observation requirements are satisfied by the current configuration.
"""
# print('\ninst, disp, fpu: ',inst,disp,fpu)
if inst not in insttable['insts']:
# print('Not available')
return False
elif inst in insttable['insts']:
# print('Available')
if 'GMOS' in inst:
# print('GMOS')
return ((disp in insttable['gmos_disp']) or ('null' in insttable['gmos_disp'])) and \
((fpu in insttable['gmos_fpu']) or ('null' in insttable['gmos_fpu']))
elif 'Flamingos' in inst:
# print('Flamingos')
return (fpu == insttable['f2_fpu']) or (insttable['f2_fpu'] == 'null')
else:
# print('Not GMOS or F2')
return True
def i_progs(gemprgid, prog_ref, verbose = False):
"""
Match program identifier strings in prog_ref to strings in gemprgid.
Return array of indices.
Parameters
----------
gemprgid : list of strings
Gemini program id column from program table
prof_ref :
Gemini program id column from observation table
Returns
-------
i_progs : int array
Array of indices.
"""
i_progs = np.full(len(prog_ref), -1)
prog_refs = np.unique(prog_ref)
if verbose:
print(prog_refs)
for prog in prog_refs:
# print (prog, np.where(gemprgid == prog)[0])
j = np.where(gemprgid == prog)[0][0] # should only have one value in array
jj = np.where(prog_ref == prog)[0][:] # observations in queue from program 'prog'
i_progs[jj] = j
if verbose:
print(prog, j, jj)
return i_progs
def instconfig(inst, disp, fpu, insttable, date, verbose = False):
"""
Select observations to add to tonight's queue.
Parameters
----------
obs : '~astropy.table.Table'
All observations in queue
insttable : '~astropy.table.Table'
Instrument configuration calender.
date : str
tonights date
Returns
-------
numpy integer array
indices of observations selected for tonight's queue
"""
i_cal = _getcalday(instcal=insttable, date=date)
bools = [_checkinst(inst=inst[j], disp=disp[j], fpu=fpu[j], insttable=insttable[i_cal]) for j in range(len(inst))]
if verbose:
print(' \n Verbose: select_obs.selectinst...')
print(' Date: ', insttable['date'][i_cal])
print(' Available inst.: ', insttable['insts'][i_cal])
print(' GMOS disperser: ', insttable['gmos_disp'][i_cal])
print(' GMOS fpu: ', insttable['gmos_fpu'][i_cal])
print(' F2 fpu: ', insttable['f2_fpu'][i_cal])
print('')
vprint = '\t{0:12.10} {1:12.10} {2:12.10} {3:12.10}'
print(vprint.format('Boolean', 'Inst.', 'Disperser', 'FPU'))
print(vprint.format('-------', '-----', '---------', '---'))
for k in range(len(inst)):
print(vprint.format(str(bools[k]), inst[k], disp[k], fpu[k]))
return np.where(bools)[0][:]
def selectqueue(cattable):
"""
Select observations from catalog to add to Queue.
Parameters
----------
cattable : '~gemini_otcat.Gcatfile'
OT catalog info
Returns
-------
numpy integer array
indices of observations selected for queue
"""
return np.where(np.logical_and(np.logical_or(cattable['obs_status'] == 'Ready', cattable['obs_status'] == 'Ongoing'),
cattable['obs_class'] == 'Science'))[0][:]
# np.logical_or(cattable['obs_class'] == 'Science',
# np.logical_and(np.logical_or(cattable['inst'] == 'GMOS', cattable['inst'] == 'bHROS'),
# np.logical_or(cattable['obs_class'] == 'Nighttime Partner Calibration',
# cattable['obs_class'] == 'Nighttime Program Calibration')))))[0][:]