From 4962561d6ca63025bac6dc1b4062687d5fed19a4 Mon Sep 17 00:00:00 2001 From: sebastianp Date: Tue, 24 May 2016 13:21:38 +0200 Subject: [PATCH] changes made to have better control of the output directory --- pylot/core/io/phases.py | 20 +++++++++++++------- scripts/pylot-reasses-pilot-db.py | 8 +++++--- scripts/pylot-reasses-pilot-event.py | 8 +++++--- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/pylot/core/io/phases.py b/pylot/core/io/phases.py index 604ea940..0893222f 100644 --- a/pylot/core/io/phases.py +++ b/pylot/core/io/phases.py @@ -270,19 +270,20 @@ def picks_from_picksdict(picks): return picks_list -def reassess_pilot_db(root_dir, out_dir=None, fn_param=None, verbosity=0): +def reassess_pilot_db(root_dir, db_dir, out_dir=None, fn_param=None, verbosity=0): import glob - evt_list = glob.glob1(root_dir,'e????.???.??') + db_root = os.path.join(root_dir, db_dir) + evt_list = glob.glob1(db_root,'e????.???.??') for evt in evt_list: if verbosity > 0: print('Reassessing event {0}'.format(evt)) - reassess_pilot_event(root_dir, evt, out_dir, fn_param, verbosity) + reassess_pilot_event(root_dir, db_dir, evt, out_dir, fn_param, verbosity) -def reassess_pilot_event(root_dir, event_id, out_dir=None, fn_param=None, verbosity=0): +def reassess_pilot_event(root_dir, db_dir, event_id, out_dir=None, fn_param=None, verbosity=0): from obspy import read from pylot.core.io.inputs import AutoPickParameter @@ -294,7 +295,7 @@ def reassess_pilot_event(root_dir, event_id, out_dir=None, fn_param=None, verbos default = AutoPickParameter(fn_param, verbosity) - search_base = os.path.join(root_dir, event_id) + search_base = os.path.join(root_dir, db_dir, event_id) phases_file = glob.glob(os.path.join(search_base, 'PHASES.mat')) if not phases_file: return @@ -335,7 +336,9 @@ def reassess_pilot_event(root_dir, event_id, out_dir=None, fn_param=None, verbos continue sel_st = select_for_phase(st, phase) if not sel_st: - warnings.warn('no waveform data found for station {station}'.format(station=station), RuntimeWarning) + msg = 'no waveform data found for station {station}'.format(station=station) + warnings.warn(msg, RuntimeWarning) + continue stime, etime = getGlobalTimes(sel_st) rel_pick = mpp - stime epp, lpp, spe = earllatepicker(sel_st, @@ -367,8 +370,11 @@ def reassess_pilot_event(root_dir, event_id, out_dir=None, fn_param=None, verbos evt.picks = picks_from_picksdict(picks_dict) # write phase information to file if not out_dir: - fnout_prefix = os.path.join(root_dir, event_id, '{0}.'.format(event_id)) + fnout_prefix = os.path.join(root_dir, db_dir, event_id, '{0}.'.format(event_id)) else: + out_dir = os.path.join(out_dir, db_dir) + if not os.path.isdir(out_dir): + os.makedirs(out_dir) fnout_prefix = os.path.join(out_dir, '{0}.'.format(event_id)) evt.write(fnout_prefix + 'xml', format='QUAKEML') #evt.write(fnout_prefix + 'cnv', format='VELEST') diff --git a/scripts/pylot-reasses-pilot-db.py b/scripts/pylot-reasses-pilot-db.py index 83cdf254..7b55ce6a 100755 --- a/scripts/pylot-reasses-pilot-db.py +++ b/scripts/pylot-reasses-pilot-db.py @@ -19,8 +19,10 @@ if __name__ == '__main__': ) parser.add_argument( - 'dbroot', type=str, help='specifies the root directory (in ' - 'most cases PILOT database folder)' + 'root', type=str, help='specifies the root directory' + ) + parser.add_argument( + 'db', type=str, help='specifies the database name' ) parser.add_argument( '--output', '-o', type=str, help='path to the output directory', @@ -36,4 +38,4 @@ if __name__ == '__main__': ) args = parser.parse_args() - reassess_pilot_db(args.dbroot, args.output, args.parfile, args.verbosity) + reassess_pilot_db(args.root, args.db, args.output, args.parfile, args.verbosity) diff --git a/scripts/pylot-reasses-pilot-event.py b/scripts/pylot-reasses-pilot-event.py index 1852e680..b9fd3a39 100755 --- a/scripts/pylot-reasses-pilot-event.py +++ b/scripts/pylot-reasses-pilot-event.py @@ -19,8 +19,10 @@ if __name__ == '__main__': ) parser.add_argument( - 'dbroot', type=str, help='specifies the root directory (in ' - 'most cases PILOT database folder)' + 'root', type=str, help='specifies the root directory' + ) + parser.add_argument( + 'db', type=str, help='specifies the database name' ) parser.add_argument( 'id', type=str, help='PILOT event identifier' @@ -33,4 +35,4 @@ if __name__ == '__main__': ) args = parser.parse_args() - reassess_pilot_event(args.dbroot, args.id, args.output, args.parfile) + reassess_pilot_event(args.root, args.db, args.id, args.output, args.parfile)