Header information by using obspy.fdsn

Hi,

I am now using FDSN web service from Obspy to download data from IRIS. Then I write all the traces to SAC files based on the trace id. See code below. However, when I check the header of the SAC files I got, it seems that the “CMPAZ” and “CMPINC” values for all traces are set to 0. Do you have any idea about how to get the right header information? Thanks.

from obspy.fdsn import Client
from obspy import UTCDateTime
client = Client()
t = UTCDateTime("2011-09-10T06:45:00.000")
st = client.get_waveform("XY", "PTTY", "*", "*", t, t + 60)

print st
for tr in st:                                                                                                              
    tmp = tr.id.split('.')
    network = tmp[0]
    sta = tmp[1]

    channel = tmp[2]
    comp = tmp[3]
    fname = '.'.join([sta, comp, network, '--'])
    tr.write(fname, format='SAC')

>>
3 Trace(s) in Stream:
XY.PTTY..EL1 | 2011-09-10T06:45:00.000000Z - 2011-09-10T06:46:00.000000Z | 200.0 Hz, 12001 samples

XY.PTTY..EL2 | 2011-09-10T06:45:00.000000Z - 2011-09-10T06:46:00.000000Z | 200.0 Hz, 12001 samples
XY.PTTY..ELZ | 2011-09-10T06:45:00.000000Z - 2011-09-10T06:46:00.000000Z | 200.0 Hz, 12001 samples

Best,

Qimin

Judging from the SAC manual these two header fields are about sensor
orientation. The waveforms we fetch via get_waveforms() are served as
MiniSEED by FDSN servers, and I don't think MiniSEED includes
information about sensor orientation.

You would need to fetch station metadata and fill in those sac header
fields from there, I think.. with something like.. (untested and a bit
ugly, please check/verify)

st = client.get_waveforms(..)
inv = client.get_stations(..)
from obspy.core.util import AttribDict
for tr in st:
    for net in inv:
        if net.code != tr.stats.network:
            continue
        for sta in net:
            if sta.code != tr.stats.station:
                continue
            for cha in st:
                if cha.code != tr.stats.channel or cha.location_code !=
tr.stats.location:
                    continue
                sac = tr.stats.setdefault("sac", AttribDict())
                sac["CMPAZ"] = cha.azimuth
                sac["CMPINC"] = cha.dip
st.write("mydata.sac", "SAC")

hope it help,
Tobias