[CentralOH] Post-processing of output files/creating animation

Yung-Yu Chen yyc at seety.org
Wed Aug 4 17:24:25 CEST 2010

On Wed, Aug 4, 2010 at 11:03, Armen Ezekielian <aezekielian at gmail.com>wrote:

> I have a C program  which outputs a six-column by N-row
> data file for each time step of a simulation. The six columns
> contain floats representing the coordinates and velocity
> components for N particles. N is generally on the order of a
> few hundred and there are at least 1000 of these files.
>                                     x     y     z     v_x     v_y     v_z
> N of these lines -->        1.0  1.3  1.1    2.6     1.9     3.8
> And as I said there is one of these files for each time step.
> I was hoping to use python to process these data files and
> create a visualization using the visual.sphere() function
> in VPython. I want to render a sphere at every x, y, z
> point and color the spheres according to a colormap
> based on the magnitude of the velocity (red = fast,
> blue = slow). This would be done for each time step file
> and then loop through them to create an animation.
The following code should be able to parse your data file into numpy.ndarray
.  You need numpy installed.   I am not familiar with vpython, but I guess
the data should be fairly easy to be processed once you have the data become
a numpy.ndarray.

#!/usr/bin/env python
def main():
    import sys
    from numpy import array
    if len(sys.argv) < 2: return
    lines = open(sys.argv[1]).readlines()[1:]
    arr = array(
        [[float(val) for val in line.split()] for line in lines],
    print arr
if __name__ == '__main__':

> Unfortunately I have limited python experience and little
> time to accomplish this. If anyone has any tips/suggestions
> on how to do the file I/O I would be extremely grateful. I am
> researching the problem myself but the majority of my time is
> being spent helping the students debug/run their C programs
> which produce the output files above. Thank you!!!
> --Armen
> _______________________________________________
> CentralOH mailing list
> CentralOH at python.org
> http://mail.python.org/mailman/listinfo/centraloh

Yung-Yu Chen
PhD candidate at The Ohio State University
Columbus, Ohio
+1 (614) 292 6745
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/mailman/private/centraloh/attachments/20100804/ae385433/attachment.html>

More information about the CentralOH mailing list