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

Поисковые слова: http astrokuban.info astrokuban
#!/usr/bin/env python
#MODULE np_hiding
#
#***********************************************************************
"""

**PURPOSE** --
Summarize for each visit within an LRP the essential SAA-hiding and
North-point hiding characteristics of the plan and constraint windows.

**DEVELOPER** --
Don Chance (from requirements provided by Ian Jordan)

**MODIFICATION HISTORY** --
Date Who What
==== === ====
07-09-07 Chance Initial implementation
07-23-12 Chance filter out bad visit ids
"""
#***********************************************************************
__version__ = "7/23/12"

import lrp_util
import sys
import time_util
import spss_sys_util
import spst_getopt
import orbit_util
import constraint_window
import visit_util
import re

GYRO_MODES = ('1', '2', '3', 'T') # the legal gyro modes

def run(*args):
"""Provide north point and SAA hiding characteristics of visits for
an LRP.

Usage:
do np_hiding [-visit=|-file=]
[-lrp=]
[-begin_time=]
[-end_time=]
[-gyro_mode=1|2|3|T]
[-orbit_file=]
[-half_width=]
[-offset=]
[-outfile=]

A visit, or a file name may be given as input. By default,
all visits in the input lrp are used. When a file is used as input,
each line of the file should contain a visit id as the first
non-whitespace on the line. Anything after the visit id on
each line will be ignored.

The -lrp defaults to the latest baselined LRP.

-begin_time defaults to the current time

-end_time defaults to the end of the current planning interval

-gyro_mode defaults to whatever the default SPSS gyro mode is (from
relation gyro_mode in the SPSS database).

-orbit_file defaults to the latest extrapolted orbit file in the SPSS database.

-half_width is the north-point half width time in days. Defaults to
8.67 days in 1 and 2 gyro mode and 7 days in 3 and T gyro mode.

-offset is the offset between the geometrical sun north point and the
exclusion zone north point. Defaults to -10 days for 1 and 2 gyro modes
and 0 for 3 and T gyro modes.

If the optional parameter -outfile= is given, all output will
go to . Otherwise output from each report will go to the
screen.

"""
allowed_options = ['outfile=', 'begin_time=', 'end_time=',
'lrp=', 'visit=', 'file=', 'gyro_mode=',
'half_width=', 'offset=', 'orbit_file=']

try:
options, parms = spst_getopt.spst_getopt(args, allowed_options)
except Exception,e:
print e
print "Illegal argument."
return not spss_sys_util.SUCCESS

if len(parms) > 0:
print "Unrecognized parameter(s):", parms
return not spss_sys_util.SUCCESS

fileName = ''
fileId = None
if options.has_key('-outfile'):
fileName = options['-outfile']
if fileName == 'stdout':
print "All output will be sent to the screen."
fileId = sys.stdout
else:
print "All output will be sent to:", fileName
fileId = open(fileName, 'w')
else:
print "All output will be sent to the screen."
fileId = sys.stdout

if options.has_key('-lrp'):
lrp = lrp_util.lrp(options['-lrp'])
else:
lrp = lrp_util.get_baselined_lrp()
fileId.write("LRP: %s\n" % lrp)

if options.has_key('-visit') and options.has_key('-file'):
print "Error -- options -visit and -file are mutually exclusive."
return not spss_sys_util.SUCCESS
elif options.has_key('-visit'):
visits = [visit_util.visit(options['-visit'])]
elif options.has_key('-file'):
visits = []
for line in open(options['-file']).readlines():
ls = line.split()
# Ignore blank lines
if ls and re.search("([0-9]{5,5})([0-9,A-Z]{2,2})", ls[0]):
try:
v=visit_util.visit(ls[0])
except:
# Ignore non-sensical visit ids
continue
visits.append(v)
if not visits:
print "Error -- Could not find visit ids in", options['-file']
return not spss_sys_util.SUCCESS
else:
# Use all the visits from the LRP
visits = lrp.get_visits()
if not visits:
print "Error -- LRP %s contains no visits." % lrp
return not spss_sys_util.SUCCESS

if options.has_key("-begin_time"):
begin_time = time_util.spss_time(options["-begin_time"])
else:
begin_time = time_util.spss_time()

if options.has_key("-end_time"):
end_time = time_util.spss_time(options["-end_time"])
else:
end_time = time_util.spss_time(lrp_util.get_default_planning_interval().endtime())

planning_interval = time_util.window(begin_time, end_time)
planning_interval_wl = time_util.window_list(planning_interval)
fileId.write("Planning interval: %s\n" % planning_interval)

if options.has_key('-gyro_mode'):
gyro_mode = options['-gyro_mode'].upper()
if gyro_mode not in GYRO_MODES:
print "Error -- Unknown gryo mode", gyro_mode
return not spss_sys_util.SUCCESS
else:
gyro_mode = spss_sys_util.get_gyro_mode()
fileId.write("Gyro mode: %s\n" % gyro_mode)

if options.has_key('-half_width'):
north_point_half_width = float(options['-half_width']) * 86400.0
elif gyro_mode in ('1', '2'):
north_point_half_width = 8.67 * 86400.0
else:
north_point_half_width = 7.0 * 86400.0
fileId.write("North point half width: %5.2f days\n" % (north_point_half_width/86400.))

if options.has_key('-offset'):
north_point_offset = float(options['-offset']) * 86400.0
elif gyro_mode in ('1', '2'):
north_point_offset = -10.0 * 86400.0
else:
north_point_offset = 0.0
fileId.write("North point offset: %5.2f days\n" % (north_point_offset/86400.))

if options.has_key('-orbit_file'):
orbit = orbit_util.orbit_file(options['-orbit_file'])
else:
orbit = orbit_util.get_latest_extrap_orbit_file()
fileId.write("Orbit file: %s\n" % orbit)

np_times = orbit.get_north_point_times(begin_time, end_time)
fileId.write("Calculated north point times: %s\n" % np_times)

np_windows = time_util.window_list([time_util.window(n + north_point_offset - north_point_half_width,
n + north_point_offset + north_point_half_width)
for n in np_times])
fileId.write("Calculated north point windows:\n%s\n" % np_windows)

fileId.write(' full part PW PW full part NP- PW-NP- SAA\n')
fileId.write(' SAA SAA start start SAA SAA SAA SAA hiding\n')
fileId.write(' earliest latest PW hide hide in SAA in NP CW hide hide hide hide PW\n')
fileId.write('SU orb PW start PW end Dur frac frac hiding? hiding? dur CW frac CW frac frac frac dur (days)\n')

for visit in visits:
pws = visit.get_plan_windows(lrp)
cws = visit.get_constraint_windows()
cws = cws.intersection(planning_interval_wl)
cw_sum = cws.get_windowlette_sum()
cw_sum_days = int(cw_sum/86400 + 0.5)
full_saa_hiding_cws = constraint_window.get_full_saa_hiding_windows(cws)
full_saa_hiding_cw_sum = full_saa_hiding_cws.get_windowlette_sum()
part_saa_hiding_cws = constraint_window.get_partial_saa_hiding_windows(cws)
part_saa_hiding_cw_sum = part_saa_hiding_cws.get_windowlette_sum()
if float(cw_sum) == 0.0:
full_saa_hiding_frac = 0.0
part_saa_hiding_frac = 0.0
else:
full_saa_hiding_frac = float(full_saa_hiding_cw_sum)/float(cw_sum)
part_saa_hiding_frac = float(part_saa_hiding_cw_sum)/float(cw_sum)
saa_hiding_cws = full_saa_hiding_cws + part_saa_hiding_cws
saa_hiding_cws_sum = saa_hiding_cws.get_windowlette_sum()
np_saa_hiding_cws = np_windows.intersection(saa_hiding_cws)
np_saa_hiding_cws_sum = np_saa_hiding_cws.get_windowlette_sum()
if float(saa_hiding_cws_sum) == 0.0:
saa_hiding_np_cw_frac = 0.0
else:
saa_hiding_np_cw_frac = float(np_saa_hiding_cws_sum)/float(saa_hiding_cws_sum)
if pws:
max_span = visit.get_pw_span(lrp)
min_pw_begin = max_span.starttime() + 30
min_pw_begin = min_pw_begin.strftime('%y.%j:%H')
max_pw_end = max_span.endtime() + 30
max_pw_end = max_pw_end.strftime('%y.%j:%H')
pw_sum = pws.get_windowlette_sum()
pw_sum_days = int(pw_sum/86400 + 0.5)
pwpfsaa = pws.intersection(full_saa_hiding_cws)
pwpfsaa_sum = pwpfsaa.get_windowlette_sum()
if float(pw_sum) == 0.0:
fully_saa_hiding_fraction = 0.0
else:
fully_saa_hiding_fraction = float(pwpfsaa_sum)/float(pw_sum)
pwppsaa = pws.intersection(part_saa_hiding_cws)
pwppsaa_sum = pwppsaa.get_windowlette_sum()
if float(pw_sum) == 0.0:
partial_saa_hiding_fraction = 0.0
else:
partial_saa_hiding_fraction = float(pwppsaa_sum)/float(pw_sum)
if full_saa_hiding_cws.contains(max_span.starttime()) or part_saa_hiding_cws.contains(max_span.starttime()):
pw_start_in_saa_hiding = 'Y'
else:
pw_start_in_saa_hiding = 'N'
if np_windows.contains(max_span.starttime()):
pw_start_in_np_hiding = 'Y'
else:
pw_start_in_np_hiding = 'N'
np_saa_hiding_cws_pw = np_saa_hiding_cws.intersection(pws)
np_saa_hiding_cws_pw_sum = np_saa_hiding_cws_pw.get_windowlette_sum()
pws_saa_hiding_cws = pws.intersection(full_saa_hiding_cws + part_saa_hiding_cws)
pws_saa_hiding_cws_sum = pws_saa_hiding_cws.get_windowlette_sum()
if float(pws_saa_hiding_cws_sum) != 0.0:
saa_np_hiding_fraction = float(np_saa_hiding_cws_pw_sum)/float(pws_saa_hiding_cws_sum)
else:
saa_np_hiding_fraction = 0.0
else:
min_pw_begin = " - "
max_pw_end = " - "
pw_sum_days = " - "
fully_saa_hiding_fraction = 0.0
partial_saa_hiding_fraction = 0.0
pw_start_in_saa_hiding = 'N'
pw_start_in_np_hiding = 'N'
saa_np_hiding_fraction = 0.0
pws_saa_hiding_cws_sum = time_util.delta_time(0.0)

fileId.write('%7s %-2s %9s %9s %3s %4.2f %4.2f %s %s %3i %4.2f %4.2f %4.2f %4.2f %6.2f\n' %
(visit['sunit_id'],
visit.get('est_orbits',0),
min_pw_begin,
max_pw_end,
pw_sum_days,
fully_saa_hiding_fraction,
partial_saa_hiding_fraction,
pw_start_in_saa_hiding,
pw_start_in_np_hiding,
cw_sum_days,
full_saa_hiding_frac,
part_saa_hiding_frac,
saa_hiding_np_cw_frac,
saa_np_hiding_fraction,
float(pws_saa_hiding_cws_sum)/86400.))

return spss_sys_util.SUCCESS



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