AutoPickParamter class modified; not working at the moment (!)

This commit is contained in:
Sebastian Wehling-Benatelli 2014-02-15 08:09:55 +01:00
parent 34c1f9111b
commit 5a093ed736

View File

@ -7,7 +7,7 @@ Created on Thu Feb 13 09:58:45 2014
"""
class AutoPickParameters(object):
class AutoPickParameter(object):
'''
AutoPickParameters is a parameter type object capable to read and/or write
parameter ASCII and binary files. Parameters are given by example:
@ -19,7 +19,7 @@ class AutoPickParameters(object):
order 4 # order_of_ar
fnoise 0 # noise_level_for_ar
suppp 7 # envelopecoeff
tolt 300 #(s)time_int_around_the_arrival_time_of_the_phase_to_analyze
tolt 300 # (s)time around arrival time
f1tpwt 4 # propfact_minfreq_secondtaper
pickwindow 9 # length_of_pick_window
w1 1 # length_of_smoothing_window
@ -38,10 +38,10 @@ class AutoPickParameters(object):
read content of an ASCII file an form a type consistent dictionary
contain all parameters.
'''
self.filename = fn
parFileCont = {}
try:
inputFile = open(fn, 'r')
inputFile = open(self.filename, 'r')
lines = inputFile.readlines()
for line in lines:
parspl = line.split('\t')[:2]
@ -62,20 +62,50 @@ class AutoPickParameters(object):
else:
val = str(value.strip())
parFileCont[key] = val
except e:
except Exception, e:
raise 'ParameterError:\n %s' % e
finally:
parFileCont = None
self.__parameter = parFileCont
def __str__(self):
pass
def __repr__(self):
reprString = ''
reprString += 'Automated picking parameter:\n\n'
string = ''
string += 'Automated picking parameter:\n\n'
if self.__parameter is not None:
for key, value in self.__parameter.iteritems():
reprString += '%s:\t\t%s' % (key, value)
string += '%s:\t\t%s' % (key, value)
else:
reprString += 'Empty parameter dictionary.'
string += 'Empty parameter dictionary.'
return string
def __repr__(self):
return 'AutoPickParameter(%s)' % self.filename
def __nonzero__(self):
return self.__parameter
def getParam(self, *args):
try:
for param in args:
try:
return self.__parameter[param]
except KeyError, e:
raise 'ParameterError:\n %s' % e
except TypeError:
try:
return self.__parameter[param]
except KeyError, e:
raise 'ParameterError:\n %s' % e
def setParam(self, **kwargs):
for param, value in kwargs:
try:
self.__parameter[param] = value
except KeyError, e:
raise 'ParameterError:\n %s' % e
finally:
self.__str__()
class ParameterError(Exception):
pass