Issue plotting P and S waves in Obspy

Anyone know why this code marks the same waves twice at roughly the same time? I’m sure the answer is simple but I just can’t see it at the moment.


Here is the relevant code:

for arr in arrivals:
    if arr.name == 'P':
        arrival_time = arr.time + start_time.timestamp - stream[0].stats.starttime.timestamp
        ax.axvline(x=arrival_time, color='b', linestyle='-', linewidth=1)
        ax.text(arrival_time, max(stream[0].data), arr.name, va='bottom', ha='center')

    elif arr.name == 'S':
        arrival_time = arr.time + start_time.timestamp - stream[0].stats.starttime.timestamp
        ax.axvline(x=arrival_time, color='r', linestyle='-')
        ax.text(arrival_time, max(stream[0].data), arr.name, va='bottom', ha='center')

ax.set_xlabel('Time (s)')
ax.set_ylabel('Counts')
ax.set_title('EHZ Waveform')

Any help would be much apricated thanks!

2 Likes

Hi Matt,

Check the contents of the arr. I am thinking there are two P and S arrivals and it is plotting them both.

Here is my arrivals list for a local quake. I ended up taking the first P and S. I also have some code to take the average value if I find it is a better match to the waveform. In most cases, the first arrival works.

5 arrivals
P phase arrival at 34.768 seconds
P phase arrival at 37.076 seconds
P phase arrival at 37.503 seconds
P phase arrival at 38.355 seconds
P phase arrival at 38.846 seconds

5 arrivals
S phase arrival at 61.310 seconds
S phase arrival at 64.162 seconds
S phase arrival at 64.909 seconds
S phase arrival at 66.208 seconds
S phase arrival at 67.056 seconds

–Steve
RS4D RD29A
Chino Hills, Ca

4 Likes

Thanks for the quick reply, that appears to be the issue as the console prints the below text

P phase arrival at 334.316 seconds
P phase arrival at 337.612 seconds
P phase arrival at 337.873 seconds
S phase arrival at 607.074 seconds
S phase arrival at 616.727 seconds
S phase arrival at 616.823 seconds

Thanks for the help!

1 Like