Документ взят из кэша поисковой машины. Адрес оригинального документа : http://www.stsci.edu/spst/UnixTransition/doc/sel_tdrs_bargraph.py
Дата изменения: Fri Apr 8 12:46:13 2016
Дата индексирования: Mon Apr 11 04:02:48 2016
Кодировка:

Поисковые слова: http www.badastronomy.com bad tv foxapollo.html
#
#MODULE sel_tdrs_bargraph
#
#****************************************************************************
"""Produces a bar graph for a selected region of the results of the (MAT-LEI)
TDRS selection tool

TITLE: sel_tdrs_bargraph.py
DEVELOPER: Alan Patterson, 10-Nov-2005

PURPOSE: The tool generates a bar graph for a selected region of the
results of the (MAT-LEI) TDRS selection tool

USAGE: do sel_tdrs_bargraph [-single]

where: is the result file from the TDRS
selection tool
-save causes output files (.PS) to be created
along with the screen display
-single presents the graph in one large pane
-period_markers causes the zoe and anode markers
to appear. (The plots will take
longer to create with this option)

RETURNS: Nothing

MOD HISTORY:
Include recognition of keeper TDRS events app 01/22/06
Include -period_markers option app 01/24/06
Add TDRS period color and marker app 01/30/06
Add save plot file feature app 01/31/06
Update documentation app 02/07/06
Mod for simpler data file name app 02/08/06
fix 000 day number drc 10/29/10
code cleanup drc 4/15/15
"""
#****************************************************************************
__author__ = "Alan Patterson"
__version__ = "15.04.15"

from pylab import figure, bar, title, vlines, setp, yticks, xlabel, legend, xlim, ylim, savefig, show
import sys
import spss_sys_util
import spst_getopt
import time_util
import os
import ccl_util
import calendar_util
import sms_util


def run(*args):
"""Creates a series of 'piano key' bargraph plots of the results
of the Communication Advisor Tool (CAT)which is part of the MAT LEI process.

Usage:

do sel_tdrs_bargraph

where
is the selection output of the CAT
Default file extension is .sel
Default name is __
n is the number of loads and g is the
gap limit used (10800 seconds default)
-period_markers puts the period markers on the plot
-save causes output files (.PS) to be created
along with the screen display
-single presents the whole week in one plot!
(which is very crowded but can be
expanded in the interactive gui)
"""
if len(args) == 0 or (len(args) == 1 and args[0] is None):
print run.__doc__
return not spss_sys_util.SUCCESS
low_args = []
for a in args:
b = a.split('=')[0]
low_args.append(a.replace(b, b.lower()))
allowed_options = ['verbose',
'outfile=',
'save',
'single',
'period_markers']
options, parms = spst_getopt.spst_getopt(low_args, allowed_options)

if len(parms) != 1:
print 'Filename is required'
return not spss_sys_util.SUCCESS

selfile = parms[0]
# from 02/08/07 the selfile name structure is .sel

lines = open(selfile).readlines()

basename = os.path.basename(selfile)
base = os.path.splitext(basename)[0]
sms = sms_util.sms(base, pass_name=1)
cclname = sms.get_calendar_name()
passname = sms.get_pass_sms_name()
state = []
wins = []
old = []

if '-save' in options:
savefiles = '%s_bargraph' % base
print 'Plots will be saved with names starting with %s' % savefiles
else:
savefiles = None

for i in range(len(lines)):
s = lines[i][-7:-1]
o = lines[i][-16:-7]
z = lines[i].split()
t1 = time_util.spss_time(z[0])
t2 = t1 + time_util.delta_time(z[1])
state.append(s)
old.append(o)
wins.append(time_util.window(t1, t2))
#yyyy = lines[0][:4]
#tzero = time_util.spss_time('%s.001' % lines[0][:4]) - 86400.

if '-period_markers' in options:
zoewins, anodetimes = get_calendar_data(cclname)
zoetimes = []
for z in zoewins:
zoeval = z.starttime() + 300
zoetimes.append(zoeval)
else:
zoewins = []
anodetimes = []
zoetimes = []

calstart = sms.get_begin_time()
calend = sms.get_end_time()

ifig = 1
#done = 0
calwinstart = calstart
if '-single' in options:
calwinend = calend
figure(1, (20.0, 8))
fsize = (20., 8.5)
print 'Close plot window to continue ...'
fig_plot(calwinstart,
calwinend,
wins,
anodetimes,
zoetimes,
ifig,
fsize,
state,
old,
passname,
savefiles)
else:
calwinend = calwinstart + 86400
fsize = (10.5, 8.0)
print 'Close plot window for Figure 1 to continue ...'
while calwinstart < calend:
fig_plot(calwinstart,
calwinend,
wins,
anodetimes,
zoetimes,
ifig,
fsize,
state,
old,
passname,
savefiles)
calwinstart = calwinend
calwinend = calwinstart + 86400
ifig = ifig + 1
print 'Enter to exit program'
raw_input()

return spss_sys_util.SUCCESS


def fig_plot(start,
end,
wins,
anodetimes,
zoetimes,
fignum,
figsize,
state,
old,
passname,
savefiles):
"""
"""
yyyy = start.strftime("%Y")
tzero = time_util.spss_time('%s.001' % yyyy) - 86400.
viewwin = time_util.window(start,end)
xvals = []
width = []
colors = []
col1b = (0.00, 0.75, 0.75)
col2b = (0.75, 0.00, 0.75)
#col3b = (0.75, 0.75, 0.00)
col1 = (0.00, 0.50, 0.50)
col1p = (0.00, 0.25, 0.25)
col2 = (0.50, 0.00, 0.50)
#col3 = (0.50, 0.50, 0.00)
colgray = (0.85, 0.85, 0.85)

height = []
bottom = []

fs_day = float(start-tzero)/86400.
fe_day = float(end-tzero)/86400.
#print fs_day,fe_day
#s_day = int(fs_day)
#e_day = int(fe_day)

for iw in range(len(wins)):
w = wins[iw]
if w.overlaps(viewwin):
#print w,state[iw]
xlo = float(w.starttime()-tzero)/86400.
xhi = float(w.endtime()-tzero)/86400.
xvals.append(xlo)
width.append(xhi-xlo)
bottom.append(0.0)
height.append(1.0)
if state[iw][0] == 'L':
col = 'r'
elif state[iw][0] == 'K':
col = 'k'
elif state[iw][5] == 'X':
col = col2
elif state[iw][4] == 'G':
col = col1
elif state[iw][4] == 'P':
col = col1p
elif state[iw][3] == 'S':
col = 'b'
elif state[iw][3] == 'E':
col = 'g'
else:
col = colgray
colors.append(col)
#
xvals.append(xlo)
width.append(xhi-xlo)
bottom.append(1.25)
height.append(0.25)
if state[iw][0] == 'L':
col = 'r'
elif state[iw][0] in ['l', 'K'] and state[iw][3:6] != ' ':
col = (1.0, 0.6, 0.6)
else:
col = colgray
height[-1] = 0.2
colors.append(col)
#
xvals.append(xlo)
width.append(xhi-xlo)
bottom.append(1.75)
height.append(0.25)
if state[iw][3] == 'S':
col = 'b'
elif state[iw][0] in ['L', 'K'] or state[iw][4:6] != ' ':
col = (0.6, 0.6, 1.0)
else:
col = colgray
height[-1] = 0.2
colors.append(col)
#
xvals.append(xlo)
width.append(xhi-xlo)
bottom.append(2.25)
height.append(0.25)
if state[iw][3] == 'E':
col = 'g'
else:
col = colgray
height[-1] = 0.2
colors.append(col)
#
xvals.append(xlo)
width.append(xhi-xlo)
bottom.append(2.75)
height.append(0.25)
if state[iw][4] == 'G':
col = col1
elif state[iw][4] == 'P':
col = col1p
height[-1] = 0.3
elif state[iw][0] in ['L', 'K'] or state[iw][4:6] != ' ':
col = col1b
else:
col = colgray
height[-1] = 0.2
colors.append(col)
#
xvals.append(xlo)
width.append(xhi-xlo)
bottom.append(3.25)
height.append(0.25)
if state[iw][5] == 'X':
col = col2
elif (state[iw][0] in ['L', 'K'] or state[iw][4:6] != ' ') and old[iw][5] == 'X':
col = col2b
else:
col = colgray
height[-1] = 0.2
colors.append(col)
#
x_anode = []
x_zoe = []
for a in anodetimes:
if a > start and a < end:
xa = float(a-tzero)/86400.
x_anode.append(xa)
for z in zoetimes:
if z > start and z < end:
xz = float(z-tzero)/86400.
x_zoe.append(xz)

#minxvals = min(xvals)
#maxxvals = max(xvals)

figure(fignum, figsize)
bar(xvals, height, width=width, bottom=bottom, color=colors)
title('TDRS event designation for %s' % passname)
if len(x_anode) > 0:
va = vlines(x_anode, [1.05], [1.20], color='k')
vlines(x_anode, [1.55], [1.70], color='k')
vlines(x_anode, [2.05], [2.20], color='k')
vlines(x_anode, [2.55], [2.70], color='k')
vlines(x_anode, [3.05], [3.20], color='k')
if len(x_zoe) > 0:
vz = vlines(x_zoe, [1.00], [1.25], color='b')
setp(vz, linewidth=2)
setp(vlines(x_zoe, [1.50], [1.75], color='b'), linewidth=2)
setp(vlines(x_zoe, [2.00], [2.25], color='b'), linewidth=2)
setp(vlines(x_zoe, [2.50], [2.75], color='b'), linewidth=2)
setp(vlines(x_zoe, [3.00], [3.25], color='b'), linewidth=2)
ytloc, ytlab = yticks([0.5, 1.375, 1.875, 2.375, 2.875, 3.375, 3.9],
['Selected', 'Loads', 'Science', 'EngDump', 'RT-Eng', 'Xtrack', 'ACTIVITIES'])
ytlab[-1].set_weight('bold')
xlabel('Day of Year (%s)' % start.strftime("%Y.%j"))
ylim(ymax=4.0)
xlim(xmin=fs_day)
xlim(xmax=fe_day)
if len(x_zoe) > 0:
legend([vz[0], va[0]], ['TDRS ZOE period', 'HST orbit period'], 0)
if savefiles is not None:
fil = '%s_%i.ps' % (savefiles, fignum)
savefig(fil, orientation='landscape')
show()

return


def get_calendar_data(cclname):
"""
"""
ccl = ccl_util.ccl(cclname)
ccl.get()
cal = calendar_util.cal_display()
anodes = cal.get_ascending_node_list()
anode_times = []
for a in anodes:
anode_times.append(a['begin_time'])
tdrs = cal.get_tdrs_list()
zstart = cal.get_begin_time()
zoewins = []
for td in tdrs:
if td['tdrs'] == 'EAST' and td['service_type'] == 'MA ':
e = td['end_time']
if zstart is None or e > zstart:
zstart = e
if td['tdrs'] == 'WEST' and td['service_type'] == 'MA ':
s = td['begin_time']
if zstart is not None and s > zstart:
zoewins.append(time_util.window(zstart, s))
zstart = None
calend = cal.get_end_time()
if zstart is not None and zstart < calend:
zoewins.append(time_util.window(zstart, calend))
print zoewins[-1]
return zoewins, anode_times


# to run on commandline
if __name__ == '__main__':
input1 = None
if len(sys.argv) > 1:
run(*tuple(sys.argv[1:]))
else:
run(None)