I am trying to convert multiple .MSEED files in a directory into .SAC files. My code loops over all the .MSEED files and read all of them, but it converts just the first .MSEED file into .SAC files. Is there anyway that I can write all of the .MSEED files into .SAC files at once? My code is attached below:
for data in readmseed:
print(data)
st=obspy.read(data, format=“MSEED”)
my_data.append(st)
for name in os.listdir(path):
print(name)
for msdata in my_data:
st=msdata.select(channel=“BH*”)
st+=msdata.select(channel=“HH*”)
print(st.str(extended=True))
for tr in st:
tr.write("/home/rauf/Desktop/SAC_data/"+name+"-"+tr.id, format=“SAC”)
I suspect the “tr.id” in your final write loop is not unique for each waveform in your stream. I would append a integer increasing segment number to the file name for each trace in the stream, and see if you’re writing them all.
It seems you missed the indentations. It should be like
for msdata in my_data:
st=msdata.select(channel=“BH*”)
st+=msdata.select(channel=“HH*”)
print(st.str(extended=True))
for tr in st:
tr.write(“/home/rauf/Desktop/SAC_data/”+name+“-”+tr.id, format=“SAC”)