[yt-users] writing x-,y- and z positions in one file

Stephen Skory stephenskory at yahoo.com
Wed Jun 9 10:40:31 PDT 2010


Shankar,

> I am trying to dump the particle_positions to a file. Here is my 
> extremely inefficient script...

It's slow because you're writing to a text file. It would be faster to write to binary. However, numpy's 'tofile' command will probably be faster than what you've got, and it can write to a text file:

http://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.tofile.html

It would be something like:

In [1]: import numpy as na

In [2]: I = na.random.random(9)

In [3]: I.tofile('I.dat', sep = " ", format="%1.5e\n")


%cat I.dat
6.31265e-01
 7.37249e-01
 8.32688e-02
 4.91137e-01
 6.83693e-01
 1.89788e-01
 6.74790e-01
 9.72683e-01
 9.24882e-01

I also suggest trying to save data using h5py, if they're going to be large fields.

Good luck!

_______________________________________________________
sskory at physics.ucsd.edu o__ Stephen Skory
http://physics.ucsd.edu/~sskory/ _.>/ _Graduate Student
________________________________(_)_\(_)_______________




More information about the yt-users mailing list