Empty sac file object

Hello,

I’ve been struggling to convert raw binary data into a sac file.

Is there a way to create an empty object with default SAC header values easily? If there is, I can just put the time series that I got from the binary file into the data array of the trace object and write the file, which would be great.

Cheers,

Hi Yaman,

Actually you should not try to make a SAC but to load your data into a Trace object.

from obspy.core import Trace, AttribDict
newt = Trace()

trace.stat <- is the header

trace.data <- is the data as NdARRAY

Also, you can fill in more sac header attributes before save it doing so …

if not hasattr(trace.stats,“sac”):
trace.stats.sac = AttribDict({})

Event parameters

trace.stats.sac[‘o’] = evp.time - trace.stats.starttime
trace.stats.sac[‘evla’] = -20.0
trace.stats.sac[‘evlo’] = -120
trace.stats.sac[‘evdp’] = 100
trace.stats.sac[‘kevnm’] = “SomeString”

in the end

trace.write(“Somefile.sac”, format=“SAC”)

regards,

Marcelo

ps. I just wrote the recipe from my head and some copy and paste from some scripts i use so can have some small inconsistencies but the general idea is there.