Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ObsPy: Save Stream as SAC files #300

Open
seisman opened this issue Apr 7, 2024 · 0 comments
Open

ObsPy: Save Stream as SAC files #300

seisman opened this issue Apr 7, 2024 · 0 comments

Comments

@seisman
Copy link
Member

seisman commented Apr 7, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant