I'm trying to integrate this nasty integral that consists of couple of functions.
import matplotlib.pyplot as plt
import numpy as np
import os
import scipy.integrate as integrate
path = '/users/username/Desktop/untitled folder/python files/document/'
os.chdir( path )
data = np.load('msii_phasespace.npy',mmap_mode='r')
# data.size: 167197
# data.shape: (167197,)
# data.dtype: dtype([('x', '<f4'), ('y', '<f4'), ('z', '<f4'),
# ('velx', '<f4'), ('vely', '<f4'), ('velz', '<f4'), ('m200', '<f4')])
## Constant
rho_m = 3.3e-14
M = data['x'] Mass of dark matter haloes
R = ((3*M)/(rho_m*4*(3.14)))**(1.0/3.0) # Km // Radius of sphere
k = 0.001 # Mpc h^-1 // Wave Dispersion relation
delt_c = 1.686
h = 0.73 # km s^-1 Mpc^-1
e = 2.718281 # Eulers number
T_CMB = 2.725
Omega_m = 0.27
kR = k*R
def T(k):
q = k/((Omega_m)*h**2)*((T_CMB)/27)**2
L = np.log(e+1.84*q)
C = 14.4 + 325/(1+60.5*q**1.11)
return L/(L+C*q**2)
def P(k):
A = 0.75
n = 0.95
return A*k**n*T(k)**2
def W(kR): # Fourier Transfrom in the top hat function
return 3*(np.sin(k*R)-k*R*np.cos(k*R))/(k*R)**3
def sig(R):
def integrand(k,P,W):
return k**2*P(k)*W(kR)**2
I1 = integrate.quad(integrand, lambda k: 0.0, lambda k: np.Inf, args=(k,))
return ((1.0/(2.0*np.pi**2)) * I1)**0.5
printing out the sig(R) gives me TypeError: a float is require
.
I need to note that R is a radius of a object that is directly proportional to its mass. The masses are given by an structured array. I'm not sure if I am using the correct integral command to evaluate all the masses. Only the array has a set of values.
If you need anymore information, please tell, and i'll be happy to share whatever I can. Any advice will be appreciated.