[edit] inserted verbosity option to control the amount of output

This commit is contained in:
Sebastian Wehling-Benatelli 2016-05-20 09:58:10 +02:00
parent 9b7db91037
commit 54b557930f
3 changed files with 29 additions and 13 deletions

View File

@ -36,7 +36,7 @@ class AutoPickParameter(object):
========== ========== ======================================= ========== ========== =======================================
''' '''
def __init__(self, fnin=None, fnout=None, **kwargs): def __init__(self, fnin=None, fnout=None, verbosity=0, **kwargs):
''' '''
Initialize parameter object: Initialize parameter object:
@ -60,7 +60,8 @@ class AutoPickParameter(object):
parspl = line.split('\t')[:2] parspl = line.split('\t')[:2]
parFileCont[parspl[0].strip()] = parspl[1] parFileCont[parspl[0].strip()] = parspl[1]
except IndexError as e: except IndexError as e:
self._printParameterError(e) if verbosity > 0:
self._printParameterError(e)
inputFile.seek(0) inputFile.seek(0)
lines = inputFile.readlines() lines = inputFile.readlines()
for line in lines: for line in lines:

View File

@ -262,18 +262,23 @@ def picks_from_picksdict(picks):
else: else:
pick.polarity = 'undecidable' pick.polarity = 'undecidable'
except KeyError as e: except KeyError as e:
print(e.message, 'No polarity information found for %s' % phase) if 'fm' in e.message: # no polarity information found for this phase
pass
else:
raise e
picks_list.append(pick) picks_list.append(pick)
return picks_list return picks_list
def reassess_pilot_db(root_dir, out_dir=None, fn_param=None): def reassess_pilot_db(root_dir, out_dir=None, fn_param=None, verbosity=0):
import glob import glob
evt_list = glob.glob1(root_dir,'e????.???.??') evt_list = glob.glob1(root_dir,'e????.???.??')
for evt in evt_list: for evt in evt_list:
reassess_pilot_event(root_dir, evt, out_dir, fn_param) if verbosity > 0:
print('Reassessing event {0}'.format(evt))
reassess_pilot_event(root_dir, evt, out_dir, fn_param, verbosity)
@ -287,15 +292,17 @@ def reassess_pilot_event(root_dir, event_id, out_dir=None, fn_param=None, verbos
import pylot.core.util.defaults as defaults import pylot.core.util.defaults as defaults
fn_param = defaults.AUTOMATIC_DEFAULTS fn_param = defaults.AUTOMATIC_DEFAULTS
default = AutoPickParameter(fn_param) default = AutoPickParameter(fn_param, verbosity)
search_base = os.path.join(root_dir, event_id) search_base = os.path.join(root_dir, event_id)
phases_file = glob.glob(os.path.join(search_base, 'PHASES.mat')) phases_file = glob.glob(os.path.join(search_base, 'PHASES.mat'))
if not phases_file: if not phases_file:
return return
#print('Opening PILOT phases file: {fn}'.format(fn=phases_file[0])) if verbosity > 1:
print('Opening PILOT phases file: {fn}'.format(fn=phases_file[0]))
picks_dict = picks_from_pilot(phases_file[0]) picks_dict = picks_from_pilot(phases_file[0])
#print('Dictionary read from PHASES.mat:\n{0}'.format(picks_dict)) if verbosity > 0:
print('Dictionary read from PHASES.mat:\n{0}'.format(picks_dict))
datacheck = list() datacheck = list()
info = None info = None
for station in picks_dict.keys(): for station in picks_dict.keys():
@ -314,7 +321,8 @@ def reassess_pilot_event(root_dir, event_id, out_dir=None, fn_param=None, verbos
raise ValueError(e.message) raise ValueError(e.message)
except Exception as e: except Exception as e:
if 'No file matching file pattern:' in e.message: if 'No file matching file pattern:' in e.message:
warnings.warn('no waveform data found for station {station}'.format(station=station), RuntimeWarning) if verbosity > 0:
warnings.warn('no waveform data found for station {station}'.format(station=station), RuntimeWarning)
datacheck.append(fn_pattern + ' (no data)\n') datacheck.append(fn_pattern + ' (no data)\n')
continue continue
else: else:
@ -348,7 +356,8 @@ def reassess_pilot_event(root_dir, event_id, out_dir=None, fn_param=None, verbos
picks_dict[station][phase] = dict(epp=epp, mpp=mpp, lpp=lpp, spe=spe) picks_dict[station][phase] = dict(epp=epp, mpp=mpp, lpp=lpp, spe=spe)
if datacheck: if datacheck:
if info: if info:
print(info + ': {0}'.format(search_base)) if verbosity > 0:
print(info + ': {0}'.format(search_base))
fncheck = open(os.path.join(search_base, 'datacheck_list'), 'w') fncheck = open(os.path.join(search_base, 'datacheck_list'), 'w')
fncheck.writelines(datacheck) fncheck.writelines(datacheck)
fncheck.close() fncheck.close()

View File

@ -23,11 +23,17 @@ if __name__ == '__main__':
'most cases PILOT database folder)' 'most cases PILOT database folder)'
) )
parser.add_argument( parser.add_argument(
'--output', '-o', type=str, help='path to the output directory', dest='output' '--output', '-o', type=str, help='path to the output directory',
dest='output'
) )
parser.add_argument( parser.add_argument(
'--parameterfile', '-p', type=str, help='full path to the parameterfile', dest='parfile' '--parameterfile', '-p', type=str,
help='full path to the parameterfile', dest='parfile'
)
parser.add_argument(
'--verbosity', '-v', action='count', help='increase output verbosity',
default=0, dest='verbosity'
) )
args = parser.parse_args() args = parser.parse_args()
reassess_pilot_db(args.dbroot, args.output, args.parfile) reassess_pilot_db(args.dbroot, args.output, args.parfile, args.verbosity)