Header information by using obspy.fdsn

Hi Tobias,

Thanks for your answer to my previous question. Following your instruction, I was able to get the station information and save it to tr.stats.sac as an AttribDict object. However, I still cannot figure out how to write the information in tr.stats.sac to my output SAC header. I guess maybe additional argument should be added to the write function. Any suggestions? Thanks.

from obspy.fdsn import Client
from obspy import UTCDateTime
from obspy.core.util import AttribDict

client = Client(“IRIS”)
t = UTCDateTime(“2011-09-10T06:45:00.000”)
st = client.get_waveforms(“XY”, “PTTY”, “", "”, t, t + 60)
inv = client.get_stations(starttime=t, endtime=t+60, network=‘XY’, station=‘PTTY’, location=’’, channel=’’, level=‘channel’)
print st
for tr in st:

#use our own filename convention

tmp = tr.id.split(’.’)
network = tmp[0]
sta = tmp[1]
channel = tmp[2]
comp = tmp[3]
fname = ‘.’.join([sta, comp, network, ‘–’])

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 sta:
if cha.code != tr.stats.channel or cha.location_code != tr.stats.location:
continue
print cha.code, cha.azimuth, cha.dip
sac = tr.stats.setdefault(“sac”, AttribDict())
sac[“CMPAZ”] = cha.azimuth
sac[“CMPINC”] = 90. - abs(cha.dip) #dip and CMPINC are not the same

print tr.stats.sac

tr.write(fname, format=‘SAC’)

Sorry about the late reply.. actually I checked right now and the SAC
dictionary in ObsPy has all lower case keys. So it works if you do
something like..

tr.stats.sac["cmpaz"] = 12
tr.stats.sac["cmpinc"] = 34

best,
T