Hi, I am trying to dump the particle_positions to a file. Here is my extremely inefficient script... from yt.mods import * import pickle fn = "RedshiftOutput0000" # parameter file to load pf = load(fn) # load data all_data = pf.h.all_data() particle_positions_x = all_data['particle_position_x'] particle_positions_y = all_data['particle_position_y'] particle_positions_z = all_data['particle_position_z'] Dark_Matter_Density = all_data['Dark_Matter_Density'] # this is a Dataset {32, 32, 64} f1 = open('junk1', 'w') f2 = open('junk2', 'w') f3 = open('junk3', 'w') s1 = str(particle_positions_x) s2 = str(particle_positions_y) s3 = str(particle_positions_z) f1.write(s1) f2.write(s2) f3.write(s3) f1.close() f2.close() f3.close() How can I write out x-,y- and z positions in three columns in the same file ? And how to handle the array Dark_Matter_Density ? Shankar KU Cosmology
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.htm... 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@physics.ucsd.edu o__ Stephen Skory http://physics.ucsd.edu/~sskory/ _.>/ _Graduate Student ________________________________(_)_\(_)_______________
participants (2)
-
Agarwal, Shankar -
Stephen Skory