[obspy-users] Fail to change encoding from sac to mseed

Mark Williams markwilliams at seismo.unr.edu
Wed Jun 5 18:27:49 CEST 2013


Hi Xiao,

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[0].data = numpy.array(st[0].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.

-Mark

Mark Williams
Nevada Seismological Laboratory
Nevada Seismic Network
University of Nevada, Reno
tel: (775)-784-4317


On Wed, Jun 5, 2013 at 6:12 AM, Wang, Xiao <Xiao.Wang at liverpool.ac.uk>wrote:

>  Hello,
>
> 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,
>
> Xiao
>
>
> 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
> write
>     writeFormat(self, filename, **kwargs)
>   File "/usr/lib/pymodules/python2.6/obspy/mseed/core.py", line 536, in
> writeMSEED
>     raise Exception(msg)
> Exception:
>                     Wrong dtype for Stream[0].data for encoding STEIM2.
>                     Please change the dtype of your data or use an
> appropriate
>                     encoding. See the obspy.mseed documentation for more
>                     information.
>
> >>> st[0].data
> array([-160786., -135037., -160595., ..., -178665., -122117.,  -66691.],
> dtype=float32)
> >>>
>
>
> _______________________________________________
> obspy-users mailing list
> obspy-users at lists.swapbytes.de
> http://lists.swapbytes.de/mailman/listinfo/obspy-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.swapbytes.de/pipermail/obspy-users/attachments/20130605/08074f5b/attachment.html>


More information about the obspy-users mailing list