Hello everybody,
I have read that there exists a set of Python functions which allow
easy access to SAC files. After some extensive googling I have been
unable to locate anything other than a mention in the following
article: http://adsabs.harvard.edu/abs/2004AGUFM.S21A0273H
Can someone please point me in the correct direction so that I don't
spend time duplicating code?
TIA
Norman.
I have read that there exists a set of Python functions which allow
easy access to SAC files. After some extensive googling I have been
unable to locate anything other than a mention in the following
article: http://adsabs.harvard.edu/abs/2004AGUFM.S21A0273H
Can someone please point me in the correct direction so that I don't
spend time duplicating code?
TIA
Norman.
-
Hi Norman,
I have read that there exists a set of Python functions which allow
I also stumbled over that article and couldn't find any other mention of this
easy access to SAC files. After some extensive googling I have been
unable to locate anything other than a mention in the following
article: http://adsabs.harvard.edu/abs/2004AGUFM.S21A0273H
Can someone please point me in the correct direction so that I don't
spend time duplicating code?
code, that's why I wrote my own module: here it is. It's not very sophisticated
and also not much tested so far, so be prepared for surprises. It can only do IO
on binary SAC files.
Usage is like this:
import pysacio
sac = pysacio.SacFile('test.sac')
sac.delta
Access the data: it is returned as a NumPy array:
sac.data[0]
To simplify dealing with the reference time of the SAC file, I implemented this:
sac.get_ref_time()
File "<stdin>", line 1, in ?
File "/bonus/lib/python2.4/site-packages/pysacio.py", line 64, in get_ref_time
raise SacError('Not all header values for reference time are set.')
pysacio.SacError: Not all header values for reference time are set.
... aaah, OK, the time headers were not set in this file, so let's set them to
the current system time, for the demo:
import time
sac.set_ref_time(time.time())
sac.get_ref_time()
sac.nzyear
sac.nzjday
sac.nzhour
You can 'print' the SAC object:
print sac
b: 0.0
e: 2.0
nzyear: 2009
nzjday: 231
nzhour: 17
nzmin: 40
nzsec: 11
nzmsec: 993
nvhdr: 6
npts: 5
iftype: 1
leven: 1
lpspol: 0
lovrok: 1
lcalda: 1
unused17: 0
kevnm: -12345 -12345
And to write it to file:
sac.write('newfile.sac')
Sebastian