Ejemplo n.º 1
0
def test_list_dc():
    smd = SurfaceMassDensity(r_s,
                             dc_list,
                             rho_c,
                             offsets=sig_off,
                             rbins=rbinarray)
    assert_equal(smd._delta_c, delta_c)
Ejemplo n.º 2
0
def test_list_sigoff():
    smd = SurfaceMassDensity(r_s,
                             delta_c,
                             rho_c,
                             offsets=soff_list,
                             rbins=rbinarray)
    assert_equal(smd._sigmaoffset, sig_off)
Ejemplo n.º 3
0
def test_list_rs():
    smd = SurfaceMassDensity(rs_list,
                             delta_c,
                             rho_c,
                             offsets=sig_off,
                             rbins=rbinarray)
    assert_equal(smd._rs, r_s)
Ejemplo n.º 4
0
def test_centered_profiles():
    def _check_sigma(i):
        assert_allclose(sigma_py.value, toy_data_sigma[i], rtol=1e-04)

    def _check_deltasigma(i):
        assert_allclose(deltasigma_py.value,
                        toy_data_deltasigma[i],
                        rtol=1e-04)
        # note: default tolerance is (rtol=1e-07, atol=0)

    zipped_inputs = zip(toy_data_rs, toy_data_dc, toy_data_rhoc)

    # check all 4 sets of toy_data:
    for i, (r_s, delta_c, rho_c) in enumerate(zipped_inputs):

        smd = SurfaceMassDensity(r_s, delta_c, rho_c, rbins=toy_data_rbins)
        sigma_py = smd.sigma_nfw()
        _check_sigma(i)

        deltasigma_py = smd.deltasigma_nfw()
        _check_deltasigma(i)
Ejemplo n.º 5
0
def test_centered_profiles():

    def _check_sigma(i):
        assert_allclose(sigma_py.value, toy_data_sigma[i],
                        rtol=1e-04)

    def _check_deltasigma(i):
        assert_allclose(deltasigma_py.value, toy_data_deltasigma[i],
                        rtol=1e-04)
        # note: default tolerance is (rtol=1e-07, atol=0)

    zipped_inputs = zip(toy_data_rs, toy_data_dc, toy_data_rhoc)

    # check all 4 sets of toy_data:
    for i, (r_s, delta_c, rho_c) in enumerate(zipped_inputs):

        smd = SurfaceMassDensity(r_s, delta_c, rho_c, rbins=toy_data_rbins)
        sigma_py = smd.sigma_nfw()
        _check_sigma(i)

        deltasigma_py = smd.deltasigma_nfw()
        _check_deltasigma(i)
Ejemplo n.º 6
0
def test_miscentered_profiles():

    def _check_sigma(i):
        assert_allclose(sigma_py_off.value, toy_data_sigma_off[i],
                        rtol=1e-04)

    def _check_deltasigma(i):
        assert_allclose(deltasigma_py_off.value, toy_data_deltasigma_off[i],
                        rtol=1e-04)

    zipped_inputs = zip(toy_data_rs, toy_data_dc, toy_data_rhoc)

    # check all 4 sets of toy_data:
    for i, (r_s, delta_c, rho_c) in enumerate(zipped_inputs):

        smd = SurfaceMassDensity(r_s, delta_c, rho_c,
                                 offsets=toy_data_offset,
                                 rbins=toy_data_rbins)
        sigma_py_off = smd.sigma_nfw()
        _check_sigma(i)

        deltasigma_py_off = smd.deltasigma_nfw()
        _check_deltasigma(i)
Ejemplo n.º 7
0
def test_miscentered_profiles():
    def _check_sigma(i):
        assert_allclose(sigma_py_off.value, toy_data_sigma_off[i], rtol=1e-04)

    def _check_deltasigma(i):
        assert_allclose(deltasigma_py_off.value,
                        toy_data_deltasigma_off[i],
                        rtol=1e-04)

    zipped_inputs = zip(toy_data_rs, toy_data_dc, toy_data_rhoc)

    # check all 4 sets of toy_data:
    for i, (r_s, delta_c, rho_c) in enumerate(zipped_inputs):

        smd = SurfaceMassDensity(r_s,
                                 delta_c,
                                 rho_c,
                                 offsets=toy_data_offset,
                                 rbins=toy_data_rbins)
        sigma_py_off = smd.sigma_nfw()
        _check_sigma(i)

        deltasigma_py_off = smd.deltasigma_nfw()
        _check_deltasigma(i)
Ejemplo n.º 8
0
def test_rhoc_units():
    rhoc_unitless = rho_c.value
    rhoc_wrongunits = rho_c.value * units.kg / units.m**3

    # test that a dimensionless rho_c is coverted to Msun/Mpc/pc**2
    smd = SurfaceMassDensity(r_s,
                             delta_c,
                             rhoc_unitless,
                             offsets=sig_off,
                             rbins=rbinarray)
    assert_equal(smd._rho_crit.unit, units.Msun / units.Mpc / units.pc**2)

    # test that an incorrect unit on rho_c raises an error
    assert_raises(ValueError,
                  SurfaceMassDensity,
                  r_s,
                  delta_c,
                  rhoc_wrongunits,
                  offsets=sig_off,
                  rbins=rbinarray)
Ejemplo n.º 9
0
def test_rs_units():
    rs_unitless = r_s.value
    rs_wrongunits = r_s.value * units.Msun

    # test that a dimensionless rs is coverted to Mpc
    smd = SurfaceMassDensity(rs_unitless,
                             delta_c,
                             rho_c,
                             offsets=sig_off,
                             rbins=rbinarray)
    assert_equal(smd._rs.unit, units.Mpc)

    # test that a non-Mpc unit on rs raises an error
    assert_raises(ValueError,
                  SurfaceMassDensity,
                  rs_wrongunits,
                  delta_c,
                  rho_c,
                  offsets=sig_off,
                  rbins=rbinarray)
Ejemplo n.º 10
0
    def calc_nfw(self, rbins, offsets=None, numTh=200, numRoff=200,
                 numRinner=20, factorRouter=3):
        """Calculates Sigma and DeltaSigma profiles.

        Generates the surface mass density (sigma_nfw attribute of parent
        object) and differential surface mass density (deltasigma_nfw
        attribute of parent object) profiles of each cluster, assuming a
        spherical NFW model. Optionally includes the effect of cluster
        miscentering offsets.

        Parameters
        ----------
        rbins : array_like
            Radial bins (in Mpc) for calculating cluster profiles. Should
            be 1D, optionally with astropy.units of Mpc.
        offsets : array_like, optional
            Parameter describing the width (in Mpc) of the Gaussian
            distribution of miscentering offsets. Should be 1D, optionally
            with astropy.units of Mpc.

        Other Parameters
        -------------------
        numTh : int, optional
            Parameter to pass to SurfaceMassDensity(). Number of bins to
            use for integration over theta, for calculating offset profiles
            (no effect for offsets=None). Default 200.
        numRoff : int, optional
            Parameter to pass to SurfaceMassDensity(). Number of bins to
            use for integration over R_off, for calculating offset profiles
            (no effect for offsets=None). Default 200.
        numRinner : int, optional
            Parameter to pass to SurfaceMassDensity(). Number of bins at
            r < min(rbins) to use for integration over Sigma(<r), for
            calculating DeltaSigma (no effect for Sigma ever, and no effect
            for DeltaSigma if offsets=None). Default 20.
        factorRouter : int, optional
            Parameter to pass to SurfaceMassDensity(). Factor increase over
            number of rbins, at min(r) < r < max(r), of bins that will be
            used at for integration over Sigma(<r), for calculating
            DeltaSigma (no effect for Sigma, and no effect for DeltaSigma
            if offsets=None). Default 3.
        """
        if offsets is None:
            self._sigoffset = np.zeros(self.number) * units.Mpc
        else:
            self._sigoffset = utils.check_units_and_type(offsets, units.Mpc,
                                                         num=self.number)

        self.rbins = utils.check_units_and_type(rbins, units.Mpc)

        rhoc = self._rho_crit.to(units.Msun / units.pc**2 / units.Mpc)
        smd = SurfaceMassDensity(self.rs, self.delta_c, rhoc,
                                 offsets=self._sigoffset,
                                 rbins=self.rbins,
                                 numTh=numTh,
                                 numRoff=numRoff,
                                 numRinner=numRinner,
                                 factorRouter=factorRouter)

        self.sigma_nfw = smd.sigma_nfw()
        self.deltasigma_nfw = smd.deltasigma_nfw()
Ejemplo n.º 11
0
    def calc_nfw(self,
                 rbins,
                 offsets=None,
                 numTh=200,
                 numRoff=200,
                 numRinner=20,
                 factorRouter=3):
        """Calculates Sigma and DeltaSigma profiles.

        Generates the surface mass density (sigma_nfw attribute of parent
        object) and differential surface mass density (deltasigma_nfw
        attribute of parent object) profiles of each cluster, assuming a
        spherical NFW model. Optionally includes the effect of cluster
        miscentering offsets.

        Parameters
        ----------
        rbins : array_like
            Radial bins (in Mpc) for calculating cluster profiles. Should
            be 1D, optionally with astropy.units of Mpc.
        offsets : array_like, optional
            Parameter describing the width (in Mpc) of the Gaussian
            distribution of miscentering offsets. Should be 1D, optionally
            with astropy.units of Mpc.

        Other Parameters
        -------------------
        numTh : int, optional
            Parameter to pass to SurfaceMassDensity(). Number of bins to
            use for integration over theta, for calculating offset profiles
            (no effect for offsets=None). Default 200.
        numRoff : int, optional
            Parameter to pass to SurfaceMassDensity(). Number of bins to
            use for integration over R_off, for calculating offset profiles
            (no effect for offsets=None). Default 200.
        numRinner : int, optional
            Parameter to pass to SurfaceMassDensity(). Number of bins at
            r < min(rbins) to use for integration over Sigma(<r), for
            calculating DeltaSigma (no effect for Sigma ever, and no effect
            for DeltaSigma if offsets=None). Default 20.
        factorRouter : int, optional
            Parameter to pass to SurfaceMassDensity(). Factor increase over
            number of rbins, at min(r) < r < max(r), of bins that will be
            used at for integration over Sigma(<r), for calculating
            DeltaSigma (no effect for Sigma, and no effect for DeltaSigma
            if offsets=None). Default 3.
        """
        if offsets is None:
            self._sigoffset = np.zeros(self.number) * units.Mpc
        else:
            self._sigoffset = utils.check_units_and_type(offsets,
                                                         units.Mpc,
                                                         num=self.number)

        self.rbins = utils.check_units_and_type(rbins, units.Mpc)

        rhoc = self._rho_crit.to(units.Msun / units.pc**2 / units.Mpc)
        smd = SurfaceMassDensity(self.rs,
                                 self.delta_c,
                                 rhoc,
                                 offsets=self._sigoffset,
                                 rbins=self.rbins,
                                 numTh=numTh,
                                 numRoff=numRoff,
                                 numRinner=numRinner,
                                 factorRouter=factorRouter)

        self.sigma_nfw = smd.sigma_nfw()
        self.deltasigma_nfw = smd.deltasigma_nfw()