Fixed bug in CosmoPower/ Eisenstein & Hu
This commit is contained in:
parent
b7392204ad
commit
9629b24487
5 changed files with 44 additions and 19 deletions
|
@ -1,5 +1,6 @@
|
|||
from libcpp cimport bool
|
||||
from libcpp cimport string as cppstring
|
||||
from libcpp cimport vector as cppvector
|
||||
import numpy as np
|
||||
cimport numpy as np
|
||||
from cpython cimport PyObject, Py_INCREF
|
||||
|
@ -29,7 +30,7 @@ cdef extern from "cic.hpp" namespace "CosmoTool":
|
|||
@cython.cdivision(True)
|
||||
@cython.wraparound(False)
|
||||
def leanCic(float[:,:] particles, float L, int Resolution):
|
||||
cdef CICParticles p
|
||||
cdef cppvector.vector[CICParticles] *p
|
||||
cdef CICFilter *cic
|
||||
cdef np.uint64_t i
|
||||
cdef CICType *field
|
||||
|
@ -40,25 +41,34 @@ def leanCic(float[:,:] particles, float L, int Resolution):
|
|||
cdef np.uint64_t j
|
||||
|
||||
cic = new CICFilter(Resolution, L)
|
||||
print("Reset mesh")
|
||||
cic.resetMesh()
|
||||
|
||||
if particles.shape[1] != 3:
|
||||
raise ValueError("Particles must be Nx3 array")
|
||||
|
||||
p.mass = 1
|
||||
for i in xrange(particles.shape[0]):
|
||||
p.coords[0] = particles[i,0]
|
||||
p.coords[1] = particles[i,1]
|
||||
p.coords[2] = particles[i,2]
|
||||
cic.putParticles(&p, 1)
|
||||
print("Inserting particles")
|
||||
# p = new cppvector.vector[CICParticles](particles.shape[0])
|
||||
# for i in xrange(particles.shape[0]):
|
||||
# *p[i].mass = 1
|
||||
# *p[i].coords[0] = particles[i,0]
|
||||
# *p[i].coords[1] = particles[i,1]
|
||||
# *p[i].coords[2] = particles[i,2]
|
||||
|
||||
# cic.putParticles(&p[0], particles.shape[0])
|
||||
del p
|
||||
|
||||
print("Done")
|
||||
field = <CICType*>0
|
||||
dummyRes = 0
|
||||
cic.getDensityField(field, dummyRes)
|
||||
|
||||
print("Got to allocate a numpy %dx%dx%d" % (dummyRes, dummyRes,dummyRes))
|
||||
|
||||
out_field = np.empty((dummyRes, dummyRes, dummyRes), dtype=np.float64)
|
||||
out_field0 = out_field.reshape(out_field.size)
|
||||
out_field_buf = out_field
|
||||
print("Copy")
|
||||
for j in xrange(out_field_buf.size):
|
||||
out_field_buf[j] = field[j]
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@ cdef extern from "cosmopower.hpp" namespace "CosmoTool":
|
|||
void setFunction(CosmoFunction)
|
||||
void updateCosmology()
|
||||
void updatePhysicalCosmology()
|
||||
void normalize(double)
|
||||
void normalize(double,double)
|
||||
void setNormalization(double)
|
||||
double power(double)
|
||||
|
||||
|
@ -74,8 +74,11 @@ cdef class CosmologyPower:
|
|||
assert self.power.OMEGA_C > 0
|
||||
|
||||
self.power.updateCosmology()
|
||||
|
||||
def setNormalization(self,A):
|
||||
self.power.setNormalization(A)
|
||||
|
||||
def normalize(self,s8,k_max=-1):
|
||||
def normalize(self,s8,k_min=-1,k_max=-1):
|
||||
"""normalize(self, sigma8)
|
||||
|
||||
Compute the normalization of the power spectrum using sigma8.
|
||||
|
@ -84,7 +87,7 @@ cdef class CosmologyPower:
|
|||
sigma8 (float): standard deviation of density field smoothed at 8 Mpc/h
|
||||
"""
|
||||
self.power.SIGMA8 = s8
|
||||
self.power.normalize(k_max)
|
||||
self.power.normalize(k_min, k_max)
|
||||
|
||||
|
||||
def setFunction(self,funcname):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue