Time selection

Hello everybody,

is there any way in ObsPy to select only a given timeframe from a Stream without using the "read" function? Or write only a certain timeframe of a Stream into a file?

I have a rather large Stream object (21 stations @ 200Hz, 24 hours), that I do not want to write into a file (it is a merger of many small Streams). Instead, I'd like to cut this Stream into hourly pieces and write those hourly pieces into MSEED files. Is there any way I can do this?

Thanks a lot and kind regards,


Hi Florian,

I think the slice method of Stream is what you search for.

stream = read(‘long_stream.mseed’)
t1 = stream[0].stats.starttime
t2 = stream[0].stats.endtime
i = 0
while t1 < t2:
stream.slice(t1, t1+3600).write(‘short_stream_%004d’ % i, ‘MSEED’)
t1 += 3600
i += 1

Good luck,