import yt
import numpy as np
# Create fake particle data for a million particles randomly distributed
ppx, ppy, ppz, ppm = np.random.random([4, 1e6])
data = {'particle_position_x': ppx,
'particle_position_y': ppy,
'particle_position_z': ppz,
'particle_mass': ppm}
ds = yt.load_particles(data, length_unit=3.08e24, mass_unit=1.9891e36)
ad = ds.all_data()
print ad['deposit', 'all_cic']
[ 2.51443487e-32 9.28708318e-33 1.89306578e-32 ..., 2.09942761e-32 2.96852128e-32 6.63823283e-32] g/cm**3
slc = yt.SlicePlot(ds, 2, ('deposit', 'all_cic'))
slc.set_figure_size(4)
#level 5 corresponds to a 32^3 array
cg = ds.covering_grid(level=5, left_edge=[0,0,0], dims=[32, 32, 32])
arr = cg['deposit', 'all_density']
print arr.max()
print arr.min()
print arr.mean()
print arr.shape
1.43198668242e-31 g/cm**3 0.0 g/cm**3 3.41235550567e-32 g/cm**3 (32, 32, 32)
arr.write_hdf5('cic_deposited_data.h5')
import h5py
f = h5py.File('cic_deposited_data.h5')
print f['array_data'][:].min()
print f['array_data'][:].max()
print f['array_data'][:].mean()
print f['array_data'].shape
0.0 1.43198668242e-31 3.41235550567e-32 (32, 32, 32)