How to Convert SEED to SAC internally

Hi Users,

I’m trying to convert a seed file to sac,
format the sac headers, before writing to file.
Is there a way to do this?

I do not want to write to sac and read in before conversion.

Thanks,

Tolulope

Tolulope:

I think you will find what you need here: http://www.iris.edu/pub/programs/converters/

Best regards,

Tolulope,

I think ObsPy's "read" function can read a seed volume and return a Stream object, with traces that have miniSEED headers. You just need a dictionary that will convert between miniSEED and SAC header values. This is helped by the fact that miniSEED headers are so minimal. If you just need a starting place, https://github.com/obspy/obspy/blob/master/obspy/sac/sacio.py should help. I think each trace just needs a valid trace.stats.sac dictionary when you do "tr.write(filename, format='SAC'). If I remember correctly, though, ObsPy always writes SAC files that have a reference time relative to the first data sample, so and manipulating of SAC time fields may be overridden/invalid unless you assume this. If you're asking about event information, too, I don't know about that.

Best,
Jon

Hi Tolulope,

try use rdseed (http://www.iris.edu/dms/nodes/dmc/manuals/rdseed/).

Regards,
Hanka

Yea. I just need to add a valid SAC Dictionary and send it to the write function.
I’ll try to see if this works, but again the stream already has a MSEED format and a mseed dictionary.

Tolu.

If you want to convert MiniSEED, just reading it with ObsPy and writing
it to SAC format should be fine:

from obspy import read
st = read("filename")
st.write("new_filename", format="SAC")

If you are talking about full SEED, it is a different matter completely.

best,
Tobias

Hi Tolu,

the additional trace.stats attribute dictionaries like "mseed" do not matter when writing a different format. They are filled upon reading a certain format - thus you're objects have an mseed stats dictionary as they originate from MiniSEED or SEED files.

Upon writing ObsPy will read any attribute set in a dictionary with the name of the desired format. So writing a SAC file will take any value in trace.stats.sac into account.

As Jon already mentioned: be careful with some attributes. All sac specified attributes that can be inferred from the default trace.stats attributes (network, station, location, channel, ...) will always be taken from the Trace object and not the sac dictionary.

See this old mailing list entry for more details:

http://lists.swapbytes.de/archives/obspy-users/2012-August/000765.html

The following is a short example doing what you want:

In [1]: import obspy.core

In [2]: tr = obspy.core.read()[0]

In [3]: tr.stats.sac = obspy.core.AttribDict()

In [4]: tr.stats.sac.stel = 15.0

In [5]: tr.write("file.sac", format="sac")

In [6]: obspy.core.read("file.sac")[0].stats.sac.stel

All the best!

Lion