Browse Source

fix bug export stacked and sligned waveforms, was broken in case of missing traces

main
gesap 2 weeks ago
parent
commit
86d409a5dd
  1. 168
      src/clustering.py

168
src/clustering.py

@ -2210,6 +2210,9 @@ def export_stacked_traces(resultcat, waveform_dir, arrivals, #coef_array,
files = glob.glob('%s/*%s.%s*' % (waveform_dir, st.network, st.station))
p = pile.make_pile(files, show_progress=False)
if not p:
continue
for i_cl, cl in enumerate(set_clusters):
trZs = []
@ -2365,100 +2368,103 @@ def export_stacked_traces(resultcat, waveform_dir, arrivals, #coef_array,
continue
if 'Z' in test_comps:
io.save(trZs, './stacked_waveforms/%s/cl%s/%s.%s_cl%s_Z_aligned.mseed'
% (method_string, cl, st.network, st.station, cl), format='mseed')
n_ev = len(trZs)
if trZs:
io.save(trZs, './stacked_waveforms/%s/cl%s/%s.%s_cl%s_Z_aligned.mseed'
% (method_string, cl, st.network, st.station, cl), format='mseed')
n_ev = len(trZs)
for itr, trZ in enumerate(trZs):
if itr == 0:
trZ_stack = trZ
else:
trZ_stack.add(trZ)
for itr, trZ in enumerate(trZs):
if itr == 0:
trZ_stack = trZ
else:
trZ_stack.add(trZ)
trZ_stack.ydata /= num.max(abs(trZ_stack.ydata))
if debug_stacking is True:
cp_trZ_list = trZs
for itr, tr in enumerate(trZs):
tr.set_location(str(itr))
trace.snuffle(trZs)
trace.snuffle([trZ_stack])
if prep_grond:
# to use grond we shift here by origin time of first event in cluster
evcl = cl_events[0][1]
trZ_stack.shift(evcl.time)
io.save(trZ_stack, './stacked_waveforms/%s/cl%s/stack_cl%s_%s.%s_Z.mseed'
% (method_string, cl, cl, st.network, st.station))
trZ_stack.ydata /= num.max(abs(trZ_stack.ydata))
if debug_stacking is True:
cp_trZ_list = trZs
for itr, tr in enumerate(trZs):
tr.set_location(str(itr))
trace.snuffle(trZs)
trace.snuffle([trZ_stack])
if prep_grond:
# to use grond we shift here by origin time of first event in cluster
evcl = cl_events[0][1]
trZ_stack.shift(evcl.time)
io.save(trZ_stack, './stacked_waveforms/%s/cl%s/stack_cl%s_%s.%s_Z.mseed'
% (method_string, cl, cl, st.network, st.station))
logger.info(' Z component, cluster %s, station %s.%s: Saved all aligned and stacked traces' % (cl, st.network, st.station)
+ ' in directory ./stacked_waveforms/.')
logger.info(' Z component, cluster %s, station %s.%s: Saved all aligned and stacked traces' % (cl, st.network, st.station)
+ ' in directory ./stacked_waveforms/.')
if 'N' in test_comps:
io.save(trNs, './stacked_waveforms/%s/cl%s/%s.%s_cl%s_N_aligned.mseed'
% (method_string, cl, st.network, st.station, cl), format='mseed')
n_ev = len(trNs)
if trNs:
io.save(trNs, './stacked_waveforms/%s/cl%s/%s.%s_cl%s_N_aligned.mseed'
% (method_string, cl, st.network, st.station, cl), format='mseed')
n_ev = len(trNs)
for itr, trN in enumerate(trNs):
if itr == 0:
trN_stack = trN
else:
trN_stack.add(trN)
for itr, trN in enumerate(trNs):
if itr == 0:
trN_stack = trN
else:
trN_stack.add(trN)
trN_stack.ydata /= num.max(abs(trN_stack.ydata))
if debug_stacking is True:
cp_trN_list = trNs
for itr, tr in enumerate(trNs):
tr.set_location(str(itr))
trace.snuffle(trNs)
trace.snuffle([trN_stack])
if prep_grond:
# to use grond we shift here by origin time of first event in cluster
evcl = cl_events[0][1]
trN_stack.shift(evcl.time)
io.save(trN_stack, './stacked_waveforms/%s/cl%s/stack_cl%s_%s.%s_N.mseed'
% (method_string, cl, cl, st.network, st.station))
trN_stack.ydata /= num.max(abs(trN_stack.ydata))
if debug_stacking is True:
cp_trN_list = trNs
for itr, tr in enumerate(trNs):
tr.set_location(str(itr))
trace.snuffle(trNs)
trace.snuffle([trN_stack])
if prep_grond:
# to use grond we shift here by origin time of first event in cluster
evcl = cl_events[0][1]
trN_stack.shift(evcl.time)
io.save(trN_stack, './stacked_waveforms/%s/cl%s/stack_cl%s_%s.%s_N.mseed'
% (method_string, cl, cl, st.network, st.station))
logger.info(' N component, cluster %s, station %s.%s: Saved all aligned and stacked traces' % (cl, st.network, st.station)
+ ' in directory ./stacked_waveforms/.')
logger.info(' N component, cluster %s, station %s.%s: Saved all aligned and stacked traces' % (cl, st.network, st.station)
+ ' in directory ./stacked_waveforms/.')
if 'E' in test_comps:
io.save(trEs, './stacked_waveforms/%s/cl%s/%s.%s_cl%s_E_aligned.mseed'
% (method_string, cl, st.network, st.station, cl), format='mseed')
n_ev = len(trEs)
if trEs:
io.save(trEs, './stacked_waveforms/%s/cl%s/%s.%s_cl%s_E_aligned.mseed'
% (method_string, cl, st.network, st.station, cl), format='mseed')
n_ev = len(trEs)
for itr, trE in enumerate(trEs):
if itr == 0:
trE_stack = trE
else:
trE_stack.add(trE)
for itr, trE in enumerate(trEs):
if itr == 0:
trE_stack = trE
else:
trE_stack.add(trE)
trE_stack.ydata /= num.max(abs(trE_stack.ydata))
if debug_stacking is True:
cp_trE_list = trEs
for itr, tr in enumerate(trEs):
tr.set_location(str(itr))
trace.snuffle(trEs)
trace.snuffle([trE_stack])
if prep_grond:
# to use grond we shift here by origin time of first event in cluster
evcl = cl_events[0][1]
trE_stack.shift(evcl.time)
io.save(trE_stack, './stacked_waveforms/%s/cl%s/stack_cl%s_%s.%s_E.mseed'
% (method_string, cl, cl, st.network, st.station))
trE_stack.ydata /= num.max(abs(trE_stack.ydata))
if debug_stacking is True:
cp_trE_list = trEs
for itr, tr in enumerate(trEs):
tr.set_location(str(itr))
trace.snuffle(trEs)
trace.snuffle([trE_stack])
if prep_grond:
# to use grond we shift here by origin time of first event in cluster
evcl = cl_events[0][1]
trE_stack.shift(evcl.time)
io.save(trE_stack, './stacked_waveforms/%s/cl%s/stack_cl%s_%s.%s_E.mseed'
% (method_string, cl, cl, st.network, st.station))
logger.info(' E component, cluster %s, station %s.%s: Saved all aligned and stacked traces' % (cl, st.network, st.station)
+ ' in directory ./stacked_waveforms/.')
logger.info(' E component, cluster %s, station %s.%s: Saved all aligned and stacked traces' % (cl, st.network, st.station)
+ ' in directory ./stacked_waveforms/.')
if prep_grond:

Loading…
Cancel
Save