Qustion about write SacIO

Dear forum.
Thank for the time you spend reading it, I have a question about SacIO module.

I hava data in X Y ascii format, I mean X is the time and Y is the
amplitudes of an seismic event.

--------------Event X_Y.ascii-------------------------
3.000000E-001 -1.350703E-009
3.500000E-001 2.278956E-009
4.000000E-001 1.296893E-009
4.500000E-001 -3.974883E-011
5.000000E-001 -1.121285E-009
5.500000E-001 -5.879399E-010

Hi Gonzalo,

we actually discourage using the interal file format functionality like SacIO. Better use our Stream/Trace classes.

Also you’re code snippet contains a couple of errors I believe. You first need to actually parse the ASCII file you have and then you can save it in whatever format you want.

Untested code snippet that should do what you want (you will most likely want to extend the header):

import numpy as np
import obspy

time, data = np.loadtxt("./Event_X_Y.ascii").T

# Estimate sample spacing.
delta = np.diff(time).mean()

tr = obspy.Trace(data=data, header={"delta": delta})
tr.write("output.sac", format="SAC”)