[obspy-users] write SAC data to file

Tobias Megies megies at geophysik.uni-muenchen.de
Thu Nov 8 15:29:28 CET 2012


Hello Ahu,

SAC stores one trace per file, so a st.write() cannot just use the given
name but has to add generic suffixes. To have more control over
filenames just loop over the traces and build your own filenames, e.g.:

for tr in st:
    fname = "%s.sac" % tr.id
    st.write(fname, format="SAC")

Beware, this could overwrite the file again if more traces with same ID
are present. Or try:

ids = set([tr.id for tr in st])
for id in ids:
    fname = "%s.sac" % id
    st.select(id=id).write(fname, format="SAC")

Which would enumerate filenames for multiple traces with the same ID.

best,
Tobias

On 08/11/12 15:16, Ahu Komec Mutlu wrote:
> 
> Hello,
> 
> I read SAC data and did some changes on that data then I want to write
> it to a file, here my code:
> 
> from obspy.core import read
> from obspy.core import UTCDateTime
> st = read("20111023_1041/2011*", format="SAC")
> print(st.__str__(extended=True))
> st.resample(50.0)
> EventOriginTime = UTCDateTime("2011-10-23T10:41:19")
> st.trim(EventOriginTime, EventOriginTime+360)
> st.write("van.sac", format="SAC")
> 
> it works but output file names are not include station name and
> component information, they are like :
> 
> van01.sac      van04.sac
> van02.sac      van05.sac
> 
> How can I write the SAC data to new file with name like
> AFSR.BHE.sac
> AFSR.BHN.sac
> AFSR.BHZ.sac
> 
> (stationname.component.sac)
> 
> Thanks & Regards
> 
> -------------------------
> 
> AHU KOMEC MUTLU
> Bogazici University Kandilli Observatory & E.R.I.
> Cengelkoy / ISTANBUL
> 
> Phone: +(90) 216 516 32 16
> 
> -------------------------
> 
> 
> 
> _______________________________________________
> obspy-users mailing list
> obspy-users at lists.sevor.de
> http://lists.obspy.org/cgi-bin/mailman/listinfo/obspy-users

-- 
Dipl.-Geophys. Tobias Megies

Geophysikalisches Observatorium
Ludwigshöhe 8
82256 Fürstenfeldbruck

Ludwig-Maximilians-Universität
Department für Geo- und Umweltwissenschaften
Sektion Geophysik
Theresienstrasse 41/IV
80333 München

Tel: +49 (0) 89 2180-73981
     +49 (0) 89 2180-4326
Mail: tobias.megies at geophysik.uni-muenchen.de




More information about the obspy-users mailing list