Align waveform plots to p pick time

Dear collegues!

I want to thank you for your replies and your suggestions.

A collegue from the University of Trieste replied directly to me with a python script with the following work flow which is similar to the suggestions I received via the Obspy list:

1. put all mseed files which should be plot together into one folder
2. iterate through all files and within this folder, read into streams and cut all to the desired length, starting with the p pick time and write cut streams to a second directory
3. now iterate through the cut streams:
Read trace of interest (e.g. "HHZ")
filter
fill an np array with the data, starting at zero time, amplitudes normalized
add subplot to plot array of matplotlib.pyplot

4. finally show plot/subplots on screen or write to graphics output file

The script basically runs but problems still exist due to minimal time shifts (0.0003 seconds) which can appear in the start time of some traces. This causes matplotlib.pyplot to rise an error because of the small shift in the x axis. I will be trying to find out if there is a way to force the trim function to avoid these shifts.

Best regards
Franz Reiter

Hi Franz,

The script basically runs but problems still exist due to minimal time shifts (0.0003 seconds) which can appear in the start time of some traces. This causes matplotlib.pyplot to rise an error because of the small shift in the x axis. I will be trying to find out if there is a way to force the trim function to avoid these shifts.

The best way to resolve this is to just interpolate them all to exactly
the same sampling points.

https://docs.obspy.org/packages/autogen/obspy.core.trace.Trace.interpolate.html

st.interpolate(sampling_rate=50.0, method="lanczos", starttime=X, npts=4000)

This is in essence a sinc-based reconstruction filter so the error is
usually neglect-able. Note that the starttime + npts setting acts like
the trimming. What you end up with are all trace being sampled at
exactly the same points in time. If you use this to also downsample
data: make sure to apply a very sharp lowpass before to avoid aliasing.

Cheers!

Lion