Hi All,
Our group is in the process of upgrading to v1.0.0. Most of our scripts work as expected (with a few warnings), but there is one operation that is causing some strange behaviour.
What we are doing is reading in a miniseed file, performing some operations on the stream, and then writing it out as a sac file. Prior to writing the sac file, we want to add the station coordinates to the sac header. Previously (ie 0.10.2), we have done this as follows:
for tr in st:
tr.stats.sac=AttribDict()
tr.stats.sac.stla = sta.stla
tr.stats.sac.stlo = sta.stlo
tr.write((fname,format=‘SAC’)
This would work fine, with the resulting sac file containing the correct origin time and B values, as well as the station coordinates.
After upgrading to v1.0.0, the same operation no produces an error when writing the sac file.
“UserWarning: Old header has invalid reftime.”
The write operation will complete successfully, and the SAC file is written to disk. However, the starttime and endtime are no longer correct, with the start time set to a default value of “1970-01-01T00:00:00.000000Z”.
For instance, reading in the sac file that was just written and viewing the stats gives:
trnew=read(fname,format=‘SAC’)
print trnew.stats
network: BP
station: CCRB
location:
channel: BP1
starttime: 1970-01-01T00:00:00.000000Z
endtime: 1970-01-01T23:59:59.950000Z
sampling_rate: 20.0
delta: 0.05
npts: 1728000
calib: 1.0
_format: SAC
sac: AttribDict({u’lpspol’: 0, u’iftype’: 1, u’stla’: 35.957199, u’leven’: 1, u’nvhdr’: 6, u’stlo’: -120.5516, u’depmen’: -12812.165, u’depmin’: -14073.0, u’kstnm’: u’CCRB’, u’depmax’: -10348.0, u’npts’: 1728000, u’lovrok’: 1, u’knetwk’: u’BP’, u’delta’: 0.050000001, u’e’: nan, u’lcalda’: 1, u’kcmpnm’: u’BP1’})
The stla and stlo are in the header as they should be, but the start and end times are incorrect.
On the other hand, if we don’t set the station coordinates, ie, do not initialize the AttribDict() in tr.stats.sac, then the trace writes out correctly with no warnings, and reading the trace in again shows it has the correct start and end times.
trnew2=read(fname,format=‘SAC)
print trnew2.stats
network: BP
station: CCRB
location:
channel: BP1
starttime: 2003-01-01T00:00:00.023800Z
endtime: 2003-01-01T23:59:59.973800Z
sampling_rate: 20.0
delta: 0.05
npts: 1728000
calib: 1.0
_format: SAC
sac: AttribDict({u’knetwk’: u’BP’, u’nzyear’: 2003, u’nzjday’: 1, u’iztype’: 9, u’nzhour’: 0, u’lcalda’: 1, u’iftype’: 1, u’nvhdr’: 6, u’depmin’: -14073.0, u’kcmpnm’: u’BP1’, u’nzsec’: 0, u’depmen’: -12812.165, u’depmax’: -10348.0, u’lovrok’: 1, u’scale’: 1.0, u’delta’: 0.050000001, u’nzmsec’: 23, u’lpspol’: 0, u’b’: 0.00079999998, u’e’: 86399.953, u’leven’: 1, u’kstnm’: u’CCRB’, u’nzmin’: 0, u’npts’: 1728000})
But now we don’t have the station coordinates (or other variables we may wish to populate.
My question is, how do we go about adding metadata to the SAC header fields to a trace that is read in (either using fdsn client or from a local miniseed file), and write the file out as a SAC file?
Thanks very much,
Andrew