Skip to content

Commit

Permalink
More robust slicing for lag-calc
Browse files Browse the repository at this point in the history
  • Loading branch information
calum-chamberlain committed Jul 25, 2024
1 parent f8c802b commit 81e9b13
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
16 changes: 12 additions & 4 deletions eqcorrscan/core/match_filter/detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,11 +406,19 @@ def extract_stream(self, stream, length, prepick, all_vert=False,
pick.sort(key=lambda p: p.time)
pick = pick[0]
cut_start = pick.time - prepick
cut_end = cut_start + length
_st = _st.slice(starttime=cut_start, endtime=cut_end).copy()
# Minimum length check
# Find nearest sample to avoid trimming to too-short length - see #573

Check failure on line 409 in eqcorrscan/core/match_filter/detection.py

View workflow job for this annotation

GitHub Actions / flake8-linter

E501 line too long (82 > 80 characters)
for tr in _st:
if abs((tr.stats.endtime - tr.stats.starttime) -
sample_offset = (cut_start - tr.stats.starttime) / tr.stats.delta

Check failure on line 411 in eqcorrscan/core/match_filter/detection.py

View workflow job for this annotation

GitHub Actions / flake8-linter

E501 line too long (81 > 80 characters)
sample_offset //= 1
# If the sample offset is not a whole number, always take the sample

Check failure on line 413 in eqcorrscan/core/match_filter/detection.py

View workflow job for this annotation

GitHub Actions / flake8-linter

E501 line too long (84 > 80 characters)
# before that requested
_tr_cut_start = tr.stats.starttime + (sample_offset * tr.stats.delta)

Check failure on line 415 in eqcorrscan/core/match_filter/detection.py

View workflow job for this annotation

GitHub Actions / flake8-linter

E501 line too long (85 > 80 characters)
_tr_cut_end = _tr_cut_start + length
Logger.info(f"Trimming {tr.id} between {_tr_cut_end} and {_tr_cut_end}.")

Check failure on line 417 in eqcorrscan/core/match_filter/detection.py

View workflow job for this annotation

GitHub Actions / flake8-linter

E501 line too long (89 > 80 characters)
_tr = tr.slice(_tr_cut_start, _tr_cut_end).copy()
Logger.debug(f"Length: {(_tr.stats.endtime - _tr.stats.starttime)}")

Check failure on line 419 in eqcorrscan/core/match_filter/detection.py

View workflow job for this annotation

GitHub Actions / flake8-linter

E501 line too long (84 > 80 characters)
Logger.debug(f"Requested length: {length}")
if abs((_tr.stats.endtime - _tr.stats.starttime) -
length) < tr.stats.delta:
cut_stream += tr
else:
Expand Down
5 changes: 4 additions & 1 deletion eqcorrscan/tests/lag_calc_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ class SyntheticTests(unittest.TestCase):
def setUpClass(cls):
np.random.seed(999)
print("Setting up class")
np.random.seed(999)
samp_rate = 50
t_length = .75
# Make some synthetic templates
templates, data, seeds = generate_synth_data(
nsta=5, ntemplates=5, nseeds=10, samp_rate=samp_rate,
t_length=t_length, max_amp=10, max_lag=15, phaseout="both",
jitter=0, noise=False, same_phase=True)
print("Made synthetic data")
# Rename channels
channel_mapper = {"SYN_Z": "HHZ", "SYN_H": "HHN"}
for tr in data:
Expand All @@ -44,6 +44,7 @@ def setUpClass(cls):
party = Party()
t = 0
data_start = data[0].stats.starttime
print("Making party")
for template, template_seeds in zip(templates, seeds):
template_name = "template_{0}".format(t)
detections = []
Expand All @@ -68,6 +69,8 @@ def setUpClass(cls):
family = Family(template=_template, detections=detections)
party += family
t += 1
print(f"Made template {template_name}")
print("Made party")
cls.party = party
cls.data = data
cls.t_length = t_length
Expand Down

0 comments on commit 81e9b13

Please sign in to comment.