예제 #1
0
    def jenkins_mass_function(self, M, sigma_sq):
        sigma = lambda m: np.sqrt(sigma_sq(m))

        dlogSigma_dlogM = differentiate(
            lambda log_m: np.log(sigma(np.exp(log_m))), h=0.01)(np.log(M))

        f = 0.315 * np.exp(-np.fabs(np.log(1 / sigma(M)) + 0.61)**3.8)

        return self.__phys.rho0 / M**2 * f * np.fabs(dlogSigma_dlogM)
예제 #2
0
    def press_schechter_mass_function(self, M, sigma_sq):
        sigma = lambda m: np.sqrt(sigma_sq(m))

        dlogSigma_dlogM = differentiate(
            lambda log_m: np.log(sigma(np.exp(log_m))), h=0.01)(np.log(M))

        return np.sqrt(
            2 / np.pi) * (self.__phys.rho0 * self.__phys.delta_crit /
                          sigma(M) / M**2) * np.fabs(dlogSigma_dlogM) * np.exp(
                              -self.__phys.delta_crit**2 / (2 * sigma(M)**2))
예제 #3
0
    def __init__(self,
                 power_spectrum,
                 mode_evolution,
                 kmin=1.0e-3,
                 kmax=1.0e4,
                 mMin=1e12,
                 mMax=1e15,
                 physics=None,
                 AXIONS=True,
                 jenkins_mass=False,
                 window_function=GAUSSIAN):
        """

		:type power_spectrum: function(float)->float
		:type mode_evolution: GrowthInterpolation
		:type kmin: float
		:type kmax: float
		:type mMin: float
		:type mMax: float
		:type physics: Physics
		:type AXIONS: bool
		:type jenkins_mass: bool
		"""

        if physics is None:
            self.__phys = Physics(True, True)
        else:
            self.__phys = physics

        self.__mMin = mMin
        self.__mMax = mMax
        self.__kmin = kmin
        self.__kmax = kmax

        self.__jenkins_mass = jenkins_mass
        self.__AXIONS = AXIONS

        self.__power_spectrum = power_spectrum

        if window_function == mean_pairwise_velocity.TOP_HAT:
            self.__window_function = mean_pairwise_velocity.top_hat_window
            self.__radius_of_mass = self.radius_of_mass_top_hat
        elif window_function == mean_pairwise_velocity.GAUSSIAN:
            self.__window_function = mean_pairwise_velocity.gaussian_window
            self.__radius_of_mass = self.radius_of_mass_gaussian
        elif window_function == mean_pairwise_velocity.SHARP_K:
            self.__window_function = mean_pairwise_velocity.sharp_k_window
            self.__radius_of_mass = self.radius_of_mass_sharp_k
        elif window_function == mean_pairwise_velocity.NO_FILTER:
            self.__window_function = mean_pairwise_velocity.no_window
            self.__radius_of_mass = self.radius_of_mass_top_hat
        else:
            print("This doesn't work!")
            print(window_function)
            raise Exception("Function Comparision fails!")

        if AXIONS:
            axion_G, axion_dlogG_dlogA = mode_evolution.get_growth(
            ), mode_evolution.get_dlogG_dlogA()
            self.__growth, self.__G0, self.__dlogG_dlogA = lambda K, A: axion_G(
                A, K), lambda K: axion_G(1, K), lambda K, A: axion_dlogG_dlogA(
                    A, K)
        else:
            dz_interp = self.__phys.get_D_interpolation(recompute=True,
                                                        save=False)
            D0 = self.__phys.D(0)

            cdm_growth = lambda k, a: dz_interp((1 - a) / a)
            cdm_dlogG_dlogA = lambda K, A: differentiate(
                lambda log_a: cdm_growth(K, np.exp(log_a)), h=0.01)(np.log(
                    A)) / cdm_growth(K, A)
            cdm_G0 = lambda k: D0

            self.__growth, self.__G0, self.__dlogG_dlogA = cdm_growth, cdm_G0, cdm_dlogG_dlogA
예제 #4
0
    def __init__(self,
                 power_spectrum,
                 mode_evolution,
                 zmin,
                 zmax,
                 Nz,
                 r_vals,
                 deltaR,
                 f_sky,
                 sigma_v_vals,
                 kmin=1.0e-3,
                 kmax=1.0e4,
                 mMin=1e12,
                 mMax=1e15,
                 physics=None,
                 jenkins_mass=False,
                 window_function=mean_pairwise_velocity.GAUSSIAN):

        if physics is None:
            self.__phys = Physics(True, True)
        else:
            self.__phys = physics

        self.__zmin = zmin
        self.__zmax = zmax
        self.__mMin = mMin
        self.__mMax = mMax
        self.__kmin = kmin
        self.__kmax = kmax
        self.__f_sky = f_sky
        self.__sigma_v_vals = sigma_v_vals
        self.__deltaR = deltaR
        self.vs = []
        self.correlation_f = []

        self.__r_vals = r_vals
        self.__z_vals = np.linspace(zmin, zmax, Nz + 1)

        self.__window_function = None
        self.__radius_of_mass = None

        if jenkins_mass:
            self.__mass_function = self.jenkins_mass_function
        else:
            self.__mass_function = self.press_schechter_mass_function

        self.__AXIONS = False

        self.__power_spectrum = power_spectrum

        if self.__AXIONS:
            axion_G, axion_dlogG_dlogA = mode_evolution.get_growth(
            ), mode_evolution.get_dlogG_dlogA()
            self.__growth, self.__G0, self.__dlogG_dlogA = lambda K, A: axion_G(
                A, K), lambda K: axion_G(1, K), lambda K, A: axion_dlogG_dlogA(
                    A, K)
        else:
            dz_interp = self.__phys.get_D_interpolation(recompute=True,
                                                        save=False)
            D0 = self.__phys.D(0)

            cdm_growth = lambda k, a: dz_interp((1 - a) / a)
            cdm_dlogG_dlogA = lambda K, A: differentiate(
                lambda log_a: cdm_growth(K, np.exp(log_a)), h=0.01)(np.log(
                    A)) / cdm_growth(K, A)
            cdm_G0 = lambda k: D0

            self.__growth, self.__G0, self.__dlogG_dlogA = cdm_growth, cdm_G0, cdm_dlogG_dlogA
            self.__f = lambda a: self.__dlogG_dlogA(0, a)

        R1, R2 = np.meshgrid(self.__r_vals, self.__r_vals)
        self.__r_pairs = [(R1.flatten()[i], R2.flatten()[i])
                          for i in range(0,
                                         len(self.__r_vals)**2)]

        output = []
        with MyProcessPool(min([6, Nz])) as pool:
            output = list(
                pool.imap(
                    lambda i: self.evaluate_covariance(i, window_function),
                    np.arange(0, Nz, 1)))

        self.__covariance = np.empty((Nz, len(r_vals), len(r_vals)))
        self.__inv_covariance_interpolations = np.empty((Nz), dtype='object')

        for i in range(Nz):
            self.__covariance[i, :, :] = np.reshape(output[i][0],
                                                    (len(r_vals), len(r_vals)))
            self.__inv_covariance_interpolations[i] = RectBivariateSpline(
                r_vals,
                r_vals,
                np.linalg.inv(self.__covariance[i]),
                bbox=[min(r_vals),
                      max(r_vals),
                      min(r_vals),
                      max(r_vals)])
            self.vs.append(output[i][1])
            self.correlation_f.append(output[i][2])