Data procesing of X Y data set

Hi folks

I would have a relatively simple question, for which I still haven’t found an answer, though. How can I turn an X Y acceleration dataset into a trace format so I can perform all the data-processing procedures on it (filtering and so on)?

The thing is, I would like to use ObsPy to analyse the results of my seismic numerical models, but all I get is a regularly sampled acceleration dataset (plus the time coordinates of the corresponding points), rather than any real seismic data format.

Thanks a lot for help

Cheers

Lukas Janku

University of Canterbury

Hi Lukas,

here is a simple example of how to enter data into a trace and stream object:

from obspy.core import stream,trace

data = np.random.random(100)
tr = trace.Trace(data)
st = stream.Stream(tr)

print st

Metadata can then be simply inserted into tr.stats which acts like a dictionary.

If your sampling of the time coordinate is not linear in your dataset, you can first use the interpolation module of scipy to get it into an equidistant form.

Hope that solves your problem.

Cheers,
Martin

In addition to what Martin wrote and assuming your data looks like the ASCII files from SPECFEM, the following function reads a file to a Stream object:

import numpy as np
import obspy

def read_specfem_ascii_waveform_file(filename, network, station, channel):
"""
Reads SPECFEM ASCII files to a :class:`~obspy.core.stream.Stream` object.
:param filename: The filename.
:type filename: str
:param network: The network id of the data.
:type network: str
:param station: The station id of the data.
:type station: str
:param channel: The channel id of the data.
:type channel: str
"""
time_array, data = np.loadtxt(filename).T
# Try to get a reasonably accurate sample spacing.
dt = np.diff(time_array).mean()

tr = obspy\.Trace\(data=data\)
tr\.stats\.network = network
tr\.stats\.station = station
tr\.stats\.channel = channel
tr\.stats\.delta = dt
tr\.stats\.starttime \+= time\_array\[0\]

return obspy\.Stream\(traces=\[tr\]\)

Cheers!

Lion