24 bit signed integer binary conversion help needed

2010-01-08 Thread Robert Somerville

hi;
I am trying to read 24bit signed WAV format (little endian) data from a 
WAV file and convert it to 32 bit little endian integer format ... can 
anybody please tell me how to do the conversion from 24 bit to 32 bit 
with a snippet of Python code ???


Thanks so much
Robert Somerville
--
http://mail.python.org/mailman/listinfo/python-list


24 bit signed integer binary conversion help needed

2010-01-08 Thread Robert Somerville




thanks Grant, your sext24 function does the trick (this Python
newbie thanks you a lot ...)

so i loop on d=wave.readframes(1) 
  call dd=sext24(d) on the frame read , then
  unpack(dd)  the output of sext24 into a 32bit integer (seems to do
the trick correctly for signed 24 bit integers )

> On 2010-01-08, Robert Somerville <rsomerville at sjgeophysics.com> wrote:
>
>> I am trying to read 24bit signed WAV format (little endian) data from a 
>> WAV file and convert it to 32 bit little endian integer format ... can 
>> anybody please tell me how to do the conversion from 24 bit to 32 bit 
>> with a snippet of Python code ???
>
> def sext24(d):
> if ord(d[2]) & 0x80:
> return d+'\xff'
> else:
> return d+'\x00'







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


24 bit signed integer binary conversion help needed

2010-01-08 Thread Robert Somerville
thanks Grant, your sext24 function does the trick (this Python newbie 
thanks you a lot ...)


so i loop on d=wave.readframes(1)
 call dd=sext24(d) on the frame read , then
  ddd=struct.unpack("<%ul" % 1 ,dd)
 unpack(dd)  the output of sext24 into a 32bit integer (seems to do the 
trick correctly for signed 24 bit integers )

-thanks , bob

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


how to sort two dimensional array

2010-01-19 Thread robert somerville
Hi;
 i am having trouble trying to sort the rows of a 2 dimensional array by the
values in the first column .. does anybody know how or have an example of
how to do this ??? while leaving the remain columns remain relative to the
leading column

from numpy import *

a=array( [ [4, 4, 3], [4, 5, 2],  [3, 1, 1] ] )

i would like to generate the output (or get the output ...)

b = [ [3,1,1], [4,4,3], [4,5,2] ]

thanks;
bob
-- 
http://mail.python.org/mailman/listinfo/python-list


how to sort two dimensional array ??

2010-01-19 Thread robert somerville
Hi;
 i am having trouble trying to sort the rows of a 2 dimensional array by the
values in the first column .. does anybody know how or have an example of
how to do this ??? while leaving the remain columns remain relative to the
leading column

from numpy import *

a=array( [ [4, 4, 3], [4, 5, 2],  [3, 1, 1] ] )

i would like to generate the output (or get the output ...)

b = [ [3,1,1], [4,4,3], [4,5,2] ]

thanks;
bob
-- 
http://mail.python.org/mailman/listinfo/python-list


how to sort two dimensional array ??

2010-01-19 Thread Robert Somerville

Hi;
i am having trouble trying to sort the rows of a 2 dimensional array by 
the values in the first column .. does anybody know how or have an 
example of how to do this ??? while leaving the remain columns remain 
relative to the leading column


from numpy import *

a=array( [ [4, 4, 3], [4, 5, 2],  [3, 1, 1] ] )

i would like to generate the output (or get the output ...)

b = [ [3,1,1], [4,4,3], [4,5,2] ]



thanks;
bob
--
http://mail.python.org/mailman/listinfo/python-list


Elementtree install problem in Ubuntu (a newbie ..)

2010-03-10 Thread robert somerville
Hi ;
I installed the elementtree and celementree packages throught the synaptic
package manager, all seems to go fine through the install ...

when i startup python and try to import them (as per the EFFBOTT.org
suggestions) .. PROBLEMS ... (see below ..) What am i doing wrong ??? this
is a new window after installation of packages ...

Python 2.6.4 (r264:75706, Dec  7 2009, 18:43:55)
[GCC 4.4.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import elementtree.ElementTree as ET
Traceback (most recent call last):
  File "", line 1, in 
ImportError: No module named elementtree.ElementTree
>>> import elementtree
Traceback (most recent call last):
  File "", line 1, in 
ImportError: No module named elementtree


thanks;
Robert somerville
-- 
http://mail.python.org/mailman/listinfo/python-list


Python 2.6 and modules dbi AND odbc

2010-03-10 Thread robert somerville
hi;
 i am trying to get some legacy python code (which i no nothing about)
working with tries to import dbi and odbc (the import fails ...) it looks
like these modules are deprecated ?? if so is there a work around , if not
deprecated, what am i doing wrong ?? i see no Ubuntu packages that look
promising ..

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


problems creating and adding class instances to a list:

2010-04-19 Thread Robert Somerville
I am trying to create a list of consisting of multiple instances of the 
same class, The Problems i am having is that i seem to be accessing the 
same memory.. How should i solve this Python problem ?


Here is some sample code demonstraing my problem (same memory) :
from copy import copy as cp

class ctest():
   x = int
   y = [1,2,3]
  


def return_class(i):
   d = ctest()
   d.y[1] = i*10
   return (d)

if __name__ == '__main__':
   c_list= []
   print 'len-a =',len(c_list)
   for i in range(5):
   e = cp(return_class(i))
   c_list.append(e)
   print 'i= ',i,c_list[i].y[1]
   if ( i > 0):
   print 'i-1= ',i-1,c_list[i-1].y[1]   
  
   print 'len = ' , len(c_list)   
   for i in range(5):

   print 'i= ',i,c_list[i].y[1]


here is the output demonstrating that i am addressing the same memory:

rsomervi...@galena:~/workspace/CSIRO_gui/trunk/src$ python test4.py
len-a = 1
i=  0 0
i=  1 10
i-1=  0 10
i=  2 20
i-1=  1 20
i=  3 30
i-1=  2 30
i=  4 40
i-1=  3 40
len =  6
i=  0 40
i=  1 40
i=  2 40
i=  3 40
i=  4 40

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


How to test whether bit is set within a flag with Python ?

2010-05-12 Thread robert somerville
I am trying to determine how to test whether variors bits are set within a
byte (or larger flag) , the python 'and' and 'or' do not seem to be doing
what i want .. does anybody have some sample code showing how to do it ??

e.g. (in "C")

unsigned char a = 6;

is 3rd bit set ??

a & 4 =,  true in this case 

thanks
Robert Somerville
-- 
http://mail.python.org/mailman/listinfo/python-list


Best XML python package to learn for Ubuntu Linux ?

2010-05-19 Thread Robert Somerville

Hi;

I am about to get my feet wet with Python XML, there appears to be many 
libraries ... can someone recommend

a good package to use on Ubuntu ???


regards;
Robert Somerville
--
http://mail.python.org/mailman/listinfo/python-list


re ElemenTree producing and reading examples needed :

2010-05-27 Thread robert somerville
does anybody have some working code that they can point me to so i could see
ElemenTtree in action (especially writing XML files) ???

Thanks
Robert Somerville
-- 
http://mail.python.org/mailman/listinfo/python-list


ElementTree write creates large one line XML file ....

2010-05-27 Thread robert somerville
Hi I am using Ubuntu 9.10 and Python 2.6.4 ..

when I create an ElementTree object and the write it out using:

 xml.etree.ElementTree.write() , I get one single long single line files,
instead of something that looks reasonable , what gives ??? (and is it
important ??)

eg: I get :

OneTwo

instead of :


One
Two



i found this example at: ( Listing 4 )
http://www.learningpython.com/2008/05/07/elegant-xml-parsing-using-the-elementtree-module/#Listing1
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ElementTree write creates large one line XML file ....

2010-05-28 Thread robert somerville
Thanks Robert Kern :

"prettyprint" ; indent()  does the trick ;-)


>ElementTree writes exactly what you tell it to. In XML, whitespace is
>significant. If you want newlines and/or indentation to make it pretty-looking,
>then you need to add those to your elements.
>
>Fredrik provides an example function for doing this:
>
>   http://effbot.org/zone/element-lib.htm#prettyprint
-- 
http://mail.python.org/mailman/listinfo/python-list


python and filter design: calculating "s" optimal transform

2010-06-01 Thread robert somerville
Hi;
this is an airy question.

does anybody have some code or ideas on how to calculate the optimal "S"
transform of user specified order (wanting the coefficients)  for a
published filter response curve, ie.

f(s) = 1.0/(a1*S^2 + a2*S + a3)
-- 
http://mail.python.org/mailman/listinfo/python-list