From 5a093ed736e48b90f18d9d06fb1959a6194fc905 Mon Sep 17 00:00:00 2001 From: Sebastian Wehling-Benatelli Date: Sat, 15 Feb 2014 08:09:55 +0100 Subject: [PATCH] AutoPickParamter class modified; not working at the moment (!) --- pylot/core/readinput/types.py | 88 +++++++++++++++++++++++------------ 1 file changed, 59 insertions(+), 29 deletions(-) diff --git a/pylot/core/readinput/types.py b/pylot/core/readinput/types.py index 6c426472..65dbecf6 100644 --- a/pylot/core/readinput/types.py +++ b/pylot/core/readinput/types.py @@ -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 parameter ASCII and binary files. Parameters are given by example: - phl S #phaselabel - ff1 0.1 #freqmin - ff2 0.5 #freqmax - tdet 6.875 #det-window_(s)_for_ar - tpred 2.5 #pred-window_(s)_for_ar - 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 - f1tpwt 4 #propfact_minfreq_secondtaper - pickwindow 9 #length_of_pick_window - w1 1 #length_of_smoothing_window - w2 0.37 #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 - aerr 30;60 #adjusted_error_slope_fitting_loc_glob - tsn 20;5;20;10 #length_signal_window_S/N - proPh Sn #nextprominentphase + phl S # phaselabel + ff1 0.1 # freqmin + ff2 0.5 # freqmax + tdet 6.875 # det-window_(s)_for_ar + tpred 2.5 # pred-window_(s)_for_ar + order 4 # order_of_ar + fnoise 0 # noise_level_for_ar + suppp 7 # envelopecoeff + tolt 300 # (s)time around arrival time + f1tpwt 4 # propfact_minfreq_secondtaper + pickwindow 9 # length_of_pick_window + w1 1 # length_of_smoothing_window + w2 0.37 # 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 + aerr 30;60 # adjusted_error_slope_fitting_loc_glob + tsn 20;5;20;10 # length_signal_window_S/N + proPh Sn # nextprominentphase ''' def __init__(self, fn): @@ -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