# Data procesing of X Y data set

**URL:** <https://discourse.obspy.org/t/data-procesing-of-x-y-data-set/416>\
**Category:** Users Mailing List Archive\
**Tags:** archive\
**Created:** [May 27, 2015, 7:32pm UTC](https://discourse.obspy.org/t/data-procesing-of-x-y-data-set/416 "2015-05-27T19:32:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lukas\_Janku](https://discourse.obspy.org/letter_avatar_proxy/v4/letter/l/76d3ee/32.png) [@Lukas\_Janku](https://discourse.obspy.org/u/Lukas_Janku)\
**Post date:** [May 27, 2015, 7:32pm UTC](https://discourse.obspy.org/t/data-procesing-of-x-y-data-set/416/1 "2015-05-27T19:32:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Martin\_Gal](https://discourse.obspy.org/letter_avatar_proxy/v4/letter/m/a698b9/32.png) [@Martin\_Gal](https://discourse.obspy.org/u/Martin_Gal)\
**Post date:** [May 28, 2015, 12:12am UTC](https://discourse.obspy.org/t/data-procesing-of-x-y-data-set/416/2 "2015-05-28T00:12:21Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![LionKrischer](https://discourse.obspy.org/user_avatar/discourse.obspy.org/lionkrischer/32/219_2.png) [@LionKrischer](https://discourse.obspy.org/u/LionKrischer)\
**Post date:** [May 28, 2015, 3:50pm UTC](https://discourse.obspy.org/t/data-procesing-of-x-y-data-set/416/3 "2015-05-28T15:50:51Z")

</div>

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
