Spectrogram plotting

Tom its1louder at yahoo.com
Tue Oct 8 15:13:15 EDT 2002


Fernando Pérez <fperez528 at yahoo.com> wrote in message news:<anuk8f$kp$1 at peabody.colorado.edu>...
> seh wrote:
> 
> > I would like to sample some data from the soundcard into a vector.
> > Then process the data ex. take an FFT. Then plot the data intensity
> > modulated vertically on the screen. Then sample some new data, process
> > and plot them near to the previous data and so on.
> > 
> > Anybody has some code to do this? Peferably in Tkinter but wxPython is
> > also of interest.
> > 
> > Svein-Erik
> 
> http://scipy.org has all the pieces you need. You can also just use 
> Numeric+Gnuplot, but the gnuplot interface is a bit clunky.
> 
> Cheers,
> 
> f.

I also use spectra and plot the FFT.  here's what I found out.

I think scipy is ok, but it is rough and doesn't seem to work with
python 2.2.  I like it for making quick plots at the commandline.  I
like dislin a little better for 2-D plots.  But ultimately, I have not
been really pleased with any plotting packages for python.  I think
Chaco (from the scipy people) has the potential to be a really good
cross platform package, but not for probably a year, it just got
started.  I'm also waiting to see how pyncl turns out, that would be
super cool for anyone interested in powerful cartography in addition
to typical plotting.

In the end I've given up on python plotting packages for now.  I use
the wxPython activexwrapper module.  I find this works really well. 
The Visual basic activex controls that I have been using a long time
(the national instruments Component works or whatever they call it
now) are easily dropped into wxpython guis.  I've created a class
called CWPlotPanel that is returned by MakeActiveXClass() function. 
BTW it is interesting that Python seems to have better activex support
then Borland C Builder, I never got these controls to work there.

the disadvantage is basically that I've abdicated cross platform
functionality to use COM.  Another disdvantage is that a bug seems to
crash the program when I try to create cursor objects for the plot and
then resize the plot.  So I don't use cursors, which is a shame, but
not a tragedy.  Since I need to use COM libraries anyway win32 only
isn't a problem for me.  I need com because I am using instruments
that return spectra (e.g., an FTIR) in the *.spc file format.  This is
a complicated format and the best high level library for reading them
that I know of is the thermo galactic GSPCIO com library.

Anyway, my instrument spits out a *.spc file.  I use the python
win32com.client lib to access the data in the spc file.   Then I use
the Numeric FFT module:
 
       
    def performFFT(self,):
        """Calculate the FFT of the interferogram."""
        fftdat = abs(real_fft(self.spcf.YData, n = SpcIO.NumPoints,))
        return fftdat

I make a plot control class called AXPlotControl with
MakeActiveXClass() and then I instantiate two plot objects - one for
the interferogram, and one for the spectrum which is the former's fft.
 My understanding of MakeActiveXClass() is that it is returning a
class that is derived from up to three things, a wxWindow, the activex
control's CoClass, and potentially an eventclass.  In this case the
event class is the object itself and the coclass is registered as
guiModule.CWGraph.

        AXPlotControl = MakeActiveXClass(guiModule.CWGraph, eventObj =
self)
        self.ifgramAXCtrl = AXPlotControl(self.notebook1, -1)
        self.specAXCtrl = AXPlotControl(self.notebook1, -1)

(My gui is structured around a notebook with a log page that spits out
*.spc header info, the intereferogram plot page, and the spectrum plot
page.)

The win32com support is so seamless that passing arrays from the
GSPCIO COM library to the the python numeric module to the activex
control requires nothing special at all, it just works.

I can show you some example code if you are interested.  It is still a
work in progress, but it basically works now (except cursors, confound
it).



More information about the Python-list mailing list