[obspy-users] Adding time array to output_ASCII file

Lion Krischer krischer at geophysik.uni-muenchen.de
Thu Apr 20 12:18:53 CEST 2017


Hi Tonino,

I guess its just a floating point accuracy issue. I attached a version
that avoid it.

Cheers!

Lion


On 16.04.17 18:25, gonzalo antonio fernandez marañon wrote:
> Dear Obspy team,
> I am working in SPAC resrarch, there is a software that need the
> inputs file in this format
>
> STATION_NAME --Header
> SPS -- Header
> UNITS -- Header
>
> # NUmber       #time                #Count
> 1                 10:34:23.0000      -76262
> 2                 10:34:23.0025      -65533
> .....
>
> Following the obspy tutorial I've found that I can export from a
> seismic format (mseed) to ascii with the following code
> from __future__ import print_function
> import sys, os
> import numpy as np
> import obspy
>
> try:
>     in_file=sys.argv[1]
>     out_file=sys.argv[2]
>     calibration=float(sys.argv[3])
> except:
>     print(__doc__)
>     raise
> st=obspy.read(in_file)
> for i, tr in enumerate(st):
>     f=open("%s %d" % (out_file,i),"w")
>     t=np.linspace(0,tr.stats.npts/tr.stats.sampling_rate,tr.stats.delta)
>     f.write("# Estacion: %s\n" % (tr.stats.station))
>     f.write("# Freq_muestreo: %f\n" % (tr.stats.sampling_rate))
>     f.write("Cuentas %s\n" % (tr.stats.npts))
>     np.savetxt(f,np.transpose([t,tr.data *calibration]),fmt="%f")
>     f.close()
>
>
> so, I added the "t" array to have the time/points in X axis and
> I inserted in the output file the t array to have this output
>
> # Estacion: DS2
> # Freq_muestreo: 40.000000
> # Cuentas 23942
> 0.000000 -1160.000000
> 0.025000 -1480.000000
> 0.050000 -1221.000000
> 0.075000 -880.000000
> 0.100000 -901.000000
> .....
>
> I need to have the time instead of having the array t = [0.0000,
> 0.02500, 0.05000, ....], so I did the following code:
>
> ti=tr.stats.starttime
> tf=tr.stats.endtime
> t_step=datetime.timedelta(tr.stats.delta)
> T=[]
> while ti<=tf:
>     T.append(ti.strftime('%H:%M:%S.%f'))
>     ti +=t_step
>
> but I do not get the same quantity of points as the data, so I am not
> able to plot
> npts=23942
> T_npts=23941
>
> Can someone give a hand to solve this litle problem?.
> Thanks in advance.
> Tonino
> _______________________________________________
> obspy-users mailing list
> obspy-users at lists.swapbytes.de
> http://lists.swapbytes.de/mailman/listinfo/obspy-users

-------------- next part --------------
A non-text attachment was scrubbed...
Name: do_it.py
Type: text/x-python-script
Size: 532 bytes
Desc: not available
URL: <http://lists.swapbytes.de/pipermail/obspy-users/attachments/20170420/f082e65c/attachment.bin>


More information about the obspy-users mailing list