Slicing the large file

There is a continuous miniseed file of 10 days. I would like to slice it into a file of 1 day and want to save in miniseed format.

I tried the code

import glob                                 
from obspy.core.stream import read
from obspy.core import UTCDateTime

mseed_file = read("5daysfile.mseed")

stime=mseed_files[0].stats.starttime

for i in range(0,432000,86400):
    print(stime+(i),stime+(i)+86400)
    mseed_files.slice(stime+(i),stime+(i)+86400)

But it doesnot slice the data instead same data it appends.Any help is highly appreciated.Thanks.

No reply yet…Is it the right place to ask the question related to obspy…

It’s absolutely the right place. Please check out the documentation of Stream.slice():

https://docs.obspy.org/packages/autogen/obspy.core.stream.Stream.slice.html

Above code doesnt look too far off…

...
    tmp = mseed_files.slice(stime+(i),stime+(i)+86400)
    tmp.write(f'my_filename_{i}.mseed', format='MSEED')

You could make it a bit nicer though regarding times

start = min(tr.stats.starttime for tr in mseed_file)
end = max(tr.stats.endtime for tr in mseed_file)
year = start.year
doy = start.julday
t1 = UTCDateTime(f'{year:4d}-{doy:03d}T00:00:00')
while t1 < end:
    t2 = UTCDateTime(f'{year:4d}-{doy + 1:03d}T00:00:00')
    tmp = mseed_file.slice(t1, t2)
    tmp.write(..., format='MSEED')
    # move on
    doy += 1  # needs some more sophisticated logic if wrapping around new year, obviously
    t1 = UTCDateTime(f'{year:4d}-{doy:03d}T00:00:00')

@megies if possible please post the full code using my example data set.