Документ взят из кэша поисковой машины. Адрес оригинального документа : http://www.stsci.edu/spst/UnixTransition/doc/set_filter_pos.py
Дата изменения: Fri Feb 28 14:46:11 2014
Дата индексирования: Sat Mar 1 17:13:53 2014
Кодировка:
# MODULE set_filter_pos
#
#******************************************************************************
"""Sets the appropriate guide star filter position for the specified obset_id
in the database based upon the FGS and Magnitude.

TITLE: set_filter_pos.py
DEVELOPER: Merle Reinhart, 14-Jun-2000

PURPOSE: To set the guide star filter position in the database relation
wguide_stars.

MOD HISTORY:
- Rework to support clear filter guiding - mdr 1/20/14
"""
#******************************************************************************

__version__ = "01/20/14"

def run (*args):
"""Sets the guide star filter for the provided obset based upon the
FGS and Magnitude.

Usage:
do set_filter_pos [-setfilter|-resetfilter] [-fgs1=]
[-fgs2=] [-fgs3=]
where is either a comma separated list of obsets
in ppppp:oo:vv format or a filename that
contains a list of obsets in ppppp:oo:vv
format with one obset per record. To
indicate a file input, this parameter must
start with either a ~ (VMS) or a % (Unix).

-setfilter will set the appropriate filter if
it is currently not set in the database.
The default is -setfilter.

-resetfilter will set the appropriate filter
regardless of the current db setting.
-setfilter and -resetfilter are mutially
exclusive

-fgs1= Allows the default magnitude where FGS1
will switch from PUPIL to CLEAR guiding.
Default is env var FGS1_CLR_SWITCH_MAG

-fgs2= Allows the default magnitude where FGS2
will switch from PUPIL to CLEAR guiding.
Default is env var FGS2_CLR_SWITCH_MAG

-fgs3= Allows the default magnitude where FGS3
will switch from PUPIL to CLEAR guiding.
Default is env var FGS3_CLR_SWITCH_MAG

"""

import os, string, errno
import stpydb, spss_sys_util, obset_util, spst_getopt

file_indicator = spss_sys_util.get_file_indicator()
clear_filter = 'CLR'
pupil_filter = 'APS'

# Get the default switch magnitudes
# Equal to or fainter requires the CLEAR filter
fgs_mag = {'1':spss_sys_util.get_environ_variable("FGS1_FL_CLR_SWITCH_MAG")[0], \
'2':spss_sys_util.get_environ_variable("FGS2_FL_CLR_SWITCH_MAG")[0], \
'3':spss_sys_util.get_environ_variable("FGS3_FL_CLR_SWITCH_MAG")[0]}

allowed_options = ['setfilter','resetfilter','fgs1=','fgs2=','fgs3=']
options, parms = spst_getopt.spst_getopt(args, allowed_options)

# Check for a valid input_data parameter
if (not parms):
print run.__doc__
raise IOError('You must enter an obset or file of obsets')
else:
input_data = parms[0]
# end if

input_data = string.strip(input_data)

# See if input_data is a file input or obset id
if (input_data[0:1] == file_indicator):
file_name = input_data[1:]
if (not os.path.exists(file_name)):
raise IOError(errno.ENOENT,os.strerror(errno.ENOENT),file_name)
# end if

# open the file and read in all the obsets
obs_file = open(file_name, 'r')
obsets = []
record = '#'
while (record != ''):
record = string.strip(obs_file.readline())
if (record == ''):
continue
# end if
obsid = string.upper(record)
obsets.append(str(obset_util.obset(obsid)))
# end while
obs_file.close()
else:
obsets = []
obsid = string.split(string.upper(string.strip(input_data)),',')
for i in obsid:
obsets.append(str(obset_util.obset(i)))
# end for i
# end if

# Check for -setfilter|-resetfilter
set_filter = 0
if (options.has_key('-setfilter')):
set_filter = 1
# end if

reset_filter = 0
if (options.has_key('-resetfilter')):
reset_filter = 1
#end if

if (set_filter and reset_filter):
raise IOError("-setflter and -resetfilter may not both be sepecified")
# end if

if (reset_filter):
set_filter = 0
else:
# Default setting
set_filter = 1
# end if

# Check for magnitude overrides
if (options.has_key('-fgs1')):
fgs_mag['1'] = options['-fgs1']
# end if

if (options.has_key('-fgs2')):
fgs_mag['2'] = options['-fgs2']
# end if

if (options.has_key('-fgs3')):
fgs_mag['3'] = options['-fgs3']
# end if
print "FGS Fine-Lock Filter Switch Mag: ", fgs_mag

x = stpydb.stpydb(dbmsName=spss_sys_util.get_environ_variable('SPSS_DB')[0])

for obs_id in obsets:
proposal_id, obset_id, version_num = string.split(obs_id, ':')
total_rowcount = 0

# Loop through each FGS
for fgs_id in ('1','2','3'):
#Loop through the filters
for filt_pos in (pupil_filter,clear_filter):
x.query('update wguide_stars')
x.query(' set filter_pos = @filt')
x.query(' where proposal_id = @prop')
x.query(' and obset_id = @obs')
x.query(' and version_num = @ver')
x.query(' and fgs_id = @fgs')
if (filt_pos == pupil_filter):
x.query(' and magnitude < @mag')
else:
x.query(' and magnitude >= @mag')
# end if
if (set_filter):
x.query(' and filter_pos = ""')
# end if
x.setParam('prop', proposal_id)
x.setParam('obs', obset_id)
x.setParam('ver', version_num)
x.setParam('filt', filt_pos)
x.setParam('fgs', fgs_id)
x.setParam('mag', float(fgs_mag[fgs_id]))

print 'Working on obset: %s:%s:%s, FGS%s, Filter:%s' % \
(proposal_id, obset_id, version_num, fgs_id, filt_pos)

x.executeUpdate()
rowcount = x.getRowcount()
print ' %4i rows affected' % rowcount
total_rowcount += rowcount
# end for filt_pos
# end for fgs_id
print ' %4i total rows affected\n' % total_rowcount
# end for i

return
# end def run




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