A Friday 29 January 2010 12:52:01 Francesc Alted escrigué:
> I'm attaching a small script showing you how to do what you are trying to
>  do in an 'pytablish' manner.  As you will see, it splits the original
>  table in one file in two ('slow' and 'fast') in another file.

Ooops!  I forgot the handy and efficient `Table.whereAppend()` method.  With 
it, your problem is reduced to something like:

# Fast particles...
fast = f2.createTable(f2.root, 'fast', table1.description)
table1.whereAppend(fast, "sqrt(x_g**2+y_g**2+z_g**2) > cut")

# Slow particles...
slow = f2.createTable(f2.root, 'slow', table1.description)
table1.whereAppend(slow, "sqrt(x_g**2+y_g**2+z_g**2) <= cut")

Attached is the new version of the script.

Cheers,

-- 
Francesc Alted
from tables import openFile, Float64Col

N = 1000*1000  # the number of particles
cut = 300000*.1

# The definition or your particle
particle = {
    "x_g": Float64Col(shape=(), dflt=0.0, pos=4),
    "y_g": Float64Col(shape=(), dflt=0.0, pos=5),
    "z_g": Float64Col(shape=(), dflt=0.0, pos=6),
    }

# Create initial file and table
f = openFile("/tmp/initial.h5", "w")
table1 = f.createTable(f.root, 'table1', particle)

# Populate the table with some arbitrary values for speed
row = table1.row
for x in xrange(N):
    row["x_g"] = x
    row["y_g"] = x*2
    row["z_g"] = x/2
    row.append()
table1.flush()

# Create a new file for the split
f2 = openFile("/tmp/final.h5", "w")

# Now, split the table in two with 'slow' and 'fast' particles each
# Fast particles...
fast = f2.createTable(f2.root, 'fast', table1.description)
table1.whereAppend(fast, "sqrt(x_g**2+y_g**2+z_g**2) > cut")

# Slow particles...
slow = f2.createTable(f2.root, 'slow', table1.description)
table1.whereAppend(slow, "sqrt(x_g**2+y_g**2+z_g**2) <= cut")

f.close()
f2.close()
------------------------------------------------------------------------------
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the business
Choose flexible plans and management services without long-term contracts
Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com
_______________________________________________
Pytables-users mailing list
Pytables-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pytables-users

Reply via email to