I have a question regarding nested tables.  The populating a nested table 
example in the PyTables UserManual (pp. 44-45) only deals with a nested table 
that is called once and really doesn't subdivide.  However, what if my data 
structure looks something like:

     MotorName             ExpSet        Load          Efficiency
|                           |                    |__ 25%____|____80%___|
|                           |       Set #1   |    50%        |       85%      |
|       2313             
|-------------------|-------------------|-------------------|     
|                           |       Set #2   |___25%____|____81%___|
|_______________ |___________|___50%____|____87%___|
|                           |    
|       2314             |       <continuation>
|_______________ |
 
I'm not sure how to use the row.append() for such a situation.  For example, I 
first populate MotorName, then Set#1, then 25% and 80%.  Next I want to proceed 
to the next "subrow", so do I do a row.append() now?  If so does it append that 
"subrow" only, or does it automatically jump to the next MotorName row (2314)?  
Or is there another preferred method of filling such nested tables?

Any help would be greatly appreciated,

K Christman



import cPickle
import re
from tables import *

f=open('a.dat')
a=cPickle.load(f)
f.close()
f=open('b.dat')
b=cPickle.load(f)
f.close()
f=open('c.dat')
c=cPickle.load(f)
f.close()
f=open('d.dat')
d=cPickle.load(f)
f.close()

class MotorData(IsDescription):
    MotorCompany = StringCol(16,pos=0)   
    MotorType = StringCol(8,pos=1) 
    CatalogNum = StringCol(16,pos=2)
    SpecNum = StringCol(16,pos=3)
    N_RatedHP = UInt16Col(pos=4)
    N_Voltage = StringCol(16,pos=5)
    N_Hertz = UInt8Col(pos=6)
    N_Phase = UInt8Col(pos=7)
    N_FullLoadAmps = StringCol(16,pos=8)
    UsableAt208Volts = Float32Col(pos=9)
    N_SyncSpeed = UInt16Col(pos=10)
    FrameSize = StringCol(8,pos=11)
    N_ServiceFactor = Float32Col(pos=12)
    N_Rating = StringCol(16,pos=13)
    N_LockedRotorCode = StringCol(1,pos=14)
    N_NEMA_DesignCode = StringCol(1,pos=15)
    InsulationClass = StringCol(1,pos=16)
    N_NominalEfficiency = Float32Col(pos=17)   #this should be decimal
    N_NominalPowerFactor = Float32Col(pos=18)
    Enclosure = StringCol(8,pos=19)
    BaldorType = StringCol(8,pos=20)
    DE_Bearing = StringCol(8,pos=21)  #this could be a Int once we confirm they 
are all integers
    ODE_Bearing = StringCol(8,pos=22)
    ElectricalSpecNum = StringCol(16,pos=23)
    MechanicalSpecNum = StringCol(16,pos=24)
    Base = StringCol(8,pos=25)
    Mounting = StringCol(8,pos=26)
    #ExpSet = MotorDataExpSets()

    class ExpSets(IsDescription):
        #many of these should be converted to number formats
        #_v_pos = 1
        FullLoadTorque = Float32Col(pos=0)  
        StartConfig = StringCol(8,pos=1)
        BreakDownTorque = Float32Col(pos=2)
        PullUpTorque = Float32Col(pos=3)
        LockedRotorTorque = Float32Col(pos=4)
        StartingCurrent = Float32Col(pos=5)
        NoLoadCurrent = Float32Col(pos=6)
        LineLineResistance = Float32Col(pos=7)
        TempRiseatFL = UInt8Col(pos=8)
        TempRiseatSF = UInt8Col(pos=9)
        #ExpSets2 = MotorLoadTest()

        class ExpSets2(IsDescription):
            #_v_pos = 2
            pLoad = Float32Col(pos=0)
            PowerFactor = Float32Col(pos=1)
            Efficiency = Float32Col(pos=2)
            Speed = UInt16Col(pos=3)
            LineAmps = Float32Col(pos=4)
            
fileh = openFile('data2.h5', 'w')
DryExp = fileh.createTable(fileh.root, 'DryExp', MotorData)
row = DryExp.row

def returnNum(string):
    reg_ex = re.compile(r'([0-9.]*)')   #regular expression
    return float(reg_ex.search(string).group(1))

for i in range(10):
    row['N_RatedHP'] = returnNum(b[0][i])
    row['N_Hertz'] = int(b[1][i])
    row['N_NominalEfficiency'] = float(b[2][i])/100
    row['N_Voltage'] = b[3][i]
    row['N_Phase'] = int(b[4][i])
    row['N_NominalPowerFactor'] = float(b[5][i])/100
    row['N_FullLoadAmps'] = b[6][i]
    row['N_NEMA_DesignCode'] = b[7][i]
    row['N_ServiceFactor'] = float(b[8][i])
    row['N_SyncSpeed'] = int(b[9][i])
    row['N_LockedRotorCode'] = b[10][i]
    row['N_Rating'] = b[11][i]

    row['ExpSets/FullLoadTorque'] = float(returnNum(b[12][i]))
    row['ExpSets/StartingCurrent'] = float(returnNum(b[13][i]))
    row['ExpSets/StartConfig'] = b[14][i]
    row['ExpSets/NoLoadCurrent'] = float(returnNum(b[15][i]))
    row['ExpSets/BreakDownTorque'] = float(returnNum(b[16][i]))
    row['ExpSets/LineLineResistance'] = float(returnNum(b[17][i]))
    row['ExpSets/PullUpTorque'] = float(returnNum(b[18][i]))
    row['ExpSets/TempRiseatFL'] = int(b[19][i])
    row['ExpSets/LockedRotorTorque'] = float(returnNum(b[20][i]))
    row['ExpSets/TempRiseatSF'] = int(b[21][i])

    for j in range(2):        
        row['ExpSets/ExpSets2/pLoad'] = float(b[22+j][i])/100 
        row['ExpSets/ExpSets2/PowerFactor'] = float(b[29+j][i])/100 
        row['ExpSets/ExpSets2/Efficiency']= float(b[36+j][i])/100
        row['ExpSets/ExpSets2/Speed'] = int(b[43+j][i])
        row['ExpSets/ExpSets2/LineAmps'] = float(b[50+j][i])
        row.append()   #this should be for the subrow only        
    row.append()           

DryExp.flush()
fileh.close()






      
____________________________________________________________________________________
Looking for last minute shopping deals?  
Find them fast with Yahoo! Search.  
http://tools.search.yahoo.com/newsearch/category.php?category=shopping

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Pytables-users mailing list
Pytables-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pytables-users

Reply via email to