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,28 +7,28 @@ 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 AutoPickParameters is a parameter type object capable to read and/or write
parameter ASCII and binary files. Parameters are given by example: parameter ASCII and binary files. Parameters are given by example:
phl S #phaselabel phl S # phaselabel
ff1 0.1 #freqmin ff1 0.1 # freqmin
ff2 0.5 #freqmax ff2 0.5 # freqmax
tdet 6.875 #det-window_(s)_for_ar tdet 6.875 # det-window_(s)_for_ar
tpred 2.5 #pred-window_(s)_for_ar tpred 2.5 # pred-window_(s)_for_ar
order 4 #order_of_ar order 4 # order_of_ar
fnoise 0 #noise_level_for_ar fnoise 0 # noise_level_for_ar
suppp 7 #envelopecoeff 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 f1tpwt 4 # propfact_minfreq_secondtaper
pickwindow 9 #length_of_pick_window pickwindow 9 # length_of_pick_window
w1 1 #length_of_smoothing_window w1 1 # length_of_smoothing_window
w2 0.37 #cf(i-1)*(1+peps)_for_local_min w2 0.37 # cf(i-1)*(1+peps)_for_local_min
w3 0.25 #cf(i-1)*(1+peps)_for_local_min w3 0.25 # cf(i-1)*(1+peps)_for_local_min
tslope 0.8;2 #slope_det_window_loc_glob tslope 0.8;2 # slope_det_window_loc_glob
aerr 30;60 #adjusted_error_slope_fitting_loc_glob aerr 30;60 # adjusted_error_slope_fitting_loc_glob
tsn 20;5;20;10 #length_signal_window_S/N tsn 20;5;20;10 # length_signal_window_S/N
proPh Sn #nextprominentphase proPh Sn # nextprominentphase
''' '''
def __init__(self, fn): def __init__(self, fn):
@ -38,10 +38,10 @@ class AutoPickParameters(object):
read content of an ASCII file an form a type consistent dictionary read content of an ASCII file an form a type consistent dictionary
contain all parameters. contain all parameters.
''' '''
self.filename = fn
parFileCont = {} parFileCont = {}
try: try:
inputFile = open(fn, 'r') inputFile = open(self.filename, 'r')
lines = inputFile.readlines() lines = inputFile.readlines()
for line in lines: for line in lines:
parspl = line.split('\t')[:2] parspl = line.split('\t')[:2]
@ -62,20 +62,50 @@ class AutoPickParameters(object):
else: else:
val = str(value.strip()) val = str(value.strip())
parFileCont[key] = val parFileCont[key] = val
except e: except Exception, e:
raise 'ParameterError:\n %s' % e raise 'ParameterError:\n %s' % e
finally: finally:
parFileCont = None parFileCont = None
self.__parameter = parFileCont self.__parameter = parFileCont
def __str__(self): def __str__(self):
pass string = ''
string += 'Automated picking parameter:\n\n'
def __repr__(self):
reprString = ''
reprString += 'Automated picking parameter:\n\n'
if self.__parameter is not None: if self.__parameter is not None:
for key, value in self.__parameter.iteritems(): for key, value in self.__parameter.iteritems():
reprString += '%s:\t\t%s' % (key, value) string += '%s:\t\t%s' % (key, value)
else: 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