class AutoPickParameter is now working; work on ticket #119 not finished yet (closure pending)
This commit is contained in:
parent
5a093ed736
commit
f9d8173b2f
@ -10,7 +10,10 @@ Created on Thu Feb 13 09:58:45 2014
|
|||||||
class AutoPickParameter(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 for example as follows:
|
||||||
|
|
||||||
phl S # phaselabel
|
phl S # phaselabel
|
||||||
ff1 0.1 # freqmin
|
ff1 0.1 # freqmin
|
||||||
ff2 0.5 # freqmax
|
ff2 0.5 # freqmax
|
||||||
@ -31,7 +34,7 @@ class AutoPickParameter(object):
|
|||||||
proPh Sn # nextprominentphase
|
proPh Sn # nextprominentphase
|
||||||
'''
|
'''
|
||||||
|
|
||||||
def __init__(self, fn):
|
def __init__(self, fn=None):
|
||||||
'''
|
'''
|
||||||
Initialize parameter object:
|
Initialize parameter object:
|
||||||
|
|
||||||
@ -41,11 +44,12 @@ class AutoPickParameter(object):
|
|||||||
self.filename = fn
|
self.filename = fn
|
||||||
parFileCont = {}
|
parFileCont = {}
|
||||||
try:
|
try:
|
||||||
|
if self.filename is not None:
|
||||||
inputFile = open(self.filename, '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]
|
||||||
parFileCont[parspl[0]] = parspl[1]
|
parFileCont[parspl[0].strip()] = parspl[1]
|
||||||
for key, value in parFileCont.iteritems():
|
for key, value in parFileCont.iteritems():
|
||||||
try:
|
try:
|
||||||
val = int(value)
|
val = int(value)
|
||||||
@ -62,24 +66,25 @@ class AutoPickParameter(object):
|
|||||||
else:
|
else:
|
||||||
val = str(value.strip())
|
val = str(value.strip())
|
||||||
parFileCont[key] = val
|
parFileCont[key] = val
|
||||||
|
else:
|
||||||
|
parFileCont = {}
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
raise 'ParameterError:\n %s' % e
|
self._printParameterError(e)
|
||||||
finally:
|
parFileCont = {}
|
||||||
parFileCont = None
|
|
||||||
self.__parameter = parFileCont
|
self.__parameter = parFileCont
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
string = ''
|
string = ''
|
||||||
string += 'Automated picking parameter:\n\n'
|
string += 'Automated picking parameter:\n\n'
|
||||||
if self.__parameter is not None:
|
if self.__parameter:
|
||||||
for key, value in self.__parameter.iteritems():
|
for key, value in self.__parameter.iteritems():
|
||||||
string += '%s:\t\t%s' % (key, value)
|
string += '%s:\t\t%s\n' % (key, value)
|
||||||
else:
|
else:
|
||||||
string += 'Empty parameter dictionary.'
|
string += 'Empty parameter dictionary.'
|
||||||
return string
|
return string
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return 'AutoPickParameter(%s)' % self.filename
|
return "AutoPickParameter('%s')" % self.filename
|
||||||
|
|
||||||
def __nonzero__(self):
|
def __nonzero__(self):
|
||||||
return self.__parameter
|
return self.__parameter
|
||||||
@ -90,22 +95,21 @@ class AutoPickParameter(object):
|
|||||||
try:
|
try:
|
||||||
return self.__parameter[param]
|
return self.__parameter[param]
|
||||||
except KeyError, e:
|
except KeyError, e:
|
||||||
raise 'ParameterError:\n %s' % e
|
self._printParameterError(e)
|
||||||
except TypeError:
|
except TypeError:
|
||||||
try:
|
try:
|
||||||
return self.__parameter[param]
|
return self.__parameter[args]
|
||||||
except KeyError, e:
|
except KeyError, e:
|
||||||
raise 'ParameterError:\n %s' % e
|
self._printParameterError(e)
|
||||||
|
|
||||||
def setParam(self, **kwargs):
|
def setParam(self, **kwargs):
|
||||||
for param, value in kwargs:
|
for param, value in kwargs.iteritems():
|
||||||
try:
|
try:
|
||||||
self.__parameter[param] = value
|
self.__parameter[param] = value
|
||||||
except KeyError, e:
|
except KeyError, e:
|
||||||
raise 'ParameterError:\n %s' % e
|
self._printParameterError(e)
|
||||||
finally:
|
finally:
|
||||||
self.__str__()
|
print self
|
||||||
|
|
||||||
|
def _printParameterError(self, errmsg):
|
||||||
class ParameterError(Exception):
|
print 'ParameterError:\n non-existent parameter %s' % errmsg
|
||||||
pass
|
|
||||||
|
Loading…
Reference in New Issue
Block a user