Pulling arrays from database for plotting

2009-08-12 Thread Kurt Schwehr
Hi all,

What's the best way to pull arrays from a database for plotting?
Right now, this is what I do, but can it be done simpler / more
efficiently?

ipython -pylab
import sqlite3
cx = sqlite3.connect('20080407.decimated.db3')
a = array( [tuple(row) for row in cx.execute('SELECT cg_offset,
delta_t_sec FROM bs_time WHERE recvr=2;')] )
x = a[:,0]
y = a[:,1]
plot(x,y)

However, if I try to plot it directly using transpose, it hangs:

import sqlite3
cx = sqlite3.connect('20080407.decimated.db3')
plot(array( [tuple(row) for row in cx.execute('SELECT cg_offset,
delta_t_sec FROM bs_time WHERE recvr=2;')] ).transpose())

It is that plot just doesn't know what to do with a 2D array?  Then I
tried this and it works, but is long and confusing to the uninitiated.

plot(*array( [tuple(row) for row in cx.execute('SELECT cg_offset,
delta_t_sec FROM bs_time WHERE recvr=2;')] ).T)



In [4]: a
Out[4]:
array([[  2.4000e+01,   0.e+00],
   [  2.5000e+01,  -1.e+00],
   [  3.4000e+01,   0.e+00],
   ...,
   [  8.6384e+04,   2.e+01],
   [  8.6394e+04,   2.e+01],
   [  8.6404e+04,   2.e+01]])

In [5]: a.transpose()
Out[5]:
array([[  2.4000e+01,   2.5000e+01,   3.4000e+01, ...,
  8.6384e+04,   8.6394e+04,   8.6404e+04],
   [  0.e+00,  -1.e+00,   0.e+00, ...,
  2.e+01,   2.e+01,   2.e+01]])



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A superclass using a child classes' methods

2009-06-24 Thread Kurt Schwehr
Jean-Michel,

Thanks for the excellent response setting me straight.  Now to figure
out what dumb thing I did to make my code not work...

-kurt

On Jun 24, 12:23 pm, Jean-Michel Pichavant 
wrote:
> Kurt Schwehr wrote:
> > I'm trying to build an OO system for encoding and decoding
> > datapackets.  I'd like the parent class to have an encode function
> > that uses each of the child classes' packing methods.  It appears that
> > this works for attributes of children accessed by the parent, but not
> > for methods.
>

[clear example of it working]

>
> Declaring the foo method at the Parent level is not required. But it's a
> good practice: explicit > implicit and it helps to write proper
> documentation.
>
> Jean-Michel

-- 
http://mail.python.org/mailman/listinfo/python-list


A superclass using a child classes' methods

2009-06-24 Thread Kurt Schwehr
I'm trying to build an OO system for encoding and decoding
datapackets.  I'd like the parent class to have an encode function
that uses each of the child classes' packing methods.  It appears that
this works for attributes of children accessed by the parent, but not
for methods.  Is that right?  For attributes I found this example,
where the alphabet attribute is set in the child, but used in the
parent.

http://www.pasteur.fr/formation/infobio/python/ch19s04.html

Should I just set an attribute in the child class and then call the
super's functionality making is pull the data from the attribute?

Thanks,
-kurt
-- 
http://mail.python.org/mailman/listinfo/python-list