[bugfix] partially reverted signature of an inner function with shadowed variable name
[refactor] minor
This commit is contained in:
parent
61c3f40063
commit
759e7bb848
@ -691,10 +691,8 @@ def correlate_event(eventdir: str, pylot_parameter: PylotParameter, params: dict
|
|||||||
|
|
||||||
# continue if there is not enough traces for stacking
|
# continue if there is not enough traces for stacking
|
||||||
if nstack < params[phase_type]['min_stack']:
|
if nstack < params[phase_type]['min_stack']:
|
||||||
logging.warning('Not enough traces to stack: {} (min_stack = {}). Skip this event'.format(nstack,
|
logging.warning(f"Not enough traces to stack: {nstack} "
|
||||||
params[
|
f"(min_stack = {params[phase_type]['min_stack']}). Skip this event")
|
||||||
phase_type][
|
|
||||||
'min_stack']))
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# write unfiltered trace
|
# write unfiltered trace
|
||||||
@ -847,9 +845,8 @@ def get_corrected_taupy_picks(picks, taupypicks, all_available=False):
|
|||||||
mean_diff = taupy_mean - picks_mean
|
mean_diff = taupy_mean - picks_mean
|
||||||
|
|
||||||
logging.info(f'Calculated {len(taupypicks_new)} TauPy theoretical picks.')
|
logging.info(f'Calculated {len(taupypicks_new)} TauPy theoretical picks.')
|
||||||
logging.info(
|
logging.info(f'Calculated median difference from TauPy '
|
||||||
'Calculated median difference from TauPy theoretical picks of {} seconds. (mean: {})'.format(median_diff,
|
f'theoretical picks of {median_diff} seconds. (mean: {mean_diff})')
|
||||||
mean_diff))
|
|
||||||
|
|
||||||
# return all available taupypicks corrected for median difference to autopicks
|
# return all available taupypicks corrected for median difference to autopicks
|
||||||
if all_available:
|
if all_available:
|
||||||
@ -1267,9 +1264,9 @@ def apply_stacking(trace_master: Trace, stations4stack: dict, wfdata: Stream, pi
|
|||||||
check_rms: bool, dt_pre: float = 250., dt_post: float = 250., plot: bool = False,
|
check_rms: bool, dt_pre: float = 250., dt_post: float = 250., plot: bool = False,
|
||||||
fig_dir: str = None) -> tuple:
|
fig_dir: str = None) -> tuple:
|
||||||
|
|
||||||
def check_trace_length_and_cut(trace: Trace):
|
def check_trace_length_and_cut(trace: Trace, pick_time: UTCDateTime = None):
|
||||||
starttime = correlated_midtime - dt_pre
|
starttime = pick_time - dt_pre
|
||||||
endtime = correlated_midtime + dt_post
|
endtime = pick_time + dt_post
|
||||||
|
|
||||||
if trace.stats.starttime > starttime or trace.stats.endtime < endtime:
|
if trace.stats.starttime > starttime or trace.stats.endtime < endtime:
|
||||||
raise ValueError('Trace too short for safe cutting. Would create inconsistent stacking. Abort!')
|
raise ValueError('Trace too short for safe cutting. Would create inconsistent stacking. Abort!')
|
||||||
@ -1282,7 +1279,7 @@ def apply_stacking(trace_master: Trace, stations4stack: dict, wfdata: Stream, pi
|
|||||||
|
|
||||||
trace_master = trace_master.copy()
|
trace_master = trace_master.copy()
|
||||||
trace_master.stats.location = 'ST'
|
trace_master.stats.location = 'ST'
|
||||||
check_trace_length_and_cut(trace_master)
|
check_trace_length_and_cut(trace_master, pick.time)
|
||||||
|
|
||||||
# empty trace so that it does not stack twice
|
# empty trace so that it does not stack twice
|
||||||
trace_master.data = np.zeros(len(trace_master.data))
|
trace_master.data = np.zeros(len(trace_master.data))
|
||||||
@ -1296,7 +1293,7 @@ def apply_stacking(trace_master: Trace, stations4stack: dict, wfdata: Stream, pi
|
|||||||
stream_other = wfdata.select(network=nw, station=st, channel=channel)
|
stream_other = wfdata.select(network=nw, station=st, channel=channel)
|
||||||
correlated_midtime = pick_other.time - dpick
|
correlated_midtime = pick_other.time - dpick
|
||||||
trace_other = stream_other[0].copy()
|
trace_other = stream_other[0].copy()
|
||||||
check_trace_length_and_cut(trace_other)
|
check_trace_length_and_cut(trace_other, correlated_midtime)
|
||||||
|
|
||||||
if not len(trace_other) == len(trace_master):
|
if not len(trace_other) == len(trace_master):
|
||||||
logging.warning(
|
logging.warning(
|
||||||
@ -1306,23 +1303,25 @@ def apply_stacking(trace_master: Trace, stations4stack: dict, wfdata: Stream, pi
|
|||||||
traces4stack.append(trace_other)
|
traces4stack.append(trace_other)
|
||||||
|
|
||||||
if check_rms:
|
if check_rms:
|
||||||
traces4stack = checkRMS(traces4stack, plot=plot, fig_dir=fig_dir)
|
traces4stack = check_rms(traces4stack, plot=plot, fig_dir=fig_dir)
|
||||||
|
|
||||||
if plot:
|
if plot:
|
||||||
fig = plt.figure(figsize=(16, 9))
|
fig = plt.figure(figsize=(16, 9))
|
||||||
ax1 = fig.add_subplot(211)
|
ax1 = fig.add_subplot(211)
|
||||||
ax2 = fig.add_subplot(212)
|
ax2 = fig.add_subplot(212)
|
||||||
|
else:
|
||||||
|
fig = ax1 = ax2 = None
|
||||||
|
|
||||||
for trace_other in traces4stack:
|
for trace_other in traces4stack:
|
||||||
# stack on mastertrace
|
# stack on mastertrace
|
||||||
trace_normalized = trace_other.copy().normalize()
|
trace_normalized = trace_other.copy().normalize()
|
||||||
trace_master.data += trace_normalized.data
|
trace_master.data += trace_normalized.data
|
||||||
count += 1
|
count += 1
|
||||||
if plot:
|
if plot and ax1 and ax2:
|
||||||
ax1.plot(trace_master.data, label=count)
|
ax1.plot(trace_master.data, label=count)
|
||||||
ax2.plot(trace_normalized.data, color='k', alpha=0.1)
|
ax2.plot(trace_normalized.data, color='k', alpha=0.1)
|
||||||
|
|
||||||
if plot:
|
if plot and fig:
|
||||||
if fig_dir:
|
if fig_dir:
|
||||||
fig.savefig(os.path.join(fig_dir, 'traces_stacked.svg'), dpi=300.)
|
fig.savefig(os.path.join(fig_dir, 'traces_stacked.svg'), dpi=300.)
|
||||||
else:
|
else:
|
||||||
@ -1335,7 +1334,7 @@ def apply_stacking(trace_master: Trace, stations4stack: dict, wfdata: Stream, pi
|
|||||||
return trace_master, count
|
return trace_master, count
|
||||||
|
|
||||||
|
|
||||||
def checkRMS(traces4stack, plot=False, fig_dir=None, max_it=10, ntimes_std=5.):
|
def check_rms(traces4stack, plot=False, fig_dir=None, max_it=10, ntimes_std=5.):
|
||||||
rms_list = []
|
rms_list = []
|
||||||
trace_names = []
|
trace_names = []
|
||||||
|
|
||||||
@ -1353,7 +1352,7 @@ def checkRMS(traces4stack, plot=False, fig_dir=None, max_it=10, ntimes_std=5.):
|
|||||||
while iterate:
|
while iterate:
|
||||||
count += 1
|
count += 1
|
||||||
if count >= max_it:
|
if count >= max_it:
|
||||||
logging.debug('Maximum iterations ({}) of checkRMS function reached.'.format(max_it))
|
logging.debug('Maximum iterations ({}) of check_rms function reached.'.format(max_it))
|
||||||
break
|
break
|
||||||
std = np.std(rms_list)
|
std = np.std(rms_list)
|
||||||
mean = np.mean(rms_list)
|
mean = np.mean(rms_list)
|
||||||
|
Loading…
Reference in New Issue
Block a user