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

Поисковые слова: http astrokuban.info astrokuban
#
#MODULE pn_switches
#
#*****************************************************************************
"""

**PURPOSE** --
Switch to PN telemetry format around SAA passages for monitoring of
magnitometer problems.

**DEVELOPER** --
Don Chance

**REQUIREMENTS** --
o Each switch to/from PN must not be closer than 2 minutes to the
start of a slew or the end of FGS visibility.
o The switch to HN on the way out of an SAA may not be closer than
1 minute to the start of the guide star acquisition.
o The switch to PN on the way into an SAA must be after the end of
any main science. The switch to PN should be at the end of the main
science or 5 minutes before the SAA entry, which ever is later.
o If the time in PN format will less than 3 minutes, don't do the
switch to PN.
o No more than 3 hours in PN are allowed without at least 10 minutes
in HN.

**MODIFICATION HISTORY** --
Initial implementation 3/14/01
Must switch back to HN after an SAA when there is no GSACQ. drc 5/9/01

"""
#*****************************************************************************
import spss_sys_util, calendar_util, ccl_util, string

SAA_MODEL = '02'
PN_MIN_TIME = 180.0
SWITCH_PAD = 120.0
GS_PAD = 60.0
PN_MAX_TIME = 10800.0
HN_MIN_TIME = 600.0
CAL_BEGIN_PAD = 1200.0
CAL_END_PAD = 1800.0
SAA_PAD = 300.0
SU_DURATION = 61.0

def pcpterm_check(time, direction, fgsoccs, slews):
"""Define function to check that a given time is not too close to
an FGS occultation or beginning of a slew."""
made_adjustment = 0
for fgsocc in fgsoccs:
if time - SWITCH_PAD < fgsocc['begin_time'] < time + SWITCH_PAD:
time = fgsocc['begin_time'] + direction*SWITCH_PAD
made_adjustment = 1
for slew in slews:
if time - SWITCH_PAD < slew['begin_time'] < time + SWITCH_PAD:
time = slew['begin_time'] + direction*SWITCH_PAD
made_adjustment = 1
if made_adjustment:
time = pcpterm_check(time, direction, fgsoccs, slews)
return time



def run(cal_name=None):
"""Create a calendar -add file for SUs to switch to PN around SAA passages.

Usage:
do pn_swtiches

A calendar name is required.

Note: This tool will overwrite your map files.

"""

if not cal_name:
# Spew out the usage and quit when no parameters
# are provided.
print run.__doc__
return spss_sys_util.SUCCESS

calendar = ccl_util.ccl(cal_name)
calendar.get()
display = calendar_util.cal_display()

# Get all the activities we'll need...
saas = display.get_saa_list(SAA_MODEL)
mains = display.get_main_sci_list()
slews = display.get_slew_list()
fgsacqs = display.get_fgs_acq_list()
fgsoccs = display.parse_calendar_display('calendar -display -slew_fgs',
'F/S_OCC')
calbegin = calendar.get_begin_time()
calend = calendar.get_end_time()

last_hn_time = calbegin
total_pn_time = 0

add_file_name = string.lower(calendar.get_name()) + '_tlm.add'
sus_file_name = string.lower(calendar.get_name()) + '_tlm.sus'
add_file = open(add_file_name, 'w')
sus_file = open(sus_file_name, 'w')

pnprop = 'TLMPN'
hnprop = 'TLMHN'

b36 ='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'

su_count = 1

# Loop through all the SAAs
for saa in saas:
# Skip SAAs at the start or end of the calendar
if ((saa['begin_time'] <= (calbegin + CAL_BEGIN_PAD)) or
(saa['end_time'] >= (calend - CAL_END_PAD))):
continue

# Find the last main science to start before this SAA
last_main = {'begin_time': calbegin + CAL_BEGIN_PAD,
'end_time': calbegin + CAL_BEGIN_PAD}
for main in mains:
if main['begin_time'] <= saa['begin_time']:
last_main = main
else:
break

# If the last main science before the SAA continues beyond the SAA,
# skip to the next SAA.
if saa['end_time'] <= last_main['end_time']:
continue

# Switch to PN at the end of the main science or right before the
# SAA, whichever is later.
pn_time = max(last_main['end_time'], saa['begin_time'] - SAA_PAD)

# Move the switch to PN away from the end of FGS visibility
# or the start of a slew.
pn_time = pcpterm_check(pn_time, 1, fgsoccs, slews)

# Find the first GS acq after the SAA (or the end of the calendar).
first_acq = {'begin_time': calend - CAL_END_PAD,
'end_time': calend - CAL_END_PAD}
for fgsacq in fgsacqs:
if fgsacq['begin_time'] >= saa['begin_time']:
first_acq = fgsacq
break

# Switch to HN before the start of the acq, or the end of the calendar
# or SAA_PAD after the end of the SAA, whichever is sooner.
hn_time = min(first_acq['begin_time'] - GS_PAD,
saa['end_time'] + SAA_PAD)

# Move the switch to HN away from the end of FGS visiblity
# or the start of a slew.
hn_time = pcpterm_check(hn_time, -1, fgsoccs, slews)

# If the time in PN is too small, skip it.
if hn_time - pn_time < PN_MIN_TIME:
continue

# Make sure we don't stay in PN too long.
if pn_time - last_hn_time < HN_MIN_TIME:
total_pn_time = total_pn_time + (hn_time - last_hn_time)
else:
total_pn_time = hn_time - pn_time
last_hn_time = hn_time

if total_pn_time >= PN_MAX_TIME:
print ">>> WARNING <<< Too much time in PN format!"
print "Last HN time", hn_time

# Determine the SU id to use and put them into the SUs and add files
su = b36[su_count/36] + b36[su_count%36]

sus_file.write(pnprop + su + ':01\n')
sus_file.write(hnprop + su + ':01\n')
add_file.write('calendar -add -ctype=p ' + pnprop + su +
' NONE,,,' + str(pn_time) + ',' +
str(pn_time + SU_DURATION) + ',A\n')
add_file.write('calendar -add -ctype=p ' + hnprop + su +
' NONE,,,' + str(hn_time) + ',' +
str(hn_time + SU_DURATION) + ',A\n')

su_count = su_count + 1

add_file.close()
sus_file.close()

print "SUs to add to the candlist written to file", sus_file_name
print "Calendar add commands written to file", add_file_name

status, text = spss_sys_util.command("candlist -add %" + sus_file_name, 1)
if status != spss_sys_util.SUCCESS:
raise RuntimeError("candlist -add failed")
status, text = spss_sys_util.command("calendar -file " + add_file_name, 1)
if status != spss_sys_util.SUCCESS:
print ">>> calendar -file returned a non-success status. Check that"
print ">>> all format switch SUs added."

# Find a unique temporary calendar name and save the cclist
# to that name
new_name = calendar.get_name()[:5] + 'PN'
i=0
temp_cal = ccl_util.ccl(new_name + b36[i])
while temp_cal.exists():
i = i + 1
temp_cal = ccl_util.ccl(new_name + b36[i])

new_cal = temp_cal.save(temp_cal.get_name())

print "New calendar with PN/HN format switches saved to", new_cal.get_name()


# Run from command line
if __name__ == '__main__':
import sys
if len(sys.argv) > 1:
run(sys.argv[1])
else:
run()