converting in format readable from obspy?

Hello, I have a database with various seismological stations from which I get two columns: one of seconds passed since 2000 and one of a value (in this case a rsam). Basically, I’d need to plot this against the seconds.

So given the easiness of the task I would probably be better off using matplotlib, but I would like to use obspy for future enhancenment of the program (applying filters etc.)

My question is: I get the data out of the database into a text file formatted likeso:

349876790 37.10712
349876791 36.446167
349876792 42.14655
349876793 43.04946

how do I convert it to a readable format from obspy? I’m ok on converting the number of seconds in a date, I just need to know which format.

Please be easy on me since I’m two times newbie: I actually am a mathematician so I’m ignorant in seismology and I’m a newbie in python


Hi Renato,

you can load the data of the second column using np.loadtxt. As far as I
can see you have one sample every second so just initialize an ObsPy
Trace object with the data, starttime and sampling_rate of 1 Hz.

import numpy as np
data = np.loadtxt("file", usecols=[1])
from obspy.core import *
sec_after_2k = int(open("file").readline().split()[0])
t = UTCDateTime(2000, 1, 1) + sec_after_2k
header = {'sampling_rate': 1.0, 'starttime': t}
tr = Trace(data, header)


Renato Budinich wrote:

thanks, worked like a charm :slight_smile: using obspy seems will make my life much easier - before I was using octave and had to manage many more things myself