-
Notifications
You must be signed in to change notification settings - Fork 1
/
scheduler_noncgi.py
executable file
·224 lines (183 loc) · 5.8 KB
/
scheduler_noncgi.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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
#!/opt/local/bin/python2.7
#
# Usage: ./scheduler_noncgi.py 2015/03/09
# where date is in format YYYY/MM/DD
import MySQLdb
import re,glob,os,sys
from SubBlock import *
from Queue import *
#from cStringIO import *
import numpy as np
import random
#import webbrowser
from matplotlib import pyplot as plt
from matplotlib.patches import Rectangle
#import matplotlib.animation as animation
#from matplotlib.collections import PatchCollection
#from matplotlib.gridspec import gridspec
from matplotlib import dates
import matplotlib.dates as md
from datetime import datetime, timedelta
#http://rhodesmill.org/pyephem/
import ephem
#import re,glob,os,sys
#setup some global things
dtor = np.pi/180.0
fsize=[20,40]
fsize=[8,8]
ymin=-0.3
ymax=5.3
XLAB_ROT=40
XLAB_FSIZE=14
SHOW_FULL=0
def IsOverlapping(Astart,Aend,Bstart,Bend):
return ( max(Astart,Bstart) <= min(Aend,Bend))
#SETUP SOME DEFAULT PARAMS
cgi_p0 = 1
cgi_p1 = 1
cgi_p2 = 1
cgi_p3 = 1
cgi_p4 = 0 #leaving this out for speed...
cgi_rss = 1
cgi_hrs = 1
cgi_bvit= 0 #bvit not really used
cgi_scam= 1
cgi_smin = 0
cgi_smax = 10
now = datetime.utcnow()+timedelta(hours=2)
if(now.hour >= 0 and now.hour <= 10):
now = now-timedelta(days=1)
cgi_date = now.strftime("%Y/%m/%d")
#if(len(sys.argv[1])>0):
# cgi_date = sys.argv[1]
cgi_alttime = now.strftime("%H:%M")
cgi_usealttime = 0
cgi_altendtime = now.strftime("%H:%M")
cgi_usealtendtime = 0
cgi_tran = "any"
cgi_notcmoon= 0
cgi_propcode = '2014-2'
cgi_piname = ''
cgi_blockid= ''
cgi_moondist = 30.0
priority_list = []
if(cgi_p0):
priority_list.append(0)
if(cgi_p1):
priority_list.append(1)
if(cgi_p2):
priority_list.append(2)
if(cgi_p3):
priority_list.append(3)
if(cgi_p4):
priority_list.append(4)
seeing_range = [cgi_smin,cgi_smax]
instrument_list = []
if(cgi_rss):
instrument_list.append("RSS")
if(cgi_scam):
instrument_list.append("SCAM")
if(cgi_hrs):
instrument_list.append("HRS")
if(cgi_bvit):
instrument_list.append("BVIT")
sqlhost= "sdb.saao"
sqldb = "sdb"
debug = 1
q = Queue(cgi_date,priority_list,seeing_range,cgi_usealttime,cgi_alttime,cgi_usealtendtime,cgi_altendtime,instrument_list,cgi_tran,cgi_notcmoon,cgi_propcode,cgi_piname,cgi_blockid,cgi_moondist,sqlhost,sqldb,debug)
(dstart,dend) = q.GetTwilightTimes()
total_duration = q.GetDuration()
duration_str="%.2f h" % (total_duration)
x=[dstart-timedelta(minutes=30),dend+timedelta(minutes=30)]
dt=timedelta(hours=total_duration*1.0/3.0)
#print "%.2f" % total_duration
#twilight buffer
dtwi=timedelta(minutes=30)
#buffer between plots
db=timedelta(minutes=5)
t1=dstart-dtwi
t2=t1+dtwi+dt
x1=[t1,t2]
t1=t2
t2=t1+dt
x2=[t1-db,t2+db]
t1=t2
t3=dend+dtwi
x3=[t1,t3]
yrange=[ymin,ymax]
yoffset=0.05*ymax
f, (ax1, ax2, ax3) = plt.subplots(nrows=3,ncols=1, sharey=True,subplot_kw=dict(ylim=yrange,yticks=[]),figsize=fsize)
f.subplots_adjust(hspace=0.3,left=0.05,right=0.95,top=0.925)
xfmt=md.DateFormatter('%H:%M')
ax1.xaxis.set_major_formatter(xfmt)
ax2.xaxis.set_major_formatter(xfmt)
ax3.xaxis.set_major_formatter(xfmt)
ax1.set_xlim(x1)
ax2.set_xlim(x2)
ax3.set_xlim(x3)
ax1.xaxis.set_major_locator(md.HourLocator(interval=1))
ax2.xaxis.set_major_locator(md.HourLocator(interval=1))
ax3.xaxis.set_major_locator(md.HourLocator(interval=1))
ax1.xaxis.set_minor_locator(md.MinuteLocator(byminute=range(0,60,10)))
ax2.xaxis.set_minor_locator(md.MinuteLocator(byminute=range(0,60,10)))
ax3.xaxis.set_minor_locator(md.MinuteLocator(byminute=range(0,60,10)))
ax1.tick_params(which='major',length=7,width=2)
ax1.tick_params(which='minor',length=5)
ax2.tick_params(which='major',length=7,width=2)
ax2.tick_params(which='minor',length=5)
ax3.tick_params(which='major',length=7,width=2)
ax3.tick_params(which='minor',length=5)
#ax1.major_ticks.set_ticksize(10)
#f.figsize=fsize
moonstr = ' [%d per cent]' % (q.GetMoonIllum())
ax1.set_title(dstart.strftime("%d %b %Y")+"\n"+duration_str+moonstr)#,weight='bold',va='top')
#format the axes properly
plt.setp(ax1.get_yticklabels(), visible=False)
plt.setp(ax2.get_yticklabels(), visible=False)
plt.setp(ax3.get_yticklabels(), visible=False)
for label in ax1.xaxis.get_ticklabels():
label.set_rotation(XLAB_ROT)
label.set_fontsize(XLAB_FSIZE)
for label in ax2.xaxis.get_ticklabels():
label.set_rotation(XLAB_ROT)
label.set_fontsize(XLAB_FSIZE)
for label in ax3.xaxis.get_ticklabels():
label.set_rotation(XLAB_ROT)
label.set_fontsize(XLAB_FSIZE)
#xstart,xend =ax1.get_xlim()
#ax1.xaxis.set_ticks(np.arange(xstart,xend,timedelta(hours=1.0)))
ax1.plot([dstart,dstart],yrange,'r--',lw=2.0)
ax3.plot([dend,dend],yrange,'r--',lw=2.0)
ti5=dstart-timedelta(minutes=15)
ti10=dstart-timedelta(minutes=20)
ti15=dstart-timedelta(minutes=25)
tf5=dend+timedelta(minutes=5)
tf10=dend+timedelta(minutes=10)
tf15=dend+timedelta(minutes=15)
ax3.plot([tf5,tf5],yrange,'y-',lw=2.0)
ax3.plot([tf10,tf10],yrange,'y-',lw=2.0)
ax3.plot([tf15,tf15],yrange,'y-',lw=2.0)
if(cgi_usealttime == 0):
ax1.plot([ti5,ti5],yrange,'y-',lw=2.0)
ax1.plot([ti10,ti10],yrange,'y-',lw=2.0)
ax1.plot([ti15,ti15],yrange,'y-',lw=2.0)
moon_alpha = 0.3
#moon_alpha = 0.5
(mstart,mend,mduration) = q.GetMoonRange()
if(mstart != 'NULL' and mend != 'NULL'):
ax1.add_patch(Rectangle((mstart,yrange[0]),mduration,yrange[1]*1.5,color='yellow',picker=False,alpha=moon_alpha))
ax2.add_patch(Rectangle((mstart,yrange[0]),mduration,yrange[1]*1.5,color='yellow',picker=False,alpha=moon_alpha))
ax3.add_patch(Rectangle((mstart,yrange[0]),mduration,yrange[1]*1.5,color='yellow',picker=False,alpha=moon_alpha))
#cgi_niter = 15
#if(cgi_p0 and cgi_p1):
# q.RandomiseBlocks(cgi_niter,False,0,1)
#if(cgi_p1 and cgi_p2):
# q.RandomiseBlocks(cgi_niter,False,1,2)
#if(cgi_p2 and cgi_p3):
# q.RandomiseBlocks(cgi_niter,False,2,3)
#if(cgi_p3 and cgi_p4):
# q.RandomiseBlocks(cgi_niter,False,3,4)
q.MimicSA()
print q.CountInActiveBlocks(0)
q.DisplayActiveBlocks(ax1,ax2,ax3,yrange)
plt.show()