Exemplo n.º 1
0
    def __call__(self, r, rt=100000, smooth=True, smooth_scale=0.1):
        """
        Evaluates the joined SIDM and NFW density profile as a function of r
        :param r: radius at which to evaluate the profile in kpc
        :param rt: truncation radius of the truncated NFW halo
        :param smooth: if True, convolves the profile with a Gaussian to remove the sharp density profile discontinuity
        at r_1
        :param smooth_scale: sets the smoothing scale length (in units of rs) for the convolution if smooth is True
        :return: the density profile evaluated at r
        """

        if isinstance(r, np.ndarray) or isinstance(r, list):
            r = np.array(r)
            out = np.empty_like(r)
            inds_0 = np.where(r <= self._rmin)
            inds_iso = np.where((r > self._rmin) & (r <= self._rmatch))
            inds_nfw = np.where(r > self._rmatch)
            out[inds_0] = self.rho0
            out[inds_iso] = self.rho_iso_interp(r[inds_iso])
            out[inds_nfw] = TNFWprofile(r[inds_nfw], self.rhos, self.rs, rt)
            if smooth:
                out = gaussian_filter(out, sigma=smooth_scale * self.rs)
            return out

        else:
            if r <= self._rmin:
                return self.rho0
            elif r <= self._rmatch:
                return self.rho_iso_interp(r)
            else:
                return TNFWprofile(r, self.rhos, self.rs, rt)
Exemplo n.º 2
0
 def _func_to_min(r):
     r = r[0]
     vdispersion_halo = nfw_velocity_dispersion_analytic(r, rhos, rs)
     cm2_per_gram_times_sigmav = cross_section_class.scattering_rate_cross_section(
         vdispersion_halo)
     func = const * TNFWprofile(r, rhos, rs, 100000 * rs
                                ) * cm2_per_gram_times_sigmav * halo_age - 1
     return func
Exemplo n.º 3
0
    def test_solver(self):

        mass_nfw = nfwprofile_mass(self.rhos, self.rs, self.r1)
        density_nfw = TNFWprofile(self.r1, self.rhos, self.rs, 1000 * self.rs)
        r_iso, rho_iso = integrate_profile(self.rho0, self.sigmav, self.rs,
                                           self.r1)
        mass_isothermal = isothermal_profile_mass(r_iso, rho_iso, self.r1)
        density_isothermal = isothermal_profile_density(
            self.r1, r_iso, rho_iso)
        npt.assert_almost_equal(density_isothermal / density_nfw, 1, 2)
        npt.assert_almost_equal(mass_nfw / mass_isothermal, 1, 2)
Exemplo n.º 4
0
    def test_nfw_velocity_dispersion(self):

        rhos, rs = 24199124.73664613, 0.55074782382099
        rt = 10000 * rs
        r = np.linspace(0.01, 10, 1000) * rs
        vdis_square = np.array(
            [nfw_velocity_dispersion_analytic(ri, rhos, rs) for ri in r])**2
        G = 4.3e-6

        def _integrand(rprime):
            return TNFWprofile(rprime, rhos, rs, rt) * G * nfwprofile_mass(
                rhos, rs, rprime) / rprime**2

        for i, ri in enumerate(r):
            value = quad(_integrand, ri, 10000 * rs)[0] / TNFWprofile(
                ri, rhos, rs, rt)
            npt.assert_almost_equal(vdis_square[i] / value, 1, 3)
Exemplo n.º 5
0
def compute_rho_sigmav_grid(log_rho_values, vdis_values, rhos, rs,
                            cross_section_class, halo_age, rmin_profile,
                            rmax_profile, use_nfw_velocity_dispersion):

    fit_grid = np.ones_like(log_rho_values) * 1e+12
    fit_grid = fit_grid.ravel()
    # compute the fit quality for each point in the search space

    for i, (log_rho_i, velocity_dispersion_i) in enumerate(
            zip(log_rho_values, vdis_values)):

        if use_nfw_velocity_dispersion:
            r1 = compute_r1_nfw_velocity_dispersion(rhos, rs,
                                                    cross_section_class,
                                                    halo_age)
        else:
            r1 = compute_r1(rhos, rs, velocity_dispersion_i,
                            cross_section_class, halo_age)

        r_iso, rho_iso = integrate_profile(10**log_rho_i,
                                           velocity_dispersion_i,
                                           rs,
                                           r1,
                                           rmin_fac=rmin_profile,
                                           rmax_fac=rmax_profile)

        m_enclosed = isothermal_profile_mass(r_iso, rho_iso, r1)
        rho_at_r1 = isothermal_profile_density(r1, r_iso, rho_iso)
        m_nfw = nfwprofile_mass(rhos, rs, r1)
        rho_nfw_at_r1 = TNFWprofile(r1, rhos, rs, 10000000 * rs)

        mass_ratio = m_nfw / m_enclosed
        density_ratio = rho_nfw_at_r1 / rho_at_r1

        mass_penalty = np.absolute(mass_ratio - 1)
        den_penalty = np.absolute(density_ratio - 1)

        fit_qual = mass_penalty + den_penalty
        fit_grid[i] = fit_qual

    return fit_grid
Exemplo n.º 6
0
def nfw_velocity_dispersion(r, rho_s, rs, tol=1e-4):
    """

    :param r:
    :param rho_s:
    :param rs:
    :return:
    """
    def _integrand(rprime):
        return TNFWprofile(rprime, rho_s, rs, 1000000000 *
                           rs) * nfwprofile_mass(rho_s, rs, rprime) / rprime**2

    rmax_init = 2 * rs
    rmax_scale = 2.
    rmax = rmax_init + rmax_scale * rs
    integral = quad(_integrand, r, rmax)[0]
    count_max = 5.
    count = 0
    while True:
        rmax *= rmax_scale
        integral_new = quad(_integrand, r, rmax)[0]
        fit = abs(integral_new / integral - 1)

        if fit < tol:
            break
        elif count > count_max:
            print(
                'warning: NFW velocity dispersion computtion did not converge to more than '
                + str(fit))
            break
        else:
            count += 1
            integral = integral_new

    G = 4.3e-6  # units kpc/M_sun * (km/sec)^2
    sigma_v_squared = G * integral_new / TNFWprofile(r, rho_s, rs, 1e+6 * rs)
    return np.sqrt(sigma_v_squared)
Exemplo n.º 7
0
 def _integrand(rprime):
     return TNFWprofile(rprime, rho_s, rs, 1000000000 *
                        rs) * nfwprofile_mass(rho_s, rs, rprime) / rprime**2
Exemplo n.º 8
0
 def _integrand(rprime):
     return TNFWprofile(rprime, rhos, rs, rt) * G * nfwprofile_mass(
         rhos, rs, rprime) / rprime**2