Python Tutorial

Python API

The python API is designed for ease of use. For speed critical applications, C++ API should be used. Looping in python is extremely slow. It is hoped that in the future a mapping to numpy might be provided to allow manipulating particles in a SIMD fashion. Nevertheless, python API remains useful for manipulating particles.

To use Partio's python API first import partio as

 import partio

Help on functions that are available are shown in


Creating a Particle Set

To create a particle set and add a couple of attributes one could write


Once this is done, we could add a series of particles that form a circle

for i in range(n):

Finally, we can write the particle file into a BGEO by writing

partio.write("circle.bgeo",particleSet) # write uncompressed
partio.write("circle.bgeo",particleSet,True) # write compressed
partio.write("circle.bgeo.gz",particleSet) # write compressed

We can then visualize the particle set with

partview circle.bgeo

yielding the image


Loading a particle set

Loading a particle set is relatively easy. If you only want to know how many particles are available or what headers are available you can do

>>> pHeaders=partio.readHeaders("circle.bgeo")

If you want everything associated with the file



Finding nearest neighbors

A KD-Tree mode is supported in partio. To use it, you must first sort the particles into a KD-Tree. This is done with the |sort()| function. Once that is done a query can be done. The basic query requires a maximum distance to look for particles as well as a maximum number of particles to return. For example, we could read our circle back in and look for particles nearby (1,0,0) like so:"circle.bgeo")

Generated on 5 Apr 2011 for Partio by  doxygen 1.6.1