[edit] inserted verbosity option to control the amount of output
This commit is contained in:
parent
9b7db91037
commit
54b557930f
@ -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:
|
||||
|
||||
@ -60,6 +60,7 @@ class AutoPickParameter(object):
|
||||
parspl = line.split('\t')[:2]
|
||||
parFileCont[parspl[0].strip()] = parspl[1]
|
||||
except IndexError as e:
|
||||
if verbosity > 0:
|
||||
self._printParameterError(e)
|
||||
inputFile.seek(0)
|
||||
lines = inputFile.readlines()
|
||||
|
@ -262,18 +262,23 @@ def picks_from_picksdict(picks):
|
||||
else:
|
||||
pick.polarity = 'undecidable'
|
||||
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)
|
||||
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
|
||||
|
||||
evt_list = glob.glob1(root_dir,'e????.???.??')
|
||||
|
||||
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
|
||||
fn_param = defaults.AUTOMATIC_DEFAULTS
|
||||
|
||||
default = AutoPickParameter(fn_param)
|
||||
default = AutoPickParameter(fn_param, verbosity)
|
||||
|
||||
search_base = os.path.join(root_dir, event_id)
|
||||
phases_file = glob.glob(os.path.join(search_base, 'PHASES.mat'))
|
||||
if not phases_file:
|
||||
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])
|
||||
#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()
|
||||
info = None
|
||||
for station in picks_dict.keys():
|
||||
@ -314,6 +321,7 @@ def reassess_pilot_event(root_dir, event_id, out_dir=None, fn_param=None, verbos
|
||||
raise ValueError(e.message)
|
||||
except Exception as e:
|
||||
if 'No file matching file pattern:' in e.message:
|
||||
if verbosity > 0:
|
||||
warnings.warn('no waveform data found for station {station}'.format(station=station), RuntimeWarning)
|
||||
datacheck.append(fn_pattern + ' (no data)\n')
|
||||
continue
|
||||
@ -348,6 +356,7 @@ 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)
|
||||
if datacheck:
|
||||
if info:
|
||||
if verbosity > 0:
|
||||
print(info + ': {0}'.format(search_base))
|
||||
fncheck = open(os.path.join(search_base, 'datacheck_list'), 'w')
|
||||
fncheck.writelines(datacheck)
|
||||
|
@ -23,11 +23,17 @@ if __name__ == '__main__':
|
||||
'most cases PILOT database folder)'
|
||||
)
|
||||
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(
|
||||
'--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()
|
||||
reassess_pilot_db(args.dbroot, args.output, args.parfile)
|
||||
reassess_pilot_db(args.dbroot, args.output, args.parfile, args.verbosity)
|
||||
|
Loading…
Reference in New Issue
Block a user