Skip to content

Commit

Permalink
Minor Bug Fix
Browse files Browse the repository at this point in the history
* Fixed a minor bug in xcorqc.py that would cause spurious empty windows
  with certain windowing parameterizations
  • Loading branch information
geojunky committed May 3, 2022
1 parent bfccf18 commit 9da4fda
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions seismic/xcorqc/xcorqc.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,18 @@ def xcorr2(tr1, tr2, sta1_inv=None, sta2_inv=None,
# sr = 0
resultCache = []

# set day-aligned start-indices
# set aligned start-indices
max_dt = np.max([1./sr1, 1./sr2])
maxStartTime = max(tr1.stats.starttime, tr2.stats.starttime)
dayAlignedStartTime = UTCDateTime(year=maxStartTime.year, month=maxStartTime.month,
day=maxStartTime.day)
itr1s = (dayAlignedStartTime - tr1.stats.starttime) * sr1
itr2s = (dayAlignedStartTime - tr2.stats.starttime) * sr2
alignedStartTime = None
if(np.fabs(tr1.stats.starttime - tr2.stats.starttime) > max_dt):
alignedStartTime = UTCDateTime(year=maxStartTime.year, month=maxStartTime.month,
day=maxStartTime.day)
else:
alignedStartTime = maxStartTime
# end if
itr1s = (alignedStartTime - tr1.stats.starttime) * sr1
itr2s = (alignedStartTime - tr2.stats.starttime) * sr2

if resample_rate:
sr1 = resample_rate
Expand All @@ -177,16 +183,16 @@ def xcorr2(tr1, tr2, sta1_inv=None, sta2_inv=None,
intervalStartSeconds = []
intervalEndSeconds = []
while itr1s < lentr1_all and itr2s < lentr2_all:
itr1e = min(lentr1_all, itr1s + interval_samples_1)
itr2e = min(lentr2_all, itr2s + interval_samples_2)

while (itr1s < 0) or (itr2s < 0):
itr1s += (window_samples_1 - 2*window_buffer_seconds*sr1_orig) - \
(window_samples_1 - 2*window_buffer_seconds*sr1_orig) * window_overlap
itr2s += (window_samples_2 - 2*window_buffer_seconds*sr2_orig) - \
(window_samples_2 - 2*window_buffer_seconds*sr2_orig) * window_overlap
# end while

itr1e = min(lentr1_all, itr1s + interval_samples_1)
itr2e = min(lentr2_all, itr2s + interval_samples_2)

if (np.fabs(itr1e - itr1s) < sr1_orig) or (np.fabs(itr2e - itr2s) < sr2_orig):
itr1s = itr1e
itr2s = itr2e
Expand Down
Binary file modified tests/test_seismic/xcorqc/data/expected/expected.tar.gz
Binary file not shown.

0 comments on commit 9da4fda

Please sign in to comment.