instrument correction and mseed encoding

Hi,
I need to work on instrument corrected traces with a program that reads
only mseed files with encoding STEIM1 or 2.
the function of Obspy for instrument correction returns float64 numbers.
When I try to save the data, I´ve downloaded , in MSEED with encoding =10
or 11
I get an error message.
Any solution to that?

thanks

Luigia

Below are the commands I use to download and save the data and the error
message:

........................

import numpy as np
import matplotlib.pyplot as plt
from obspy.core import read, UTCDateTime, Stream, Trace
from obspy.arclink import Client
from obspy.signal import cornFreq2Paz, seisSim

# Retrieve waveforms via ArcLink
client = Client(host="webdc.eu", port=18001)
t = UTCDateTime("2009-08-24 00:20:03")
st = client.getWaveform('BW', 'RJOB', '', 'EHZ', t, t+30)
paz = client.getPAZ('BW', 'RJOB', '', 'EHZ', t, t+30)
paz = paz.values()[0]

# Correct for frequency response of the instrument
res = seisSim(st[0].data, st[0].stats.sampling_rate, paz, inst_sim=None) #
Correct for overall sensitivity
res=(res / paz['sensitivity'])

#save corrected in MSEED 5 encoding float 32 , 10 encoding STEIM1
stcorr = Stream([Trace(data=res, header=st[0].stats)])
stcorr.write("prova.mseed", format='MSEED', encoding=10)

Exception:
                    Wrong dtype for Stream[0].data for encoding STEIM1.
Please change the dtype of your data or use an
appropriate
                    encoding. See the obspy.mseed documentation for more
information.

Hi Luigia,

I am not sure whether this makes sense semantically, but typecasting gets me around the type error at least:

stcorr = Stream([Trace(data=res.astype('int32'), header=st[0].stats)])

Cheers,
Martin

Hi,

the error is raised on purpose because Steim 1/2 compression is only
working for int32 data values - a explicit type conversion before
saving the data as proposed by Martin is the correct solution for now.

Although I think it is safe option for a future version of obspy.mseed
to have an automatic type conversion using the Stream.write() method
combined with a UserWarning.

Cheers,
Robert

Hi Luigia,

I am not sure whether this makes sense semantically, but
typecasting gets me around the type error at least:

stcorr = Stream([Trace(data=res.astype('int32'),
header=st[0].stats)])

Cheers, Martin

Hi, I need to work on instrument corrected traces with a program
that reads only mseed files with encoding STEIM1 or 2. the
function of Obspy for instrument correction returns float64
numbers. When I try to save the data, I´ve downloaded , in MSEED
with encoding =10 or 11 I get an error message. Any solution to
that?

thanks

Luigia

Below are the commands I use to download and save the data and
the error message:

........................

import numpy as np import matplotlib.pyplot as plt from
obspy.core import read, UTCDateTime, Stream, Trace from
obspy.arclink import Client from obspy.signal import
cornFreq2Paz, seisSim

# Retrieve waveforms via ArcLink client = Client(host="webdc.eu",
port=18001) t = UTCDateTime("2009-08-24 00:20:03") st =
client.getWaveform('BW', 'RJOB', '', 'EHZ', t, t+30) paz =
client.getPAZ('BW', 'RJOB', '', 'EHZ', t, t+30) paz =
paz.values()[0]

# Correct for frequency response of the instrument res =
seisSim(st[0].data, st[0].stats.sampling_rate, paz,
inst_sim=None) # Correct for overall sensitivity res=(res /
paz['sensitivity'])

#save corrected in MSEED 5 encoding float 32 , 10 encoding
STEIM1 stcorr = Stream([Trace(data=res, header=st[0].stats)])
stcorr.write("prova.mseed", format='MSEED', encoding=10)

Exception: Wrong dtype for Stream[0].data for encoding STEIM1.
Please change the dtype of your data or use an appropriate
encoding. See the obspy.mseed documentation for more
information.

_______________________________________________ obspy-users
mailing list obspy-users@lists.sevor.de
http://lists.obspy.org/cgi-bin/mailman/listinfo/obspy-users

_______________________________________________ obspy-users mailing
list obspy-users@lists.sevor.de
http://lists.obspy.org/cgi-bin/mailman/listinfo/obspy-users

- --
Dr. Robert Barsch

EGU Office Munich
Luisenstr. 37
80333 Munich
Germany

Phone: +49-89-21806549
Fax: +49-89-218017855
eMail: admin@egu.eu

Thanks for the suggestion,
but I cannot use data=res.astype('int32') because res is an array of
numbers < 1.

Luigia

Quick and dirty: multiply it by a large number :slight_smile:

Martin

Hey Luigia,

STEIM1 and STEIM2 are integer compression algorithms so a MiniSEED file using either
of those encodings can only store integer numbers.

A possible solution in your case would be to multiply the data with 1000, or 1E6 depending
on the desired accuracy. Do not go much higher because STEIM1 + 2 compressions use
(at the max) 32 bit integers and you want to avoid a possible integer overflow.

MiniSEED is as far as I know also not able to store a simple calibration factor so you would need
to remember the calibration factor in some way.

Lion