Can't rotate seismograms for some events, works for example events though

Hi Tom,

I’ve been working on other projects since we chatted via email but to pick that thread up from November. I am using your example template for calculating basic RFs for a chosen event. I can run your example data no problem.

However, for my own data, some seismograms seem to rotate and produce a sensible RF, but others do not rotate at all, and do not make any RFs. I do get the following error, but I think this is unrelated because I get that error on the working RFs.

“/opt/anaconda3/envs/RF_package/lib/python3.8/site-packages/rf/deconvolve.py:346: UserWarning: Toeplitz import error. Fallback to slower Scipy version.
warn(‘Toeplitz import error. Fallback to slower Scipy version.’)”

I’d be very happy to share code/data to see how I can move forward and get some RFs made for analysis.

I’m working on a MacBook Pro with Apple M1 Pro, Monterey 12.4 OS.

Many thanks,
Chris

Hi Chris,

yes, best would be to share a minimal working (or in this case failing) example including data and code.

The warning is unrelated and can be safely ignored.

Hi Tom,

OK no problem. The code is not pretty because I have been playing around with it and will improve it when I know what I am looking for!

Being a new user I cannot upload an attachment. I will send these via email?

Many thanks,
Chris

The problem with the data which does not rotate is that the event origin time does not match in the three traces:

> print([tr.stats.event_time for tr in stream])
[2019-08-02T12:03:26.999980Z,
 2019-08-02T12:03:27.001018Z,
 2019-08-02T12:03:26.999980Z]
> print([tr.stats.sac.o for tr in stream])
[-563.52, -563.519, -563.52]

rf is quite pedantic here without any warning. I am thinking about ways to improve this behavior.

A quick fix for your code would be

        for tr in stream:
            tr.stats.event_time = stream[0].stats.event_time  

after reading the waveform data.

I thought it would be some syntax issue that an external pair of eyes would see - I couldn’t see the wood for the trees. Sorry for not spotting it myself!

Many thanks for your help, hopefully I can make some progress now.

Cheers,
Chris

Hi again,

Another hopefully quick question please!

I got all the RFs working for one of my datasets with no issues after your suggestions. However, the next dataset has more time window problems. I’ve attached my code and the datafiles that are a problem. This error is happening for many of my traces for this network, it is not isolated. See the output at the bottom please.

I’ve played around altering the cut time/length and changing the onset time, event time. I can see the files are the same length with same onset time so I’ve got to a dead end. Any suggestions please?

Code
RF_LQT_from_seismogram.ipynb (245.3 KB)
20220823143139_962_Z1.Z01J.hhe (28.0 KB)
20220823143139_962_Z1.Z01J.hhn (28.0 KB)
20220823143139_962_Z1.Z01J.hhz (28.0 KB)

20220823143139_962_Z1.Z01J.hhz
Z1.Z01J…HHE | -75.0s - 205.0s onset:2022-08-23T14:43:19.715974Z | 25.0 Hz, 7001 samples | dist:78.3 baz:92.9 slow:316.30
Z1.Z01J…HHN | -75.0s - 205.0s onset:2022-08-23T14:43:19.715974Z | 25.0 Hz, 7001 samples | dist:78.3 baz:92.9 slow:316.30
Z1.Z01J…HHZ | -75.0s - 205.0s onset:2022-08-23T14:43:19.715974Z | 25.0 Hz, 7001 samples | dist:78.3 baz:92.9 slow:316.30
3 Trace(s) in Stream:
Z1.Z01J…HHE | -75.0s - 205.0s onset:2022-08-23T14:43:19.715974Z | 25.0 Hz, 7001 samples | dist:78.3 baz:92.9 slow:316.30
Z1.Z01J…HHN | -75.0s - 205.0s onset:2022-08-23T14:43:19.715974Z | 25.0 Hz, 7001 samples | dist:78.3 baz:92.9 slow:316.30
Z1.Z01J…HHZ | -75.0s - 205.0s onset:2022-08-23T14:43:19.715974Z | 25.0 Hz, 7001 samples | dist:78.3 baz:92.9 slow:316.30
3 Trace(s) in Stream:
Z1.Z01J…HHE | -15.5s - 84.5s onset:2022-08-23T14:43:35.192669Z | 25.0 Hz, 2501 samples | dist:78.4 baz:93.0 slow:5.51
Z1.Z01J…HHN | -15.5s - 84.5s onset:2022-08-23T14:43:35.192669Z | 25.0 Hz, 2501 samples | dist:78.4 baz:93.0 slow:5.51
Z1.Z01J…HHZ | -15.5s - 84.5s onset:2022-08-23T14:43:35.192669Z | 25.0 Hz, 2501 samples | dist:78.4 baz:93.0 slow:5.51

ValueError Traceback (most recent call last)
Input In [19], in <cell line: 10>()
45 print(stream)
46 # stream[:3].plot(type=‘relative’, reftime=stream[0].stats.onset)
—> 48 stream.rf(deconvolve=‘multitaper’)
49 # stream.rf()
50 stream.moveout

File /opt/anaconda3/envs/RF_package/lib/python3.8/site-packages/decorator.py:232, in decorate..fun(*args, **kw)
230 if not kwsyntax:
231 args, kw = fix(args, kw, sig)
→ 232 return caller(func, *(extras + args), **kw)

File /opt/anaconda3/envs/RF_package/lib/python3.8/site-packages/rf/util.py:243, in _add_processing_info(func, *args, **kwargs)
240 arguments = [‘%s=%s’ % (k, repr(v)) if not isinstance(v, str) else
241 “%s=‘%s’” % (k, v) for k, v in kw.items()]
242 info = info % ‘::’.join(sorted(arguments))
→ 243 stream = func(*args, **kwargs)
244 try:
245 for tr in stream:

File /opt/anaconda3/envs/RF_package/lib/python3.8/site-packages/rf/rfstream.py:326, in RFStream.rf(self, method, filter, trim, downsample, rotate, deconvolve, source_components, **kwargs)
324 if rotate:
325 for stream3c in iter3c(self):
→ 326 stream3c.rotate(rotate)
327 # Multiply -1 on Q component, because Q component is pointing
328 # towards the event after the rotation with ObsPy.
329 # For a positive phase at a Moho-like velocity contrast,
(…)
332 # away from the event.
333 # (compare issue #4)
334 for tr in self:

File /opt/anaconda3/envs/RF_package/lib/python3.8/site-packages/obspy/core/stream.py:2852, in Stream.rotate(self, method, back_azimuth, inclination, inventory, **kwargs)
2843 if (len(i_1) != len(i_2)) or (len(i_1) != len(i_3)) or
2844 (abs(i_1.stats.starttime -
2845 i_2.stats.starttime) > dt) or
(…)
2849 i_2.stats.sampling_rate) or
2850 (i_1.stats.sampling_rate != i_3.stats.sampling_rate):
2851 msg = “All components need to have the same time span.”
→ 2852 raise ValueError(msg)
2853 for i_1, i_2, i_3 in zip(input_1, input_2, input_3):
2854 # Figure out inclination and back-azimuth.
2855 baz = back_azimuth

ValueError: All components need to have the same time span.

Hey,

it is a similar problem and ObsPy’s standard behavior. The starttimes do not align:

In [1]: from obspy import read
In [2]: s = read('20220823143139_962_Z1.Z01J.hh?')
In [3]: s
Out[3]: 
3 Trace(s) in Stream:
Z1.Z01J..HHE | 2022-08-23T14:42:04.709993Z - 2022-08-23T14:46:44.709993Z | 25.0 Hz, 7001 samples
Z1.Z01J..HHN | 2022-08-23T14:42:04.720002Z - 2022-08-23T14:46:44.720002Z | 25.0 Hz, 7001 samples
Z1.Z01J..HHZ | 2022-08-23T14:42:04.699983Z - 2022-08-23T14:46:44.699983Z | 25.0 Hz, 7001 samples
In [4]: s.rotate('ZNE->LQT', azimuth=0, inlcination=10)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[4], line 1
----> 1 s.rotate('ZNE->LQT', azimuth=0, inlcination=10)

File ~/.local/anaconda/envs/workhorse/lib/python3.10/site-packages/obspy/core/stream.py:2852, in Stream.rotate(self, method, back_azimuth, inclination, inventory, **kwargs)
   2843     if (len(i_1) != len(i_2)) or (len(i_1) != len(i_3)) or \
   2844             (abs(i_1.stats.starttime -
   2845                  i_2.stats.starttime) > dt) or \
   (...)
   2849                 i_2.stats.sampling_rate) or \
   2850             (i_1.stats.sampling_rate != i_3.stats.sampling_rate):
   2851         msg = "All components need to have the same time span."
-> 2852         raise ValueError(msg)
   2853 for i_1, i_2, i_3 in zip(input_1, input_2, input_3):
   2854     # Figure out inclination and back-azimuth.
   2855     baz = back_azimuth

ValueError: All components need to have the same time span.

Thanks!

Figured it out with your suggestions.

Many thanks,
Chris