cosmotool/python/cosmotool/cic.py

21 lines
1003 B
Python

import numpy as np
def cicParticles(particles, L, N):
for d in xrange(3):
q = particles[d]*N/L
i.append(np.floor(q).astype(int))
r.append(q-i[-1])
density = np.bincount(shifted(i, (0,0,0)), weights= r[0]* r[1]* r[2], minlength=N*N*N)
density += np.bincount(shifted(i, (0,0,1)), weights= r[0]* r[1]*(1-r[2]), minlength=N*N*N)
density += np.bincount(shifted(i, (0,1,0)), weights= r[0]*(1-r[1])* r[2], minlength=N*N*N)
density += np.bincount(shifted(i, (0,1,1)), weights= r[0]*(1-r[1])*(1-r[2]), minlength=N*N*N)
density += np.bincount(shifted(i, (1,0,0)), weights=(1-r[0])* r[1]* r[2], minlength=N*N*N)
density += np.bincount(shifted(i, (1,0,1)), weights=(1-r[0])* r[1]*(1-r[2]), minlength=N*N*N)
density += np.bincount(shifted(i, (1,1,0)), weights=(1-r[0])*(1-r[1])* r[2], minlength=N*N*N)
density += np.bincount(shifted(i, (1,1,1)), weights=(1-r[0])*(1-r[1])*(1-r[2]), minlength=N*N*N)
return density