How to use correlation_detector for envelopes?

detections, sims = cross_correlation.correlation_detector(stream_env, template_env, height, distance)


AttributeError Traceback (most recent call last)
Cell In[109], line 3
1 height=0.1
2 distance=3
----> 3 detections, sims = cross_correlation.correlation_detector(stream_env, template_env, height, distance)

File ~/anaconda3/lib/python3.9/site-packages/obspy/signal/cross_correlation.py:1075, in correlation_detector(stream, templates, heights, distance, template_times, template_magnitudes, template_names, similarity_func, details, plot, **kwargs)
1073 template_time = _get_item(template_times, template_id)
1074 try:
→ 1075 ccs = correlate_stream_template(stream, template,
1076 template_time=template_time,
1077 **cckwargs)
1078 except ValueError as ex:
1079 msg = ‘{} → do not use template {}’.format(ex, template_id)

File ~/anaconda3/lib/python3.9/site-packages/obspy/signal/cross_correlation.py:842, in correlate_stream_template(stream, template, template_time, **kwargs)
802 def correlate_stream_template(stream, template, template_time=None, **kwargs):
803 “”"
804 Calculate cross-correlation of traces in stream with traces in template.
805
(…)
840 BW.RJOB…EHZ | … - 2009-08-24T00:20:22.990000Z | 100.0 Hz, 2000 samples
841 “”"
→ 842 stream, template = _prep_streams_correlate(stream, template,
843 template_time=template_time)
844 return _correlate_prepared_stream_template(stream, template, **kwargs)

File ~/anaconda3/lib/python3.9/site-packages/obspy/signal/cross_correlation.py:745, in _prep_streams_correlate(stream, template, template_time)
738 def _prep_streams_correlate(stream, template, template_time=None):
739 “”"
740 Prepare stream and template for cross-correlation.
741
742 Select traces in stream and template with the same seed id and trim
743 stream to correct start and end times.
744 “”"
→ 745 if len({tr.stats.sampling_rate for tr in stream + template}) > 1:
746 raise ValueError(‘Traces have different sampling rate’)
747 ids = {tr.id for tr in stream} & {tr.id for tr in template}

File ~/anaconda3/lib/python3.9/site-packages/obspy/signal/cross_correlation.py:745, in (.0)
738 def _prep_streams_correlate(stream, template, template_time=None):
739 “”"
740 Prepare stream and template for cross-correlation.
741
742 Select traces in stream and template with the same seed id and trim
743 stream to correct start and end times.
744 “”"
→ 745 if len({tr.stats.sampling_rate for tr in stream + template}) > 1:
746 raise ValueError(‘Traces have different sampling rate’)
747 ids = {tr.id for tr in stream} & {tr.id for tr in template}

AttributeError: ‘numpy.float64’ object has no attribute ‘stats’

The correlation detector should work with envelopes out of the box. Just make sure to calculate the envelopes beforehand and assign it to the data attributes of the trace objects. The error seems to indicate, that you are working with numpy arrays instead of traces.

Please have a look here for how to format postings :slight_smile: