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

Поисковые слова: п п п п п п п п п п п п р п р п р п р п р п р п р п
#
#MODULE create_contacts
#
#***********************************************************************
"""

**PURPOSE** --
Run the PASS AVTUT tool.

**DEVELOPER** --
Don Chance

**MODIFICATION HISTORY** --
Initial implementation 9/9/08
Modified for PASS build 33.30 3/30/09
Allow for user input tdrs.dat file. 5/7/09
Add namelist editing through GUI. drc 6/10/09
Update for PASS build 33.40. drc 9/24/09
Modified to support anal_views run with MS generation. drc 10/15/09
Updated for PASS build 33.80. drc 2/14/11
Updated for PASS build 33.92. drc 11/14/13
Updated for PASS build 33.95. drc 5/8/14
"""
#***********************************************************************
from pass_product import pass_product
import os
import time_util
import pass_util
import configure_util
import get_web_tut
import spss_sys_util
import spst_getopt
import namelist_util
import sys
HAS_GUI = False
# must have at least Python version 2.5 to use GUI
if sys.hexversion >= 33882352:
try:
import avtut_namelist_editor
HAS_GUI = True
except:
pass

__version__ = "14.05.08"

class avtut(pass_product):
"""A class for the AVTUT tool.
"""
def __init__(self, ms=None, tut_file='', tdrs_dat=None):
"""The input parameters are an ms object and the last
corresponding cl object.
"""
pass_product.__init__(self,'avtut')
self.ms = None
if ms:
self.ms = ms
self.input_directory = os.getcwd()
if self.ms:
self.output_directory = os.path.join(os.path.dirname(os.path.dirname(self.ms.get_output_directory())),
'avtut',
os.path.basename(self.ms.get_output_directory()),
self.run_time.strftime('%Y_%j-%H-%M-%S'))
else:
self.output_directory = self.input_directory
if not os.path.isdir(self.output_directory):
os.makedirs(self.output_directory)
self.namelist_path = os.path.join(self.output_directory, 'avtut_input.nml')
self.tut_file_path = tut_file
# tdrs_dat should be the path to a tdrs.dat file or None is you want to use
# the same tdrs.dat file as the PASS MS/CL run.
if tdrs_dat is not None:
self.tdrs_dat = os.path.abspath(tdrs_dat)
else:
self.tdrs_dat = tdrs_dat
if self.ms and not self.ms.get_output_file('aet'):
raise ValueError('No .aet file found in ' + self.ms.get_output_directory())
if self.ms:
self.ism_file = self.ms.get_output_file('ism')[0]
self.aet_file = self.ms.get_output_file('aet')[0]
self.oev_file = self.ms.get_output_file('oev')[0]
self.ms_basefile_path = self.ms.get_basefile().get_namelist_path()
self.ms_config_file_path = self.ms.get_config_file()
self.run_name = self.ms.get_run_name()
self.ms_cin_file_path = self.ms.get_cin_file().get_namelist_path()
self.top_level = False
self.generic_namelist = None

def get_tut_file_path(self):
return self.tut_file_path

def set_tut_file_path(self, tut_file_path):
self.tut_file_path = tut_file_path

def set_aet_file(self, aet_file):
self.aet_file = aet_file

def get_aet_file(self):
return self.aet_file

def set_ism_file(self, ism_file):
self.ism_file = ism_file

def get_ism_file(self):
return self.ism_file

def set_oev_file(self, oev_file):
self.oev_file = oev_file

def get_oev_file(self):
return self.oev_file

def get_cin_file(self):
if not hasattr(self, 'ms_cin_file_path'):
self.ms_cin_file_path = self.ms.get_cin_file().get_namelist_path()
return self.ms_cin_file_path

def create_script(self):
"""Create the script to run AVTUT
"""
self.script_obj = pass_util.pass_script('avtut', self.software_version)
self.script_obj.set_top_level(self.get_top_level())
self.script_obj.source_file(self.ms_config_file_path)

# Input: SCHF and TDRS schedule files
self.script_obj.add_environment_definition('TUT_SCHF_ODB', '$CFG_SCHFODB')
if self.tdrs_dat is None:
self.script_obj.add_environment_definition('TUT_TDRS_SCHED', '$CFG_TDRSSCHD')
else:
self.script_obj.add_environment_definition('TUT_TDRS_SCHED', self.tdrs_dat)

# Input: MS basefile
self.script_obj.add_environment_definition('TUT_MS_BAS', self.ms_basefile_path)

# Input: TUT file
self.script_obj.add_environment_definition('TUT_FILE', self.tut_file_path)

# Input: TUT namelist
self.script_obj.add_environment_definition('TUT_IN_NML', self.namelist_path)

# Input: AET file
self.script_obj.add_environment_definition('AET_FILE', self.aet_file)

# Input: ISM file
self.script_obj.add_environment_definition('TUT_MS_ISM', self.ism_file)

# Input: MS CIN file
self.script_obj.add_environment_definition('TUT_MS_CIN', self.get_cin_file())

# Input: OEV file (orbital events file)
self.script_obj.add_environment_definition('TUT_OEV_FILE', self.oev_file)

# Output files
self.script_obj.add_environment_definition('ANA_VIEWS',
os.path.join(self.output_directory, 'av_views.rpt'))
self.script_obj.add_environment_definition('ANA_BLOCKAGES',
os.path.join(self.output_directory, 'av_blockages.rpt'))
self.script_obj.add_environment_definition('ANA_DEBUG',
os.path.join(self.output_directory, 'av_views.dbg'))
self.script_obj.add_environment_definition('TUT_SUM_FILE',
os.path.join(self.output_directory, 'tut_summary.rpt'))
self.script_obj.add_environment_definition('TUT_DBG_FILE',
os.path.join(self.output_directory, 'tut_debug.dbg'))
self.script_obj.add_environment_definition('TUT_OUT_SSR',
os.path.join(self.output_directory, 'tut.ssr'))
self.script_obj.add_environment_definition('TUT_SSR_SUM',
os.path.join(self.output_directory, 'ssr_summary.rpt'))
self.script_obj.add_environment_definition('TUT_EVT_PLOT',
os.path.join(self.output_directory, 'tut_evt_plot.dat'))
self.script_obj.add_environment_definition('TUT_TDRS_PLOT',
os.path.join(self.output_directory, 'tut_tdrs_plot.dat'))
self.script_obj.add_environment_definition('AVTUT_LOG',
os.path.join(self.output_directory, 'avtut.log'))
self.script_obj.add_environment_definition('HGA_TRK_RPT',
os.path.join(self.output_directory, 'hga_track.rpt'))
self.script_obj.add_environment_definition('TUT_TRK_RPT',
os.path.join(self.output_directory, 'tut_track.rpt'))

self.script_obj.append_line('cat $AVTUT_LOG')
self.script_obj.append_line('cat -s $TUT_SUM_FILE')

self.script_created = 1

self.script_obj.set_script_path(os.path.join(self.output_directory,
"avtut_script.csh"))
self.script_obj.set_logpath(os.path.join(self.output_directory,
"avtut_script.log"))
self.script_obj.set_jobname("AVTUT")
return

def create_namelist(self):
"""Create the namelist necessary for running the AVTUT program.

Returns the path to the namelist.
"""
if not self.generic_namelist:
if not self.namelist_template:
self.generic_namelist = namelist_util.namelist(pass_util.get_pass_namelist_path('avtut.nml',
self.software_version))
else:
self.generic_namelist = namelist_util.namelist(pass_util.get_pass_namelist_path(self.namelist_template,
self.software_version))

self.generic_namelist.write_namelist(self.namelist_path)
return self.namelist_path

def get_namelist(self):
return self.namelist_path

def get_span(self):
"""Get time span of run sms.
"""
return self.ms.get_span()

def set_top_level(self, bool):
if bool:
self.top_level = True
else:
self.top_level = False

def get_top_level(self):
if hasattr(self, 'top_level'):
return self.top_level
else:
return False

def run(*args):
"""Run AVTUT

Usage:
do create_contacts [-namelist= [-software_version=old|ops|new]
[-tdrs=tde,tdw,...]
[-tut_file=]
[-sched=]
[-gui]

If -tut_file is given, this TUT file will be used. Otherwise, get_web_tut.py will be used
to get a TUT file. The -tdrs option is passed along to get_web_tut. If a tut file is
provided, then -tdrs has no effect. Use -namelist to specify an AVTUT namelist. Otherwise,
the appropriate default namelist from the PASS software area will be used.

Use -sched option to specify the path to a tdrs.dat file. Otherwise the same tdrs.dat file
will be used as the MS run.

Use -gui to start the AVTUT GUI for editing AVTUT namelist parameters.
"""

#if not ms_name:
# print run.__doc__
# return spss_sys_util.SUCCESS

allowed_options = ['namelist=',
'software_version=',
'tdrs=',
'tut_file=',
'sched=',
'gui']

options, parms = spst_getopt.spst_getopt(args, allowed_options)

if '-software_version' in options.keys():
sw_version = options['-software_version'].lower()
else:
sw_version = 'ops'

if '-namelist' in options.keys():
namelist_path = options['-namelist']
else:
namelist_path = None

if '-tdrs' in options.keys():
tdrss = options['-tdrs']
else:
tdrss = ''

if '-tut_file' in options.keys():
tut_file = options['-tut_file']
else:
tut_file = ''

if parms:
ms_name = parms[0]
else:
ms_name = ''

if '-sched' in options.keys():
tdrs_dat = options['-sched']
else:
tdrs_dat = None

if '-gui' in options.keys() and HAS_GUI:
use_gui = True
elif '-gui' in options.keys() and not HAS_GUI:
print "GUI option specified, but no GUI available!"
use_gui = False
else:
use_gui = False


path = spss_sys_util.resolver('PASS_OUTPUT_PICKLES')
lib = configure_util.pickle_library_list(path)
pickle_list = lib.get_pickle_list().filter('mscl', ms_name.lower())
pickle_list.sort()

mscl=configure_util.get_pickled_object(pickle_list.pick_a_pickle())

# Check to see if there is an AET file in the MS output directory.
ms = mscl.my_ms
aet_files = ms.get_output_file('aet')
if not aet_files:
raise ValueError( "No .aet file found in MS output directory: %s" % ms.get_output_directory())

# Check to see if there is an ISM file in the MS output directory.
ism_files = ms.get_output_file('ism')
if not ism_files:
raise ValueError( "No .ism file found in MS output directory: %s" % ms.get_output_directory())

oev_files = ms.get_output_file('oev')
if not oev_files:
raise ValueError( "No .oev file found in MS output directory: %s" % ms.get_output_directory())

av_tut = avtut(ms, tdrs_dat=tdrs_dat)
av_tut.set_software_version(sw_version)
if namelist_path:
av_tut.set_namelist_template(os.path.abspath(namelist_path))
if use_gui:
avtut_namelist_editor.gui(av_tut)
if not av_tut.generic_namelist:
av_tut.create_namelist()
else:
av_tut.create_namelist()
av_tut.set_aet_file(aet_files[0])
av_tut.set_ism_file(ism_files[0])
av_tut.set_oev_file(oev_files[0])

if (not tut_file and
(av_tut.generic_namelist['TTNTUTNML']['UPDATE_TDRS_SCHED'] == ['.TRUE.'] or
av_tut.generic_namelist['TTNTUTNML']['HGA_TRACK_REPORT'] == ["'YES_TUT'"])):
# Construct inputs to get_web_tut
tutname = 'tut_' + av_tut.get_run_time().strftime('%Y_%j-%H-%M-%S') + ".tut"
tut_file = os.path.join(av_tut.get_output_directory(), tutname)
get_web_tut_args = ['-outfile=' + tut_file]
if tdrss:
get_web_tut_args.append('-tdrs=' + tdrss)
process_times = av_tut.generic_namelist.get_value('TTNTUTNML','SELECT_TIME')
begin_time = process_times[0].strip("'").strip()
end_time = process_times[1].strip("'").strip()
if begin_time:
get_web_tut_args.append("-start="+str(time_util.spss_time(begin_time)))
if end_time:
get_web_tut_args.append("-end="+str(time_util.spss_time(end_time)))
# Use get_web_tut to create a TUT file
print "Getting TUT file..."
print "get_web_tut arguments: ", get_web_tut_args
get_web_tut.run(*tuple(get_web_tut_args))

av_tut.set_tut_file_path(tut_file)

status, output = av_tut.run()
print output

print "Output sent to", av_tut.get_output_directory()

return spss_sys_util.SUCCESS


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