-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Description
We can use Trace.write
to save traces into SAC files, but the SAC files don't have event and station information. Below is codes that I've used for some while to save SAC files that have event and station information. I think it's useful and should be documented.
Path(f"SAC/{ev.id}").mkdir(parents=True, exist_ok=True)
for tr in st:
sac = SACTrace.from_obspy_trace(tr)
# set event information
sac.evla = ev.latitude
sac.evlo = ev.longitude
sac.evdp = ev.depth
sac.mag = ev.magnitude
sac.reftime = ev.origin
sac.o = 0.0
sac.iztype = "io"
# set station information
coord = inv.get_coordinates(tr.id, datetime=ev.origin)
sac.stla = coord["latitude"]
sac.stlo = coord["longitude"]
sac.stel = coord["elevation"]
sac.stdp = coord["local_depth"]
# set channel orientation
orient = inv.get_orientation(tr.id, datetime=ev.origin)
# Need to cautious with the different definitions of 'dip'
# In ObsPy, 'dip' is degrees, down from horizontal [-90, 90]
# In SAC, 'dip' is degrees, down from vertical-up [0, 180]
sac.cmpinc = orient["dip"] + 90.0
sac.cmpaz = orient["azimuth"]
# set SAC header
sac.lcalda = True # calculate distance, azimuth and back-azimuth in saving
print(f"SAC/{ev.id}/{tr.id}.SAC")
sac.write(f"SAC/{ev.id}/{tr.id}.SAC")
Code from https://github.com/seisman/DDRelocator/blob/main/examples/ex2/process_data.py
Metadata
Metadata
Assignees
Labels
No labels