Ejemplo n.º 1
0
    def test_readmask(self):
        """
        Test reading and using of mask files in redmapper.HPMask
        """

        file_path = "data_for_tests"
        conf_filename = "testconfig.yaml"
        config = Configuration(file_path + "/" + conf_filename)

        # First, test a bare mask

        config.mask_mode = 0
        mask = get_mask(config)
        maskgal_index = mask.select_maskgals_sample()
        testing.assert_equal(hasattr(mask, 'maskgals'), True)
        testing.assert_equal(isinstance(mask, Mask), True)
        testing.assert_equal(isinstance(mask, HPMask), False)

        # And the healpix mask

        config.mask_mode = 3
        mask = get_mask(config)
        maskgal_index = mask.select_maskgals_sample()
        testing.assert_equal(hasattr(mask, 'maskgals'), True)
        testing.assert_equal(isinstance(mask, Mask), True)
        testing.assert_equal(isinstance(mask, HPMask), True)

        # When ready, add in test of gen_maskgals()

        # Test the healpix configuration
        testing.assert_equal(mask.nside, 2048)

        # Next test the compute_radmask() function
        # Note: RA and DECs are in degrees here

        RAs = np.array([140.00434405, 142.04090, 142.09242, 142.11448, 50.0])
        Decs = np.array([63.47175301, 65.133844, 65.084844, 65.109541, 50.0])

        comp = np.array([True, True, True, True, False])

        testing.assert_equal(mask.compute_radmask(RAs, Decs), comp)

        # And test that we're getting the right numbers from a sub-mask
        config2 = Configuration(file_path + "/" + conf_filename)
        config2.d.hpix = 582972
        config2.d.nside = 1024
        config2.border = 0.02
        mask2 = get_mask(config2)
        maskgal_index = mask2.select_maskgals_sample()

        comp = np.array([False, True, True, True, False])
        testing.assert_equal(mask2.compute_radmask(RAs, Decs), comp)
Ejemplo n.º 2
0
    def test_readmask(self):
        """
        Test reading and using of mask files in redmapper.HPMask
        """

        file_path = "data_for_tests"
        conf_filename = "testconfig.yaml"
        config = Configuration(file_path + "/" + conf_filename)

        # First, test a bare mask

        config.mask_mode = 0
        mask = get_mask(config)
        maskgal_index = mask.select_maskgals_sample()
        testing.assert_equal(hasattr(mask, 'maskgals'), True)
        testing.assert_equal(isinstance(mask, Mask), True)
        testing.assert_equal(isinstance(mask, HPMask), False)

        # And the healpix mask

        config.mask_mode = 3
        mask = get_mask(config)
        maskgal_index = mask.select_maskgals_sample()
        testing.assert_equal(hasattr(mask, 'maskgals'), True)
        testing.assert_equal(isinstance(mask, Mask), True)
        testing.assert_equal(isinstance(mask, HPMask), True)

        # When ready, add in test of gen_maskgals()

        # Test the healpix configuration
        testing.assert_equal(mask.nside,2048)

        # Next test the compute_radmask() function
        # Note: RA and DECs are in degrees here

        RAs = np.array([140.00434405, 142.04090, 142.09242, 142.11448, 50.0])
        Decs = np.array([63.47175301, 65.133844, 65.084844, 65.109541, 50.0])

        comp = np.array([True, True, True, True, False])

        testing.assert_equal(mask.compute_radmask(RAs, Decs), comp)

        # And test that we're getting the right numbers from a sub-mask
        config2 = Configuration(file_path + "/" + conf_filename)
        config2.d.hpix = 582972
        config2.d.nside = 1024
        config2.border = 0.02
        mask2 = get_mask(config2)
        maskgal_index = mask2.select_maskgals_sample()

        comp = np.array([False, True, True, True, False])
        testing.assert_equal(mask2.compute_radmask(RAs, Decs), comp)
Ejemplo n.º 3
0
    def test_maskgals(self):
        """
        Test generation of maskgals file.
        """

        # Note that due to historical reasons, this is testing the
        # new generation of maskgals with some spot checks.  Independently,
        # it has been checked that the distributions are the same as for
        # the old IDL code which was used to generate the reference used
        # in the cluster tests.

        file_path = "data_for_tests"
        conf_filename = "testconfig.yaml"
        config = Configuration(os.path.join(file_path, conf_filename))
        # For testing, and backwards compatibility, only make one
        config.maskgal_nsamples = 1

        config.mask_mode = 0
        mask = get_mask(config)

        self.test_dir = tempfile.mkdtemp(dir='./', prefix='TestRedmapper-')
        config.outpath = self.test_dir

        maskgalfile = os.path.join(self.test_dir, 'testmaskgal.fit')

        random.seed(seed=12345)

        # This will generate the file if it isn't there
        mask.read_maskgals(maskgalfile)

        maskgals, hdr = fitsio.read(maskgalfile, ext=1, header=True)

        self.assertEqual(maskgals.size, config.maskgal_ngals * config.maskgal_nsamples)
        self.assertEqual(hdr['VERSION'], 6)
        self.assertEqual(hdr['R0'], config.percolation_r0)
        self.assertEqual(hdr['BETA'], config.percolation_beta)
        self.assertEqual(hdr['STEPSIZE'], config.maskgal_rad_stepsize)
        self.assertEqual(hdr['NMAG'], config.nmag)
        self.assertEqual(hdr['NGALS'], config.maskgal_ngals)
        self.assertEqual(hdr['CHISQMAX'], config.chisq_max)
        self.assertEqual(hdr['LVALREF'], config.lval_reference)
        self.assertEqual(hdr['EXTRA'], config.maskgal_dmag_extra)
        self.assertEqual(hdr['ALPHA'], config.calib_lumfunc_alpha)
        self.assertEqual(hdr['RSIG'], config.rsig)
        self.assertEqual(hdr['ZREDERR'], config.maskgal_zred_err)

        testing.assert_almost_equal(maskgals['r'][0: 3], [0.66900003, 0.119, 0.722])
        testing.assert_almost_equal(maskgals['phi'][0: 3], [1.73098969, 2.53610063, 4.2362957])
        testing.assert_almost_equal(maskgals['x'][0: 3], [-0.1067116, -0.09784444, -0.33090013])
        testing.assert_almost_equal(maskgals['m'][0: 3], [0.46200001, 1.778, -1.43599999])
        testing.assert_almost_equal(maskgals['chisq'][0: 3], [8.63599968, 2.28399992, 1.55799997])
        testing.assert_almost_equal(maskgals['cwt'][0: 3], [0.02877194, 0.1822518, 0.17872778])
        testing.assert_almost_equal(maskgals['nfw'][0: 3], [0.15366785, 0.32543495, 0.1454625])
        testing.assert_almost_equal(maskgals['dzred'][0: 3], [-0.03090504, 0.00847131, -0.01800639])
        testing.assert_almost_equal(maskgals['zwt'][0: 3], [6.0447073, 18.23568916, 13.30043507])
        testing.assert_almost_equal(maskgals['lumwt'][0: 3], [0.39371657, 0.62304342, 0.01774093])
        testing.assert_almost_equal(maskgals['theta_r'][0: 3, 3], [0.73237121, 1., 0.3299689])
        testing.assert_almost_equal(maskgals['radbins'][0, 0: 3], [0.40000001, 0.5, 0.60000002])
        testing.assert_almost_equal(maskgals['nin_orig'][0, 0: 3], [2213., 2663., 3066.])
        testing.assert_almost_equal(maskgals['nin'][0, 0: 3], [2203.3347168, 2651.54467773, 3062.44628906])
Ejemplo n.º 4
0
    def test_depthfit(self):
        """
        Test depth fitting with redmapper.DepthLim
        """

        file_path = "data_for_tests"
        conf_filename = "testconfig.yaml"
        config = Configuration(file_path + "/" + conf_filename)

        gals = GalaxyCatalog.from_galfile(config.galfile)

        np.random.seed(seed=12345)

        # First creation of depth object
        dlim = DepthLim(gals.refmag, gals.refmag_err)

        # This has been inspected that it makes sense.
        # Also, one should really be using a depth map

        testing.assert_almost_equal(dlim.initpars['EXPTIME'], 104.782066, 0)
        testing.assert_almost_equal(dlim.initpars['LIMMAG'], 20.64819717, 0)

        # And take a subpixel

        gals = GalaxyCatalog.from_galfile(config.galfile, hpix=8421, nside=128)

        config.mask_mode = 0
        mask = get_mask(config)
        maskgal_index = mask.select_maskgals_sample()
        mask.read_maskgals(config.maskgalfile)

        dlim.calc_maskdepth(mask.maskgals, gals.refmag, gals.refmag_err)

        pars, fail = calcErrorModel(gals.refmag, gals.refmag_err, calcErr=False)

        testing.assert_almost_equal(pars['EXPTIME'], 63.73879623, 0)
        testing.assert_almost_equal(pars['LIMMAG'], 20.68231583, 0)

        # And make sure the maskgals are getting the right constant value
        testing.assert_almost_equal(pars['EXPTIME'], mask.maskgals.exptime.min())
        testing.assert_almost_equal(pars['EXPTIME'], mask.maskgals.exptime.max())
        testing.assert_almost_equal(pars['LIMMAG'], mask.maskgals.limmag.min())
        testing.assert_almost_equal(pars['LIMMAG'], mask.maskgals.limmag.max())
Ejemplo n.º 5
0
    def runTest(self):
        """
        This tests the mask.py module. Since this
        module is still in developement, so too are
        these unit tests.

        First test the red_maskgals() and gen_maskgals() functions.
        Note: the gen_maskgals() function isn't written yet, so it
        can't be tested. TODO

        Next create a HPMask, check that it has maskgals and then
        test to see if nside, offset, and npix are 
        the values that we expect them to be. These are 
        variables that tell us about how healpix is formatted.

        Next test the fracgood array and its features, including
        the fracgood_float and various fracgood entries.

        Next test the compute_radmask() function which
        finds if an array of (RA,DEC) pairs are in or out
        of the mask. TODO

        """
        file_path = "data_for_tests"
        conf_filename = "testconfig.yaml"
        config = Configuration(file_path + "/" + conf_filename)

        # First, test a bare mask

        config.mask_mode = 0
        mask = get_mask(config)
        testing.assert_equal(hasattr(mask, 'maskgals'), True)
        testing.assert_equal(isinstance(mask, Mask), True)
        testing.assert_equal(isinstance(mask, HPMask), False)

        # And the healpix mask

        config.mask_mode = 3
        mask = get_mask(config)
        testing.assert_equal(hasattr(mask, 'maskgals'), True)
        testing.assert_equal(isinstance(mask, Mask), True)
        testing.assert_equal(isinstance(mask, HPMask), True)

        # When ready, add in test of gen_maskgals()

        # Test the healpix configuration
        testing.assert_equal(mask.nside, 2048)
        testing.assert_equal(mask.offset, 2100800)
        testing.assert_equal(mask.npix, 548292)

        # Next test that the fracgood is working properly
        indices = [396440, 445445, 99547, 354028, 516163]  #Random indices
        true_fracgoods = np.array([0, 0, 0.828125, 0.796875,
                                   0.828125])  #known fracgoods at indices
        testing.assert_equal(mask.fracgood_float, 1)
        testing.assert_equal(mask.fracgood.shape[0], 548292)
        testing.assert_equal(mask.fracgood[indices], true_fracgoods)

        # Next test the compute_radmask() function
        # Note: RA and DECs are in degrees here

        RAs = np.array([142.10934, 142.04090, 142.09242, 142.11448, 50.0])
        Decs = np.array([65.022666, 65.133844, 65.084844, 65.109541, 50.0])

        comp = np.array([True, True, True, True, False])

        testing.assert_equal(mask.compute_radmask(RAs, Decs), comp)

        # And test that we're getting the right numbers from a sub-mask
        config2 = Configuration(file_path + "/" + conf_filename)
        config2.hpix = 582972
        config2.nside = 1024
        config2.border = 0.02
        mask2 = get_mask(config2)

        comp = np.array([False, True, True, True, False])
        testing.assert_equal(mask2.compute_radmask(RAs, Decs), comp)
Ejemplo n.º 6
0
    def test_maskgals(self):
        """
        Test generation of maskgals file.
        """

        # Note that due to historical reasons, this is testing the
        # new generation of maskgals with some spot checks.  Independently,
        # it has been checked that the distributions are the same as for
        # the old IDL code which was used to generate the reference used
        # in the cluster tests.

        file_path = "data_for_tests"
        conf_filename = "testconfig.yaml"
        config = Configuration(os.path.join(file_path, conf_filename))
        # For testing, and backwards compatibility, only make one
        config.maskgal_nsamples = 1

        config.mask_mode = 0
        mask = get_mask(config)

        self.test_dir = tempfile.mkdtemp(dir='./', prefix='TestRedmapper-')
        config.outpath = self.test_dir

        maskgalfile = os.path.join(self.test_dir, 'testmaskgal.fit')

        random.seed(seed=12345)

        # This will generate the file if it isn't there
        mask.read_maskgals(maskgalfile)

        maskgals, hdr = fitsio.read(maskgalfile, ext=1, header=True)

        self.assertEqual(maskgals.size,
                         config.maskgal_ngals * config.maskgal_nsamples)
        self.assertEqual(hdr['VERSION'], 6)
        self.assertEqual(hdr['R0'], config.percolation_r0)
        self.assertEqual(hdr['BETA'], config.percolation_beta)
        self.assertEqual(hdr['STEPSIZE'], config.maskgal_rad_stepsize)
        self.assertEqual(hdr['NMAG'], config.nmag)
        self.assertEqual(hdr['NGALS'], config.maskgal_ngals)
        self.assertEqual(hdr['CHISQMAX'], config.chisq_max)
        self.assertEqual(hdr['LVALREF'], config.lval_reference)
        self.assertEqual(hdr['EXTRA'], config.maskgal_dmag_extra)
        self.assertEqual(hdr['ALPHA'], config.calib_lumfunc_alpha)
        self.assertEqual(hdr['RSIG'], config.rsig)
        self.assertEqual(hdr['ZREDERR'], config.maskgal_zred_err)

        testing.assert_almost_equal(maskgals['r'][0:3],
                                    [0.66900003, 0.119, 0.722])
        testing.assert_almost_equal(maskgals['phi'][0:3],
                                    [1.73098969, 2.53610063, 4.2362957])
        testing.assert_almost_equal(maskgals['x'][0:3],
                                    [-0.1067116, -0.09784444, -0.33090013])
        testing.assert_almost_equal(maskgals['m'][0:3],
                                    [0.46200001, 1.778, -1.43599999])
        testing.assert_almost_equal(maskgals['chisq'][0:3],
                                    [8.63599968, 2.28399992, 1.55799997])
        testing.assert_almost_equal(maskgals['cwt'][0:3],
                                    [0.02877194, 0.1822518, 0.17872778])
        testing.assert_almost_equal(maskgals['nfw'][0:3],
                                    [0.15366785, 0.32543495, 0.1454625])
        testing.assert_almost_equal(maskgals['dzred'][0:3],
                                    [-0.03090504, 0.00847131, -0.01800639])
        testing.assert_almost_equal(maskgals['zwt'][0:3],
                                    [6.0447073, 18.23568916, 13.30043507])
        testing.assert_almost_equal(maskgals['lumwt'][0:3],
                                    [0.39371657, 0.62304342, 0.01774093])
        testing.assert_almost_equal(maskgals['theta_r'][0:3, 3],
                                    [0.73237121, 1., 0.3299689])
        testing.assert_almost_equal(maskgals['radbins'][0, 0:3],
                                    [0.40000001, 0.5, 0.60000002])
        testing.assert_almost_equal(maskgals['nin_orig'][0, 0:3],
                                    [2213., 2663., 3066.])
        testing.assert_almost_equal(
            maskgals['nin'][0,
                            0:3], [2203.3347168, 2651.54467773, 3062.44628906])