Trimming streams/traces with different starting and ending time

Hi all,

When I’m trimming some streams with slightly different starting and ending time to the same starting and ending time, the resulted streams don’t have the same stats.startting and stats.enditime even the sample size is the same. Here’s an example using different channels (same applied to different stations):

st = obspy.read()
st1 = st[0].copy()
st2 = st[1].copy()
st3 = st[2].copy()
print(st)

3 Trace(s) in Stream:
BW.RJOB…EHZ | 2009-08-24T00:20:03.000000Z - 2009-08-24T00:20:32.990000Z | 100.0 Hz, 3000 samples
BW.RJOB…EHN | 2009-08-24T00:20:03.000000Z - 2009-08-24T00:20:32.990000Z | 100.0 Hz, 3000 samples
BW.RJOB…EHE | 2009-08-24T00:20:03.000000Z - 2009-08-24T00:20:32.990000Z | 100.0 Hz, 3000 samples

I then trim the stream randomly to get three traces with different starting and ending time and add them back to a main stream and downsample the data:

st1.trim(st1.stats.starttime+0.0589, st1.stats.endtime-0.0565)
st2.trim(st2.stats.starttime+0.0256, st2.stats.endtime-0.0248)
st3.trim(st3.stats.starttime+0.039, st3.stats.endtime-0.043)

st_all = obspy.Stream()
st_all += st1
st_all += st2
st_all += st3
st_all.decimate(5)
print(st_all)

3 Trace(s) in Stream:
BW.RJOB…EHZ | 2009-08-24T00:20:03.060000Z - 2009-08-24T00:20:32.910000Z | 20.0 Hz, 598 samples
BW.RJOB…EHN | 2009-08-24T00:20:03.030000Z - 2009-08-24T00:20:32.930000Z | 20.0 Hz, 599 samples
BW.RJOB…EHE | 2009-08-24T00:20:03.040000Z - 2009-08-24T00:20:32.940000Z | 20.0 Hz, 599 samples

st_all.trim(obspy.UTCDateTime("2009-08-24T00:20:03.15000Z"),obspy.UTCDateTime("2009-08-24T00:20:32.856000Z"))
print(st_all)

3 Trace(s) in Stream:
BW.RJOB…EHZ | 2009-08-24T00:20:03.160000Z - 2009-08-24T00:20:32.860000Z | 20.0 Hz, 595 samples
BW.RJOB…EHN | 2009-08-24T00:20:03.180000Z - 2009-08-24T00:20:32.880000Z | 20.0 Hz, 595 samples
BW.RJOB…EHE | 2009-08-24T00:20:03.140000Z - 2009-08-24T00:20:32.840000Z | 20.0 Hz, 595 samples

How do I get the same starting and ending time in this case (besides redownloading all data)?

Thanks!
Angel

Hi Angel,

your samples are not aligned due to the decimation step. In your example, you should move the decimate line to the end and it should work. If you have original data with unaligned samples you can use the interpolate method.

Thanks for your response! You are right. Moving the decimate line to the end should work for the streams with samples that are already aligned before (e.g., channels of the same station), but I guess I will have to use interpolation for different stations with unaligned samples in their original data.

Thanks again!