[obspy-users] convert sac to wav

mbyt random.seed at web.de
Mon May 12 20:31:41 CEST 2014


Hello,

the WAV format is written by default as int32. And by default obspy
does not rescale the data. Most probable, your WAV file viewing tool
limits the yaxis to maximum [-1, +1], which corresponds to integer
[-2**31-1, 2**31-1].  If you zoom in a lot (approx factor 2E+9), you
will see the data.

To rescale the data to [-1, +1] use the rescale flag of st.write::

  from obspy.core import read
  st = read('http://examples.obspy.org/RJOB_061005_072159.ehz.new')
  st.write('myfile.wave', format='WAV', framerate=7000, rescale=True)

See also:
http://docs.obspy.org/packages/autogen/obspy.wav.core.writeWAV.html#obspy.wav.core.writeWAV


Cheers,
mbyt

On Sun, May 11, 2014 at 01:09:13PM -0700, Robin Matoza wrote:
> Hi,
> 
> Not sure if this helps, but with scipy.io.wavfile, you have to normalize and scale the amplitudes like in the example below.
> 
> Robin
> 
> import scipy.io.wavfile as wav
> 
> xspd  = 200.                                                # speed up by factor of 200
> fswav = fs*xspd
> wscal = p[0:M]/max(np.absolute(p[0:M]))   # scale to -1 <= p <= 1; p is vector length M
> wscal = 0.99*wscal                                     # avoid clipping
> convert_16_bit = float(2**15)                      # convert to int16 format for wavwrite
> wscal = np.int16( wscal * convert_16_bit ) # convert to int16 format for wavwrite
> wav.write('audio.wav',fswav,wscal)
> 
> 
> > Message: 1
> > Date: Sat, 10 May 2014 13:54:25 +0200
> > From: Tobias Megies <megies at geophysik.uni-muenchen.de>
> > To: users at obspy.org
> > Subject: Re: [obspy-users] convert sac to wav
> > Message-ID: <536E1371.2020305 at geophysik.uni-muenchen.de>
> > Content-Type: text/plain; charset=ISO-8859-1
> > 
> > This looks like a bug to me, so I've opened a ticket to track this
> > issue, see https://github.com/obspy/obspy/issues/791.
> > 
> > best,
> > Tobias
> > 
> > 
> > On 05/09/2014 11:01 PM, RJ wrote:
> >> Dear list,
> >> 
> >> I'm trying to convert sac to wav format, eg
> >> http://docs.obspy.org/packages/obspy.wav.html
> >> 
> >> My code below creates a wav file of 141KB but it's a flat line.
> >> from obspy.core import read
> >> st = read('http://examples.obspy.org/RJOB_061005_072159.ehz.new')
> >> st.write('myfile.wave', format='WAV', framerate=7000)
> >> 
> >> The input is a seismogram so I don't expect a flat output. Any suggestions?
> >> 
> >> R
> >> _______________________________________________
> >> obspy-users mailing list
> >> obspy-users at lists.swapbytes.de
> >> http://lists.swapbytes.de/mailman/listinfo/obspy-users
> >> 
> > 
> > -- 
> > Dipl.-Geophys. Tobias Megies
> > 
> > Geophysikalisches Observatorium
> > Ludwigsh?he 8
> > 82256 F?rstenfeldbruck
> > 
> > Ludwig-Maximilians-Universit?t
> > Department f?r Geo- und Umweltwissenschaften
> > Sektion Geophysik
> > Theresienstrasse 41/IV
> > 80333 M?nchen
> > 
> > Tel: +49 (0) 89 2180-73981
> >     +49 (0) 89 2180-4326
> > Mail: tobias.megies at geophysik.uni-muenchen.de
> > 
> > 
> > ------------------------------
> > 
> > Message: 2
> > Date: Sat, 10 May 2014 21:33:56 +0200
> > From: Thomas Lecocq <thomas.lecocq at seismology.be>
> > To: obspy-users at lists.swapbytes.de
> > Subject: Re: [obspy-users] convert sac to wav
> > Message-ID: <536E7F24.1040804 at seismology.be>
> > Content-Type: text/plain; charset=ISO-8859-1; format=flowed
> > 
> > Hey all,
> > 
> > for what I remember of my tests writing WAV, the data has to be 
> > normalized to some value in order to match WAV specification, and this 
> > is not done internally by obspy, resulting in the error mentionned : a 
> > buggy file...
> > 
> > HTH,
> > 
> > Tom
> > 
> > Le 10/05/2014 13:54, Tobias Megies a ?crit :
> >> This looks like a bug to me, so I've opened a ticket to track this
> >> issue, see https://github.com/obspy/obspy/issues/791.
> >> 
> >> best,
> >> Tobias
> >> 
> >> 
> >> On 05/09/2014 11:01 PM, RJ wrote:
> >>> Dear list,
> >>> 
> >>> I'm trying to convert sac to wav format, eg
> >>> http://docs.obspy.org/packages/obspy.wav.html
> >>> 
> >>> My code below creates a wav file of 141KB but it's a flat line.
> >>> from obspy.core import read
> >>> st = read('http://examples.obspy.org/RJOB_061005_072159.ehz.new')
> >>> st.write('myfile.wave', format='WAV', framerate=7000)
> >>> 
> >>> The input is a seismogram so I don't expect a flat output. Any suggestions?
> >>> 
> >>> R
> >>> _______________________________________________
> >>> obspy-users mailing list
> >>> obspy-users at lists.swapbytes.de
> >>> http://lists.swapbytes.de/mailman/listinfo/obspy-users
> >>> 
> > 
> > 
> > 
> > ------------------------------
> > 
> > _______________________________________________
> > obspy-users mailing list
> > obspy-users at lists.swapbytes.de
> > http://lists.swapbytes.de/mailman/listinfo/obspy-users
> > 
> > End of obspy-users Digest, Vol 42, Issue 7
> > ******************************************
> 
> _______________________________________________
> obspy-users mailing list
> obspy-users at lists.swapbytes.de
> http://lists.swapbytes.de/mailman/listinfo/obspy-users


More information about the obspy-users mailing list