Документ взят из кэша поисковой машины. Адрес оригинального документа : http://www.stsci.edu/spst/UnixTransition/doc/plot_ssr_vol.py
Дата изменения: Fri Feb 28 14:46:11 2014
Дата индексирования: Sat Mar 1 16:17:09 2014
Кодировка:

Поисковые слова: m 17
#
#MODULE plot_ssr_vol
#
#***********************************************************************
"""

**PURPOSE** --
Generate the science and engineering SSR volume plots.

**DEVELOPER** --
Don Chance

**MODIFICATION HISTORY** --
o initial implementation DC 9/28/05
o take an input directory DC 11/8/06
"""
#***********************************************************************
import pylab
import spss_sys_util
import os
import string

__version__ = "11/8/06"

def run(msdir=None):
"""Generate the science and engineering SSR volume plots.

Usage:
do plot_ssr_vol []

Input parameter is assumed to be an MS directory. If no directory
is specified, then the tool assumes your current working directory
is an MS directory. In either case, the directory must contain RSO,
PED, and PSD files.
"""
if msdir:
os.chdir(msdir)

# First generate the science data volume plot.
found_file = False
filename = find_file('psd')
if filename:
found_file = True
lines = parse_file(filename)
time = [i[0] for i in lines]
tvol = [i[1] for i in lines]
tvol_gbits = [i[2] for i in lines]
tsize = [i[3] for i in lines]
trigger = [i[4] for i in lines]
ssr1 = [i[5] for i in lines]
ssr3 = [i[7] for i in lines]
size1 = [i[9] for i in lines]
size3 = [i[10] for i in lines]

pylab.figure(1)
pylab.plot(time, tvol,
time, ssr1,
time, ssr3,
time, tsize,
time, trigger,
time, size1,
time, size3)
pylab.xlabel('Time (Day of year)')
pylab.ylabel('Science Data Volume (Blocks)')
pylab.legend(('Total Volume',
'SSR1 Volume',
'SSR3 Volume',
'Total Capacity',
'Trigger',
'SSR1 Capacity',
'SSR3 Capacity'))
rsofile = find_file('rso')
if rsofile:
vol_text = "Total Vol recorded: %6.2f Gbits\nTotal Vol dumped: %6.2f Gbits" % get_recorded_dumped(rsofile)
pylab.figtext(0.2, 0.8, vol_text)
msname = os.path.basename(os.path.dirname(filename))
pylab.title('Science Data Volume for %s' % msname)
if spss_sys_util.get_environ_variable('MODE') != ['interactive']:
# Don't save the plot in interactive mode. The user can
# do that himself in the plot window.
pylab.savefig(msname + '-sci.ps')

# Now generate the engineering data volume plot.
filename = find_file('ped')
if filename:
found_file = True
lines = parse_file(filename)
time = [i[0] for i in lines]
tvol = [i[1] for i in lines]
tsize = [i[3] for i in lines]
trigger= [i[4] for i in lines]

pylab.figure(2)
pylab.plot(time, tvol,
time, tsize,
time, trigger)
pylab.xlabel('Time (Day of year)')
pylab.ylabel('Science Data Volume (Blocks)')
pylab.legend(('Total Eng Volume',
'Total Eng Capacity',
'Trigger'))
msname = os.path.basename(os.path.dirname(filename))
pylab.title('Engineering Data Volume for %s' % msname)
if spss_sys_util.get_environ_variable('MODE') != ['interactive']:
# Don't save the plot in interactive mode. The user can
# do that himself in the plot window.
pylab.savefig(msname + '-eng.ps')
if found_file and spss_sys_util.get_environ_variable('MODE')==['interactive']:
pylab.show()

def find_file(extension):
"""Find the file with given extension in the current working directory.
"""
file_glob = spss_sys_util.glob('*.%s' % extension)
if file_glob:
return os.path.abspath(file_glob[0])
return ''

def parse_file(fname):
"""Parse a ped or psd file for SSR information.
"""
lines = []
for line in open(fname).readlines()[1:]:
sline=line.split(',')
z=[]
for item in ([sline[0]] + sline[3:]):
z.append(float(item))
lines.append(z)
return lines

def get_recorded_dumped(rsofile):
"""Extract the total volume recorded/dumped from the rso file
"""
# Extract certain summary data
volrec = 0.0
voldump = 0.0
for line in open(rsofile).readlines():
if (string.find(line,"TOTAL SCIENCE DATA RECORDED (BLOCKS)") != -1):
z = string.split(line,')')
volrec = float(z[1]) * 0.00021504
if (string.find(line,"TOTAL SCIENCE DATA RECORDED (GBITS)") != -1):
z = string.split(line,')')
zz = string.strip(z[1])
if (zz[0] != "*"):
volrec = float(z[1])
if (string.find(line,"TOTAL SCIENCE DUMPED VOLUME (BLOCKS)") != -1):
z = string.split(line,')')
voldump = float(z[1]) * 0.00021504
if (string.find(line,"TOTAL SCIENCE DUMPED VOLUME (GBITS)") != -1):
z = string.split(line,')')
zz = string.strip(z[1])
if (zz[0] != "*"):
voldump = float(z[1])

return volrec, voldump

if __name__ == '__main__':
import sys
if len(sys.argv) > 1:
apply(run, (sys.argv[1],))
else:
run()