[pyrwi] r9 committed - Minor new tools.

4 views
Skip to first unread message

codesite...@google.com

unread,
Apr 5, 2010, 7:23:26 PM4/5/10
to pyrwi...@googlegroups.com
Revision: 9
Author: danielrairigh
Date: Mon Apr 5 16:22:55 2010
Log: Minor new tools.
http://code.google.com/p/pyrwi/source/detail?r=9

Modified:
/trunk/docs/examples/ContAcq-IntClk.py
/trunk/pyrwi/__init__.py
/trunk/pyrwi/daq.py
/trunk/pyrwi/tools.py

=======================================
--- /trunk/docs/examples/ContAcq-IntClk.py Sat Sep 5 14:55:38 2009
+++ /trunk/docs/examples/ContAcq-IntClk.py Mon Apr 5 16:22:55 2010
@@ -53,11 +53,13 @@
nSamples = 1000 #Number of samples to read before calling Python back

h = DAQmx.CreateTask("ContAcq") #Create a new task
- DAQmx.CreateAIVoltageChan(h,"Dev1/ai0","",\ #Configure to read a
voltage
+ #Configure to read a voltage
+ DAQmx.CreateAIVoltageChan(h,"Dev1/ai1","",\
DAQmx.Val_Cfg_Default,-10.0,10.0,\
DAQmx.Val_Volts,None)
- DAQmx.CfgSampClkTiming(h,"",10000.0,\ #Configure a continuous
- DAQmx.Val_Rising,DAQmx.Val_ContSamps,\ #clock
+ #Configure a continuous clock
+ DAQmx.CfgSampClkTiming(h,"",10000.0,\
+ DAQmx.Val_Rising,DAQmx.Val_ContSamps,\
nSamples)

if True :
=======================================
--- /trunk/pyrwi/__init__.py Sat Sep 5 14:55:38 2009
+++ /trunk/pyrwi/__init__.py Mon Apr 5 16:22:55 2010
@@ -13,7 +13,7 @@
from daq import float64, int16, int32, uInt8, uInt16, uInt32
from gui import Fl_Log, Fl_Button_Stack, RWI_Window
from Fl_Plot import Fl_Plot
-from tools import getBits, bitsToInt, fmtEng, fmtBin, writeDataFile,
timeVector, analog_fft
+from tools import getBits, bitsToInt, fmtEng, getEngExp, UnitsSpice,
fmtBin, writeDataFile, timeVector, analog_fft

########################################################################
# Universal Code
=======================================
--- /trunk/pyrwi/daq.py Sat Sep 5 14:55:38 2009
+++ /trunk/pyrwi/daq.py Mon Apr 5 16:22:55 2010
@@ -133,6 +133,13 @@
#Data being shifted out has already been saved
return

+
+ if self.bufferMaxLen == 0 and len(self.buffer)>0:
+ #Unlimited buffers have no x data, so we must create it.
+ buf_len = len(self.buffer[0])
+ #Build an X axis
+ self.x =
sp.arange(self.t0,stop=self.t0+float(buf_len)/self.Fs, step=1.0/self.Fs)
+
pat = "%f, " + ",".join([self.fmt_str]*len(self.buffer)) + "\n"

for i,tpl in enumerate(zip(self.x[0:self.buffer_len],
*self.buffer)) :
=======================================
--- /trunk/pyrwi/tools.py Sat Sep 5 14:55:38 2009
+++ /trunk/pyrwi/tools.py Mon Apr 5 16:22:55 2010
@@ -76,6 +76,20 @@

multiplier = val / pow(10, p3)
return fmt % (multiplier, p3)
+
+def getEngExp(val) :
+ '''
+ Find the 10's exponent and round to the nearest 3
+ @param val : Floating point or Int input
+ @return: One of ... -6, -3, 0, 3, 6, 9 ...
+ '''
+ import math
+ l = math.log10(abs(val))
+ l = math.floor(l)
+ return int(int(l) / 3) * 3 #Round to nearest 3
+
+UnitsSpice = {-15:'f', -12:'p', -9:'n', -6:'u', -3:'m', 0:'',
+ 3:'k', 6:'M', 9:'G'}

def fmtBin(x, digits=0):
'''
@@ -91,6 +105,9 @@
binstring = [oct2bin[int(n)] if n != '-' else '-' for n in oct(x)]
return ''.join(binstring).lstrip('0').zfill(digits)

+########################################################################
+# helpers
+########################################################################
def writeDataFile(outFile, *data, **kargs) :
'''
Write lists of data to a file formatted nicely for Excel.
@@ -106,6 +123,7 @@
writeDataFile(open('log.csv','a'), [1,2,3,4], [4,5,1,3])
writeDataFile('log.csv', headers=['time','Volts'], range(4), [4,5,1,3])
'''
+ from copy import deepcopy

if isinstance(outFile, file) :
#Already a file handle
@@ -121,11 +139,23 @@
if len(headers) != len(data): raise IndexError, "Headers must be
same length as data"
fh.write( ",".join([str(h) for h in headers]) + "\n")

+ #Make all vectors the same length
+ maxLen = len(max(data, key=len)) #Max returns longest vector
+ data = [ v.tolist() if hasattr(v, "tolist") else deepcopy(v) for v in
data]
+ for v in data :
+ v += [''] * (maxLen - len(v))
+
#Make a pattern for writting one row at a time
pat = ",".join(["%f"]*len(data)) + "\n"

- for i,tpl in enumerate(zip(*data)) :
- fh.write( pat % tpl )
+ if True :
+ import csv
+ csvWrite = csv.writer(fh, lineterminator="\n")
+ for tpl in zip(*data) :
+ csvWrite.writerow(tpl)
+ else :
+ for i,tpl in enumerate(zip(*data)) :
+ fh.write( pat % tpl )

if closeFile: fh.close()

Reply all
Reply to author
Forward
0 new messages