This script shows how to make plots using the parseparticles module. usage: ./test.py particleFile1 [particleFile2 particleFile3 ... ]
(fileList)
| 8 | import pylab |
| 9 | |
| 10 | def main(fileList): |
| 11 | """ |
| 12 | This script shows how to make plots using the parseparticles module. |
| 13 | |
| 14 | usage: ./test.py particleFile1 [particleFile2 particleFile3 ... ] |
| 15 | """ |
| 16 | |
| 17 | # this returns a dict whose keys are a unique identifier (based on |
| 18 | # id and CPU) and values are the actual particle objects |
| 19 | particlesDict = parseparticles.parseParticleFile(fileList) |
| 20 | |
| 21 | # get just the particle objects |
| 22 | particles = particlesDict.values() |
| 23 | |
| 24 | print "there are %d unique particles" % len(particles) |
| 25 | |
| 26 | # plots - this is based on the plotting done in the original |
| 27 | # parseparticles.py script, which has since become a module for importing |
| 28 | pylab.clf() |
| 29 | |
| 30 | # global domain extrema |
| 31 | xmin = 1.e33 |
| 32 | xmax = -1e33 |
| 33 | ymin = 1.e33 |
| 34 | ymax = -1.e33 |
| 35 | |
| 36 | # loop over the particle objects and create the particle paths |
| 37 | for particle in particles: |
| 38 | coords, time = particle.flatten() |
| 39 | |
| 40 | # find the extrema of the particles over time to make all frames the |
| 41 | # same size |
| 42 | xmin = min(xmin,min(coords[0,:])) |
| 43 | xmax = max(xmax,max(coords[0,:])) |
| 44 | ymin = min(ymin,min(coords[1,:])) |
| 45 | ymax = max(ymax,max(coords[1,:])) |
| 46 | |
| 47 | pylab.scatter([coords[0,0]], [coords[1,0]], marker="x") |
| 48 | pylab.plot(coords[0,:], coords[1,:]) |
| 49 | |
| 50 | pylab.xlabel("x") |
| 51 | pylab.ylabel("y") |
| 52 | |
| 53 | pylab.savefig("particle_paths.png") |
| 54 | |
| 55 | # make an animation -- note: this assumes that all particles exist at all |
| 56 | # timesteps |
| 57 | |
| 58 | |
| 59 | # grab the total number of timesteps from the first particle's history |
| 60 | # totalSteps = len(particles[0].history) |
| 61 | |
| 62 | # nstep = 0 |
| 63 | # while (nstep < totalSteps): |
| 64 | # pylab.clf() |
| 65 | |
| 66 | # for particle in particles: |
| 67 | # pylab.scatter([particle.history[nstep].xyz[0]], |
no test coverage detected