How to split in minutes a mseed file of 1 day

Dear all,

I am pretty new here and just discover the obspy project. I did succeed in installation and read, filter some files.

I would like to know if there a way to split a mseed (or segy) file of 24 hours in minutes (so 1440 files). The file is at 100 Hz so i could also split the file in sample (each 6000 sample for instance).

I did try the cutout fonction but it seems to use only UTCTime so not a length or number of samples.

If someone can give me a tip, I will be very greatful.

Thank you

Franz

You could do this in a simple loop, could look kind of like…

t = UTCDateTime(...)
end = UTCDateTime(...)
st = read(...)

while t < end:
    tmp = st.slice(t, t+3600)
    tmp.write(...)
    t += 3600

Dear Megies,

Many thanks for your answers. I will have a try.

I also try this way :

from obspy import read
tr= read(“C:\Data*.mseed”)[0]
print(tr)
st = tr / 1440
print (st)
for tr in st:
tr.write(tr.id + “C:\Data\out.mseed”)

It seems to cut the stream in 1440 traces, what I want to do, but now I would like to save each trace as a separate file and my last command seems not good.

You can consider using the start time to write the mseed file:

for tr in st:
     start_time = tr.stats.starttime
     tr.write(str(start_time)+".mseed")

Dear,

Thanks for your answers. You give me the right tip, it was not working because I am on windows and file with dot is not good but I manage to do it like this :

from obspy import read
tr= read(“C:\Data*.mseed”)[0]
print(tr)
st = tr / 1440
print (st)
for tr in st:
filename = tr.stats.starttime.strftime(‘%Y%m%d_%H.%M’)
tr.write(filename)

Thank you for your help.

Now I am trying to convert mseed in segy file, I will may open an other question.