[obspy-users] Fail to change encoding from sac to mseed
markwilliams at seismo.unr.edu
Wed Jun 5 18:27:49 CEST 2013
The type that miniSEED uses by default and for compression is integers, so
you need to convert your float32 array type before you try to encode it:
>>> import numpy
>>> st.data = numpy.array(st.data, dtype=numpy.int32)
I believe there is also an easy way to do this in obspy.core.read. Try this:
>>> st = read('OBSB19-1.sac', dtype='int32')
>>> st.write('out.mseed', format='MSEED', encoding='STEIM2')
You do need to be careful about altering data in conversions like this, I
am not very familiar with how SAC formats things internally, it looks like
from your example, there are no decimal places in your data, so this
solution should work for you.
Nevada Seismological Laboratory
Nevada Seismic Network
University of Nevada, Reno
On Wed, Jun 5, 2013 at 6:12 AM, Wang, Xiao <Xiao.Wang at liverpool.ac.uk>wrote:
> I got sac file and want to convert in mseed file with different encoding
> by using obspy stream. But I failed. The dtype of sac file is float32 and I
> want to convert to STEIM2 in mseed file, and I am using python 2.6.
> Any idea?
> Thanks in advance,
> The following is the output when I try to convert.
> Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56)
> [GCC 4.4.3] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> from obspy import read
> >>> st=read('OBSB19-1.sac')
> >>> st.write('out.mseed', format='MSEED', encoding='STEIM2')
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> File "/usr/lib/pymodules/python2.6/obspy/core/stream.py", line 1279, in
> writeFormat(self, filename, **kwargs)
> File "/usr/lib/pymodules/python2.6/obspy/mseed/core.py", line 536, in
> raise Exception(msg)
> Wrong dtype for Stream.data for encoding STEIM2.
> Please change the dtype of your data or use an
> encoding. See the obspy.mseed documentation for more
> >>> st.data
> array([-160786., -135037., -160595., ..., -178665., -122117., -66691.],
> obspy-users mailing list
> obspy-users at lists.swapbytes.de
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the obspy-users