Thursday, February 14, 2013

Anand & Daniel's Adventures in Python

Valentine's Day - Planning Meeting
Essential:
- pyserial
- numpy/scipy (based off numpy)
? GTK runtime + pyGTK: GUI widget library used by matplotlib in certain implementations

All Python graphing library options (with examples)
1. matplotlib
http://yassinebenabbas.wordpress.com/article/creer-un-graphe-dynamique-avec-pyplot-31z31ug7b5vz5-26/

http://eli.thegreenplace.net/2008/08/01/matplotlib-with-wxpython-guis/

http://stackoverflow.com/questions/7663263/reading-real-time-values-with-pyserial-while-plotting


2. pylab
http://www.gossamer-threads.com/lists/python/dev/439302

3. Chaco
http://docs.enthought.com/chaco/user_manual/chaco_tutorial.html#tutorial

4. pyqtgraph


- glumpy, visvis (OpenGL-based)


- Anand: we will probably be using matplotlib in the end
- pylab is used for a lot of toy examples on the internet

Feb 15 Meeting
- let's run through the matplotlib examples and understand how they work
- construct real-time signal reader that works

Friday update:
Someone in Germany viewed our blog! We're famous now.
It turns out pylab is actually part of matplotlib! Actually, it's a metapackage related to numpy and stuff. They're not competitors. We're using pylab from matplotlib. This can be done using any of the following:

1. import matplotlib
OR 
2. from matplotlib import *
OR
 3. from matplotlib import pylab
OR
4. from matplotlib.pylab import *
OR 
5. import pylab
OR
6. from pylab import *

Noticing a pattern here? A quick note on importing Python modules: let's say we have a Python module x that contains some other sub-module y. For example, x could be matplotlib, and y could be pylab. If we use "import x" and we want to use stuff in y, we have to call it "x.y" in our code. If we use "from x import *" and then we want to use y, we can just call it "y". Therefore our choice of the above will affect how our code looks. I lean towards "from pylab import *" since it makes the later code easier to write.

We played around a bit with the example code in the "cookbook" file on GitHub. We discovered the following:

1. Interactive mode must be on. Call ion() at the beginning.
2. Call draw() to update the graph as desired.

We validated this by also running the example code from http://mindseye.no/2011/04/03/animating-plots-and-waves-in-python-using-matplotlib/ using pylab

Then we combined pylab with our serial code successfully!

Next, we ran Karen's awesome simultaneous 5-channel sine generation Arduino code, and graphed the output from that as well! Daniel also made pretty fireworks by graphing the wrong thing.

Finally, we made Karen's code way more intense by graphing gigantic sine waves using the long data type, allowing us to test graphing 20 bytes at a time (4 bytes per channel times 5 channels) in real time! It worked, even at 115,200 baud with only 2 microseconds delay! Woohoo!

No comments:

Post a Comment