Data converters: I have my seismic data and now wish to write to SAC

Hello everyone,

I’ve been quietly learning Python and I’m working on some data converters that I need to use with some Russian data. The data is written in a variation of Symmetric Research’s .DAT binary format called .OUT , so it needs converting so I can use some other tools besides waveform viewer.

I’ve imported the data into my Python code, and have the binary data for all four channels (time, Z, N, E) loaded into an array. I’ve called in the header information and have station names, channel names, a start time, a verified sample rate, GPS tics, station channel gain, etcetera now available in my program. I can probably also call up from an index the station coordinates and embed them if necessary.

I’m at the stage where I wish to roll all these arrays, calculated variables, and dictionaries into a series of SAC files. What I haven’t found within the ObsPy documentation is how to go about creating a new SAC file when one hasn’t yet been read. There’s plenty of information on how to read a pre-existing sac file, and how to write it out again, but what I need to know is how to generate one from scratch.

– I’m stuck on this one - and hoping there’s an easy method of creating the SAC wrapper around my existing data, like, declaring some sort of structure called SAC, and then filling it with my data fields.

Daniel Burk, Michigan State University

Hi Daniel,

To do that you'd need to use the low-level SacIO class which has a function fromarray:

Here's a short example:

from obspy.sac import SacIO
import numpy as np
t = SacIO()
b = np.arange(10)
# set the date to today

If you run the example above in an IPython console you can get the names of the header values with t? and the optional keywords for 'fromarray' with t.fromarray?.

Hope that helps.

I got it, Yannik!

I now have my first converted data file staring at me in all it’s seismological glory as a newly minted SAC file!

Thank you for your help, it was just what I needed. There are three or four file variants in my collection that are Russian variants of data originating from Symmetric Research seismic data acquisition systems.

Now I just need to put the finishing touches on this new converter, add the command line switches, integrate the other subflavors of this file format, bake in a little error checking, and voila! I’ll be in seismic heaven.

  • Daniel Burk

Michigan State University

Welcome to the Obspy Nirvana.