Chaco real-time plot with PySerial

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Chaco real-time plot with PySerial

Jack Keegan
Hi there,

My apologies if this question has been posted before but I couldn't find a
way to search the archives. I have been considering using chaco / traits
for close to a year now and am finally biting the bullet so to speak. One
of my most common requirements is real-time data visualisation/plotting
from an external source (e.g. serial port, data acquisition card etc..). I
imagine this would be a common requirement but I can't seem to find any
examples. I know there are examples of plotting at
https://github.com/enthought/chaco/tree/master/examples/demo/updating_plot but
these examples generate data from within the same object/thread. I'm just
wondering if anyone has tried updating a real-time plot from a separate
thread/process using something like PySerial?

Robert has previously pointed me in the direction of pyface.gui.invoke_later

As I haven't yet written any code with chaco (still reading the
documentation), I'm wondering if anyone has a more complete example for me
to work from?

Thanks very much,

Jack

--
The earth is a very small stage in a vast cosmic arena. Think of the rivers
of blood spilled by all those generals and emperors so that in glory and in
triumph they could become the momentary masters of a fraction of a dot.
- Carl Sagan [Pale Blue Dot]
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Chaco real-time plot with PySerial

Corran Webster
You might have a look at the examples/demo/advanced/spectrum.py example in
Chaco, which grabs data using PyAudio and creates a live spectrogram of
it.  This should hopefully give you an idea of how to do the Chaco updating
from an external data source.

-- Corran

On Thu, Nov 3, 2011 at 7:43 AM, Jack Keegan <[hidden email]>wrote:

> Hi there,
>
> My apologies if this question has been posted before but I couldn't find a
> way to search the archives. I have been considering using chaco / traits
> for close to a year now and am finally biting the bullet so to speak. One
> of my most common requirements is real-time data visualisation/plotting
> from an external source (e.g. serial port, data acquisition card etc..). I
> imagine this would be a common requirement but I can't seem to find any
> examples. I know there are examples of plotting at
> https://github.com/enthought/chaco/tree/master/examples/demo/updating_plotbut
> these examples generate data from within the same object/thread. I'm just
> wondering if anyone has tried updating a real-time plot from a separate
> thread/process using something like PySerial?
>
> Robert has previously pointed me in the direction of
> pyface.gui.invoke_later
>
> As I haven't yet written any code with chaco (still reading the
> documentation), I'm wondering if anyone has a more complete example for me
> to work from?
>
> Thanks very much,
>
> Jack
>
> --
> The earth is a very small stage in a vast cosmic arena. Think of the rivers
> of blood spilled by all those generals and emperors so that in glory and in
> triumph they could become the momentary masters of a fraction of a dot.
> - Carl Sagan [Pale Blue Dot]
> _______________________________________________
> Enthought-Dev mailing list
> [hidden email]
> https://mail.enthought.com/mailman/listinfo/enthought-dev
>
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Chaco real-time plot with PySerial

Adam Hughes
Another thing you can do is simply monitor a directory by having a program
which scans the directory every 30s, minute, 5 minutes etc... and stores
the file names in the directory into some sort of data object (usually a
m-dimensional numpy array is best).  Then you can simply call an update to
the chaco plot module (or make the update automatic via listeners).  In
your chaco plot all you'd need is something like:

class MyPlot(HasTraits):
     plot=Instance(plot)
     data=Abstract_plot_data()

     def update_plot(self):  #This module would draw the plot
          ::Do stuff::
          new_plot=this
          new_plot.append(that)
          etc...
          self.plot=new_plot

     def update_data(self, new_data):  #This would be called from another
program
            self.data=new_data
            self.update_plot()

If you define your plot objects this way, they are completely separate from
the model, and can be called/updated whenever your program dictates simply
by calling the update_data method.

On Thu, Nov 3, 2011 at 9:53 AM, Corran Webster <[hidden email]>wrote:

> You might have a look at the examples/demo/advanced/spectrum.py example in
> Chaco, which grabs data using PyAudio and creates a live spectrogram of
> it.  This should hopefully give you an idea of how to do the Chaco updating
> from an external data source.
>
> -- Corran
>
> On Thu, Nov 3, 2011 at 7:43 AM, Jack Keegan <[hidden email]
> >wrote:
>
> > Hi there,
> >
> > My apologies if this question has been posted before but I couldn't find
> a
> > way to search the archives. I have been considering using chaco / traits
> > for close to a year now and am finally biting the bullet so to speak. One
> > of my most common requirements is real-time data visualisation/plotting
> > from an external source (e.g. serial port, data acquisition card etc..).
> I
> > imagine this would be a common requirement but I can't seem to find any
> > examples. I know there are examples of plotting at
> >
> https://github.com/enthought/chaco/tree/master/examples/demo/updating_plotbut
> > these examples generate data from within the same object/thread. I'm just
> > wondering if anyone has tried updating a real-time plot from a separate
> > thread/process using something like PySerial?
> >
> > Robert has previously pointed me in the direction of
> > pyface.gui.invoke_later
> >
> > As I haven't yet written any code with chaco (still reading the
> > documentation), I'm wondering if anyone has a more complete example for
> me
> > to work from?
> >
> > Thanks very much,
> >
> > Jack
> >
> > --
> > The earth is a very small stage in a vast cosmic arena. Think of the
> rivers
> > of blood spilled by all those generals and emperors so that in glory and
> in
> > triumph they could become the momentary masters of a fraction of a dot.
> > - Carl Sagan [Pale Blue Dot]
> > _______________________________________________
> > Enthought-Dev mailing list
> > [hidden email]
> > https://mail.enthought.com/mailman/listinfo/enthought-dev
> >
> _______________________________________________
> Enthought-Dev mailing list
> [hidden email]
> https://mail.enthought.com/mailman/listinfo/enthought-dev
>
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Chaco real-time plot with PySerial

Jack Keegan
Hi Adam,

I need to plot data which is being sampled many times faster than that (up
to 2kHz). Therefore I'm not sure the file option would be suitable.

Thank you for your response though.

Cheers,

Jack

On Thu, Nov 3, 2011 at 2:55 PM, Adam Hughes <[hidden email]> wrote:

> Another thing you can do is simply monitor a directory by having a program
> which scans the directory every 30s, minute, 5 minutes etc... and stores
> the file names in the directory into some sort of data object (usually a
> m-dimensional numpy array is best).  Then you can simply call an update to
> the chaco plot module (or make the update automatic via listeners).  In
> your chaco plot all you'd need is something like:
>
> class MyPlot(HasTraits):
>     plot=Instance(plot)
>     data=Abstract_plot_data()
>
>     def update_plot(self):  #This module would draw the plot
>          ::Do stuff::
>          new_plot=this
>          new_plot.append(that)
>          etc...
>          self.plot=new_plot
>
>     def update_data(self, new_data):  #This would be called from another
> program
>            self.data=new_data
>            self.update_plot()
>
> If you define your plot objects this way, they are completely separate from
> the model, and can be called/updated whenever your program dictates simply
> by calling the update_data method.
>
> On Thu, Nov 3, 2011 at 9:53 AM, Corran Webster <[hidden email]
> >wrote:
>
> > You might have a look at the examples/demo/advanced/spectrum.py example
> in
> > Chaco, which grabs data using PyAudio and creates a live spectrogram of
> > it.  This should hopefully give you an idea of how to do the Chaco
> updating
> > from an external data source.
> >
> > -- Corran
> >
> > On Thu, Nov 3, 2011 at 7:43 AM, Jack Keegan <[hidden email]
> > >wrote:
> >
> > > Hi there,
> > >
> > > My apologies if this question has been posted before but I couldn't
> find
> > a
> > > way to search the archives. I have been considering using chaco /
> traits
> > > for close to a year now and am finally biting the bullet so to speak.
> One
> > > of my most common requirements is real-time data visualisation/plotting
> > > from an external source (e.g. serial port, data acquisition card
> etc..).
> > I
> > > imagine this would be a common requirement but I can't seem to find any
> > > examples. I know there are examples of plotting at
> > >
> >
> https://github.com/enthought/chaco/tree/master/examples/demo/updating_plotbut
> > > these examples generate data from within the same object/thread. I'm
> just
> > > wondering if anyone has tried updating a real-time plot from a separate
> > > thread/process using something like PySerial?
> > >
> > > Robert has previously pointed me in the direction of
> > > pyface.gui.invoke_later
> > >
> > > As I haven't yet written any code with chaco (still reading the
> > > documentation), I'm wondering if anyone has a more complete example for
> > me
> > > to work from?
> > >
> > > Thanks very much,
> > >
> > > Jack
> > >
> > > --
> > > The earth is a very small stage in a vast cosmic arena. Think of the
> > rivers
> > > of blood spilled by all those generals and emperors so that in glory
> and
> > in
> > > triumph they could become the momentary masters of a fraction of a dot.
> > > - Carl Sagan [Pale Blue Dot]
> > > _______________________________________________
> > > Enthought-Dev mailing list
> > > [hidden email]
> > > https://mail.enthought.com/mailman/listinfo/enthought-dev
> > >
> > _______________________________________________
> > Enthought-Dev mailing list
> > [hidden email]
> > https://mail.enthought.com/mailman/listinfo/enthought-dev
> >
> _______________________________________________
> Enthought-Dev mailing list
> [hidden email]
> https://mail.enthought.com/mailman/listinfo/enthought-dev
>



--
The earth is a very small stage in a vast cosmic arena. Think of the rivers
of blood spilled by all those generals and emperors so that in glory and in
triumph they could become the momentary masters of a fraction of a dot.
- Carl Sagan [Pale Blue Dot]
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Chaco real-time plot with PySerial

Robert Kern
On Thu, Nov 3, 2011 at 3:28 PM, Jack Keegan <[hidden email]> wrote:
> Hi Adam,
>
> I need to plot data which is being sampled many times faster than that (up
> to 2kHz). Therefore I'm not sure the file option would be suitable.

While you are probably right that the file option would not be
suitable, you shouldn't update the GUI faster than about 60Hz.
Anything more than that, and you are just wasting CPU cycles drawing
frames that the user will never see.

--
Robert Kern
Enthought
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Chaco real-time plot with PySerial

Jack Keegan
In reply to this post by Corran Webster
Hi Corran,

I did have a look at that before. I just wasn't sure what was going on with
the demo class. I then wen't back to reading the documentation. I guess
I'll have to look into it further.

Thanks,

Jack

On Thu, Nov 3, 2011 at 1:53 PM, Corran Webster <[hidden email]>wrote:

> You might have a look at the examples/demo/advanced/spectrum.py example in
> Chaco, which grabs data using PyAudio and creates a live spectrogram of
> it.  This should hopefully give you an idea of how to do the Chaco updating
> from an external data source.
>
> -- Corran
>
> On Thu, Nov 3, 2011 at 7:43 AM, Jack Keegan <[hidden email]
> >wrote:
>
> > Hi there,
> >
> > My apologies if this question has been posted before but I couldn't find
> a
> > way to search the archives. I have been considering using chaco / traits
> > for close to a year now and am finally biting the bullet so to speak. One
> > of my most common requirements is real-time data visualisation/plotting
> > from an external source (e.g. serial port, data acquisition card etc..).
> I
> > imagine this would be a common requirement but I can't seem to find any
> > examples. I know there are examples of plotting at
> >
> https://github.com/enthought/chaco/tree/master/examples/demo/updating_plotbut
> > these examples generate data from within the same object/thread. I'm just
> > wondering if anyone has tried updating a real-time plot from a separate
> > thread/process using something like PySerial?
> >
> > Robert has previously pointed me in the direction of
> > pyface.gui.invoke_later
> >
> > As I haven't yet written any code with chaco (still reading the
> > documentation), I'm wondering if anyone has a more complete example for
> me
> > to work from?
> >
> > Thanks very much,
> >
> > Jack
> >
> > --
> > The earth is a very small stage in a vast cosmic arena. Think of the
> rivers
> > of blood spilled by all those generals and emperors so that in glory and
> in
> > triumph they could become the momentary masters of a fraction of a dot.
> > - Carl Sagan [Pale Blue Dot]
> > _______________________________________________
> > Enthought-Dev mailing list
> > [hidden email]
> > https://mail.enthought.com/mailman/listinfo/enthought-dev
> >
> _______________________________________________
> Enthought-Dev mailing list
> [hidden email]
> https://mail.enthought.com/mailman/listinfo/enthought-dev
>



--
The earth is a very small stage in a vast cosmic arena. Think of the rivers
of blood spilled by all those generals and emperors so that in glory and in
triumph they could become the momentary masters of a fraction of a dot.
- Carl Sagan [Pale Blue Dot]
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Chaco real-time plot with PySerial

Jack Keegan
In reply to this post by Robert Kern
Hi Robert,

Indeed. I just need to sample faster than that. When I said 2kHz I meant
that I will have a large amount of samples to process before every update.
I would be hoping to do a real-time FFT plot so I would imagine that
accessing files will slow me down too much. I'm surprised that you said
60Hz though. That would be impressive :)

Cheers,

Jack

On Thu, Nov 3, 2011 at 3:34 PM, Robert Kern <[hidden email]> wrote:

> On Thu, Nov 3, 2011 at 3:28 PM, Jack Keegan <[hidden email]>
> wrote:
> > Hi Adam,
> >
> > I need to plot data which is being sampled many times faster than that
> (up
> > to 2kHz). Therefore I'm not sure the file option would be suitable.
>
> While you are probably right that the file option would not be
> suitable, you shouldn't update the GUI faster than about 60Hz.
> Anything more than that, and you are just wasting CPU cycles drawing
> frames that the user will never see.
>
> --
> Robert Kern
> Enthought
> _______________________________________________
> Enthought-Dev mailing list
> [hidden email]
> https://mail.enthought.com/mailman/listinfo/enthought-dev
>



--
The earth is a very small stage in a vast cosmic arena. Think of the rivers
of blood spilled by all those generals and emperors so that in glory and in
triumph they could become the momentary masters of a fraction of a dot.
- Carl Sagan [Pale Blue Dot]
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Chaco real-time plot with PySerial

Peter Wang
In reply to this post by Jack Keegan
On Thu, Nov 3, 2011 at 10:35 AM, Jack Keegan <[hidden email]> wrote:
> Hi Corran,
> I did have a look at that before. I just wasn't sure what was going on with
> the demo class. I then wen't back to reading the documentation. I guess
> I'll have to look into it further.

The Demo class stuff in any of the Chaco examples was to help tie all
the Chaco examples into a single large Traits UI application.  You can
safely ignore it and look at the bare WX or Qt code in the section
below (after the comment "Stand-alone frame to display the plot").

-Peter
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Chaco real-time plot with PySerial

Jack Keegan
Hi Peter,

Thanks for that info. Everything helps. Much appreciated.

cheers,

Jack

On Fri, Nov 4, 2011 at 3:49 PM, Peter Wang <[hidden email]> wrote:

> On Thu, Nov 3, 2011 at 10:35 AM, Jack Keegan <[hidden email]>
> wrote:
> > Hi Corran,
> > I did have a look at that before. I just wasn't sure what was going on
> with
> > the demo class. I then wen't back to reading the documentation. I guess
> > I'll have to look into it further.
>
> The Demo class stuff in any of the Chaco examples was to help tie all
> the Chaco examples into a single large Traits UI application.  You can
> safely ignore it and look at the bare WX or Qt code in the section
> below (after the comment "Stand-alone frame to display the plot").
>
> -Peter
> _______________________________________________
> Enthought-Dev mailing list
> [hidden email]
> https://mail.enthought.com/mailman/listinfo/enthought-dev
>



--
The earth is a very small stage in a vast cosmic arena. Think of the rivers
of blood spilled by all those generals and emperors so that in glory and in
triumph they could become the momentary masters of a fraction of a dot.
- Carl Sagan [Pale Blue Dot]
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev