Пример #1
0
    def test_zred_runpixels(self):
        """
        Test redmapper.ZredRunPixels, computing zreds for all the galaxies
        in a pixelized galaxy catalog.
        """

        file_path = 'data_for_tests'
        configfile = 'testconfig.yaml'

        config = Configuration(os.path.join(file_path, configfile))

        config.d.hpix = 2163
        config.d.nside = 64
        config.border = 0.0

        self.test_dir = tempfile.mkdtemp(dir='./', prefix='TestRedmapper-')
        config.zredfile = os.path.join(self.test_dir, 'zreds', 'testing_zreds_master_table.fit')

        # FIXME: try an illegal one...

        zredRunpix = ZredRunPixels(config)
        zredRunpix.run()

        # Check that the zred file has been built...

        self.assertTrue(os.path.isfile(config.zredfile))

        # Read in just the galaxies...
        gals0 = GalaxyCatalog.from_galfile(config.galfile, nside=config.d.nside, hpix=config.d.hpix, border=config.border)

        # And with the zreds...
        gals = GalaxyCatalog.from_galfile(config.galfile, zredfile=config.zredfile, nside=config.d.nside, hpix=config.d.hpix, border=config.border)

        # Confirm they're the same galaxies...
        testing.assert_array_almost_equal(gals0.ra, gals.ra)

        # Confirm the zreds are okay
        self.assertGreater(np.min(gals.zred), 0.0)
        self.assertGreater(np.min(gals.chisq), 0.0)
        self.assertLess(np.max(gals.lkhd), 0.0)

        zredfile = os.path.join(file_path, 'zreds_test', 'dr8_test_zreds_master_table.fit')
        gals_compare = GalaxyCatalog.from_galfile(config.galfile, zredfile=zredfile,
                                                  nside=config.d.nside, hpix=config.d.hpix, border=config.border)

        zredstr = RedSequenceColorPar(config.parfile)
        mstar_input = zredstr.mstar(gals_compare.zred_uncorr)
        mstar = zredstr.mstar(gals_compare.zred_uncorr)

        ok, = np.where((gals_compare.refmag < (mstar_input - 2.5*np.log10(0.15))) |
                       (gals_compare.refmag < (mstar - 2.5*np.log10(0.15))))

        delta_zred_uncorr = gals.zred_uncorr[ok] - gals_compare.zred_uncorr[ok]

        use, = np.where(np.abs(delta_zred_uncorr) < 1e-3)
        testing.assert_array_less(0.98, float(use.size) / float(ok.size))
Пример #2
0
    def test_zred_runcat(self):
        """
        Test redmapper.ZredRunCatalog, computing zreds for all the galaxies in
        a single catalog file.
        """

        file_path = 'data_for_tests'
        configfile = 'testconfig.yaml'

        config = Configuration(os.path.join(file_path, configfile))

        self.test_dir = tempfile.mkdtemp(dir='./', prefix='TestRedmapper-')
        config.outpath = self.test_dir
        outfile = os.path.join(self.test_dir, 'test_zred_out.fits')

        tab = fitsio.read(config.galfile, ext=1, lower=True)
        galfile = os.path.join(os.path.dirname(config.galfile),
                               tab[0]['filenames'][0].decode())

        zredRuncat = ZredRunCatalog(config)

        zredRuncat.run(galfile, outfile)

        # This exercises the reading code
        gals = GalaxyCatalog.from_galfile(galfile, zredfile=outfile)

        self.assertGreater(np.min(gals.zred), 0.0)
        self.assertGreater(np.min(gals.chisq), 0.0)
        self.assertLess(np.max(gals.lkhd), 0.0)

        # And compare to the "official" run...
        config.zredfile = os.path.join(file_path, 'zreds_test',
                                       'dr8_test_zreds_master_table.fit')
        ztab = fitsio.read(config.zredfile, ext=1, lower=True)
        zredfile = os.path.join(os.path.dirname(config.zredfile),
                                ztab[0]['filenames'][0].decode())

        gals_compare = GalaxyCatalog.from_galfile(galfile, zredfile=zredfile)

        zredstr = RedSequenceColorPar(config.parfile)
        mstar_input = zredstr.mstar(gals_compare.zred_uncorr)
        mstar = zredstr.mstar(gals_compare.zred_uncorr)

        ok, = np.where(
            (gals_compare.refmag < (mstar_input - 2.5 * np.log10(0.15)))
            | (gals_compare.refmag < (mstar - 2.5 * np.log10(0.15))))

        delta_zred_uncorr = gals.zred_uncorr[ok] - gals_compare.zred_uncorr[ok]

        use, = np.where(np.abs(delta_zred_uncorr) < 1e-3)
        testing.assert_array_less(0.98, float(use.size) / float(ok.size))
Пример #3
0
    def test_galaxycatalog_read(self):
        """
        Run redmapper.GalaxyCatalog tests,
        """

        file_path = 'data_for_tests'

        galfile = 'pixelized_dr8_test/dr8_test_galaxies_master_table.fit'

        gals_all = GalaxyCatalog.from_galfile(file_path + '/' + galfile)

        # check that we got the expected number...
        testing.assert_equal(gals_all.size, 14449)

        # read in a subregion, no border
        gals_sub = GalaxyCatalog.from_galfile(file_path + '/' + galfile,
                                              hpix=2163, nside=64)

        theta = (90.0 - gals_all.dec) * np.pi/180.
        phi = gals_all.ra * np.pi/180.
        ipring_all = hp.ang2pix(64, theta, phi)
        use, = np.where(ipring_all == 2163)

        testing.assert_equal(gals_sub.size, use.size)

        # read in a subregion, with border
        gals_sub = GalaxyCatalog.from_galfile(file_path + '/' + galfile,
                                              hpix=9218, nside=128, border=0.1)

        # this isn't really a big enough sample catalog to fully test...
        testing.assert_equal(gals_sub.size, 2511)

        # and test the matching...

        indices, dists = gals_all.match_one(140.5, 65.0, 0.2)
        testing.assert_equal(indices.size, 521)
        testing.assert_array_less(dists, 0.2)

        i0, i1, dists = gals_all.match_many([140.5,141.2],
                                            [65.0, 65.2], [0.2,0.1])
        testing.assert_equal(i0.size, 666)
        test, = np.where(i0 == 0)
        testing.assert_equal(test.size, 521)
        testing.assert_array_less(dists[test], 0.2)
        test, = np.where(i0 == 1)
        testing.assert_equal(test.size, 666 - 521)
        testing.assert_array_less(dists[test], 0.1)
Пример #4
0
    def test_zred_runcat(self):
        """
        Test redmapper.ZredRunCatalog, computing zreds for all the galaxies in
        a single catalog file.
        """

        file_path = 'data_for_tests'
        configfile = 'testconfig.yaml'

        config = Configuration(os.path.join(file_path, configfile))

        self.test_dir = tempfile.mkdtemp(dir='./', prefix='TestRedmapper-')
        config.outpath = self.test_dir
        outfile = os.path.join(self.test_dir, 'test_zred_out.fits')

        tab = fitsio.read(config.galfile, ext=1, lower=True)
        galfile = os.path.join(os.path.dirname(config.galfile), tab[0]['filenames'][0].decode())

        zredRuncat = ZredRunCatalog(config)

        zredRuncat.run(galfile, outfile)

        # This exercises the reading code
        gals = GalaxyCatalog.from_galfile(galfile, zredfile=outfile)

        self.assertGreater(np.min(gals.zred), 0.0)
        self.assertGreater(np.min(gals.chisq), 0.0)
        self.assertLess(np.max(gals.lkhd), 0.0)

        # And compare to the "official" run...
        config.zredfile = os.path.join(file_path, 'zreds_test', 'dr8_test_zreds_master_table.fit')
        ztab = fitsio.read(config.zredfile, ext=1, lower=True)
        zredfile = os.path.join(os.path.dirname(config.zredfile), ztab[0]['filenames'][0].decode())

        gals_compare = GalaxyCatalog.from_galfile(galfile, zredfile=zredfile)

        zredstr = RedSequenceColorPar(config.parfile)
        mstar_input = zredstr.mstar(gals_compare.zred_uncorr)
        mstar = zredstr.mstar(gals_compare.zred_uncorr)

        ok, = np.where((gals_compare.refmag < (mstar_input - 2.5*np.log10(0.15))) |
                       (gals_compare.refmag < (mstar - 2.5*np.log10(0.15))))

        delta_zred_uncorr = gals.zred_uncorr[ok] - gals_compare.zred_uncorr[ok]

        use, = np.where(np.abs(delta_zred_uncorr) < 1e-3)
        testing.assert_array_less(0.98, float(use.size) / float(ok.size))
Пример #5
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())
Пример #6
0
    def runTest(self):
        """
        Run the ClusterFit test.
        """
        random.seed(seed=12345)

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

        gals = GalaxyCatalog.from_galfile(config.galfile)

        # temporary hack...
        dist = esutil.coords.sphdist(142.12752, 65.103898, gals.ra, gals.dec)
        mpc_scale = np.radians(1.) * config.cosmo.Da(0, 0.227865)
        r = np.clip(mpc_scale * dist, 1e-6, None)
        use, = np.where(r < 0.75)

        st = np.argsort(r[use])

        cbkg = ColorBackground(config.bkgfile_color, usehdrarea=True)
        zredstr = RedSequenceColorPar(None, config=config)

        cluster = Cluster(r0=0.5,
                          beta=0.0,
                          config=config,
                          cbkg=cbkg,
                          neighbors=gals[use[st]],
                          zredstr=zredstr)
        cluster.ra = 142.12752
        cluster.dec = 65.103898
        cluster.redshift = 0.227865
        cluster.update_neighbors_dist()

        mask = HPMask(cluster.config)
        maskgal_index = mask.select_maskgals_sample(maskgal_index=0)
        depthstr = DepthMap(cluster.config)
        mask.set_radmask(cluster)
        depthstr.calc_maskdepth(mask.maskgals, cluster.ra, cluster.dec,
                                cluster.mpc_scale)

        lam = cluster.calc_richness_fit(mask,
                                        1,
                                        centcolor_in=1.36503,
                                        calc_err=False)
        testing.assert_almost_equal(lam, 16.174486160, decimal=5)
        testing.assert_almost_equal(cluster.neighbors.pcol[0:4],
                                    np.array([0.94243, 0., 0.06338, 0.16077]),
                                    5)

        lam = cluster.calc_richness_fit(mask, 1, calc_err=False)
        testing.assert_almost_equal(lam, 16.2049961, decimal=5)
Пример #7
0
    def runTest(self):
        """
        Run the ClusterFit test.
        """
        random.seed(seed=12345)

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

        gals = GalaxyCatalog.from_galfile(config.galfile)

        # temporary hack...
        dist = esutil.coords.sphdist(142.12752, 65.103898, gals.ra, gals.dec)
        mpc_scale = np.radians(1.) * config.cosmo.Da(0, 0.227865)
        r = np.clip(mpc_scale * dist, 1e-6, None)
        use, = np.where(r < 0.75)

        st = np.argsort(r[use])

        cbkg = ColorBackground(config.bkgfile_color, usehdrarea=True)
        zredstr = RedSequenceColorPar(None, config=config)

        cluster = Cluster(r0=0.5, beta=0.0, config=config, cbkg=cbkg, neighbors=gals[use[st]], zredstr=zredstr)
        cluster.ra = 142.12752
        cluster.dec = 65.103898
        cluster.redshift = 0.227865
        cluster.update_neighbors_dist()

        mask = HPMask(cluster.config)
        maskgal_index = mask.select_maskgals_sample(maskgal_index=0)
        depthstr = DepthMap(cluster.config)
        mask.set_radmask(cluster)
        depthstr.calc_maskdepth(mask.maskgals, cluster.ra, cluster.dec, cluster.mpc_scale)

        lam = cluster.calc_richness_fit(mask, 1, centcolor_in=1.36503, calc_err=False)
        testing.assert_almost_equal(lam, 16.174486160, decimal=5)
        testing.assert_almost_equal(cluster.neighbors.pcol[0:4], np.array([0.94243, 0., 0.06338, 0.16077]), 5)

        lam = cluster.calc_richness_fit(mask, 1, calc_err=False)
        testing.assert_almost_equal(lam, 16.2049961, decimal=5)
Пример #8
0
    def test_galaxycatalog_create(self):
        """
        Run `redmapper.GalaxyCatalogMaker` tests.
        """

        # Make a test directory
        self.test_dir = tempfile.mkdtemp(dir='./', prefix='TestRedmapper-')

        info_dict = {'LIM_REF': 21.0,
                     'REF_IND': 3,
                     'AREA': 25.0,
                     'NMAG': 5,
                     'MODE': 'SDSS',
                     'ZP': 22.5,
                     'U_IND': 0,
                     'G_IND': 1,
                     'R_IND': 2,
                     'I_IND': 3,
                     'Z_IND': 3}

        # Test 1: read in catalog, write it to a single file, and then
        # try to split it up
        # make sure that it makes it properly, and that the output number
        # of files is the same as input number of files.

        configfile = os.path.join('data_for_tests', 'testconfig.yaml')
        config = Configuration(configfile)
        gals = GalaxyCatalog.from_galfile(config.galfile)
        tab = Entry.from_fits_file(config.galfile)

        maker = GalaxyCatalogMaker(os.path.join(self.test_dir, 'test_working'), info_dict, nside=tab.nside)
        maker.append_galaxies(gals._ndarray)
        maker.finalize_catalog()

        tab2 = Entry.from_fits_file(os.path.join(self.test_dir, 'test_working_master_table.fit'))
        self.assertEqual(tab.nside, tab2.nside)
        self.assertEqual(tab.filenames.size, tab2.filenames.size)

        for filename in tab2.filenames:
            self.assertTrue(os.path.isfile(os.path.join(self.test_dir, filename.decode())))

        # Test 2: Make a catalog that has an incomplete dtype
        dtype = [('id', 'i8'),
                 ('ra', 'f8')]
        maker = GalaxyCatalogMaker(os.path.join(self.test_dir, 'test'), info_dict)
        testgals = np.zeros(10, dtype=dtype)
        self.assertRaises(RuntimeError, maker.append_galaxies, testgals)

        # Test 3: make a catalog that has the wrong number of magnitudes
        dtype = GalaxyCatalogMaker.get_galaxy_dtype(3)
        testgals = np.zeros(10, dtype=dtype)
        self.assertRaises(RuntimeError, maker.append_galaxies, testgals)

        # Test 4: make a catalog that has some NaNs
        dtype = GalaxyCatalogMaker.get_galaxy_dtype(info_dict['NMAG'])
        testgals = np.ones(10, dtype=dtype)
        testgals['mag'][0, 1] = np.nan
        self.assertRaises(RuntimeError, maker.append_galaxies, testgals)

        # Test 5: make a catalog that has ra/dec out of range
        testgals = np.ones(10, dtype=dtype)
        testgals['ra'][1] = -1.0
        self.assertRaises(RuntimeError, maker.append_galaxies, testgals)

        testgals = np.ones(10, dtype=dtype)
        testgals['dec'][1] = -100.0
        self.assertRaises(RuntimeError, maker.append_galaxies, testgals)

        # Test 6: make a catalog that has mag > 90.0
        testgals = np.ones(10, dtype=dtype)
        testgals['mag'][0, 1] = 100.0
        self.assertRaises(RuntimeError, maker.append_galaxies, testgals)

        # Test 7: make a catalog that has mag_err == 0.0
        testgals = np.ones(10, dtype=dtype)
        testgals['mag_err'][0, 1] = 0.0
        self.assertRaises(RuntimeError, maker.append_galaxies, testgals)
Пример #9
0
    def runTest(self):

        file_path = 'data_for_tests'
        conffile = 'testconfig.yaml'

        config = Configuration(file_path + '/' + conffile)

        gals_all = GalaxyCatalog.from_galfile(config.galfile)

        zred_filename = 'test_dr8_pars.fit'
        zredstr = RedSequenceColorPar(file_path + '/' + zred_filename, fine=True)

        bkg_filename = 'test_bkg.fit'
        bkg = Background('%s/%s' % (file_path, bkg_filename))

        mask = HPMask(config)
        depthstr = DepthMap(config)

        #cosmo = Cosmo()


        testcatfile = 'test_cluster_pos.fit'
        cat = ClusterCatalog.from_catfile(file_path + '/' + testcatfile,
                                          zredstr=zredstr,
                                          config=config,
                                          bkg=bkg)

        # test single neighbors...
        c0 = cat[0]
        c0.find_neighbors(0.2, gals_all)
        c1 = cat[1]
        c1.find_neighbors(0.2, gals_all)

        testing.assert_equal(c0.neighbors.size, 580)
        testing.assert_equal(c1.neighbors.size, 298)
        testing.assert_array_less(c0.neighbors.dist, 0.2)
        testing.assert_array_less(c1.neighbors.dist, 0.2)

        # and multi-match...
        i0, i1, dist = gals_all.match_many(cat.ra, cat.dec, 0.2)

        u0, = np.where(i0 == 0)
        testing.assert_equal(c0.neighbors.size, u0.size)

        u1, = np.where(i0 == 1)
        testing.assert_equal(c1.neighbors.size, u1.size)

        # and compute the richness on the first one...
        mask.set_radmask(c0)

        depthstr.calc_maskdepth(mask.maskgals, c0.ra, c0.dec, c0.mpc_scale)

        richness = c0.calc_richness(mask)

        # Make sure the numbers were propagated to the parent catalog
        testing.assert_equal(richness, cat.Lambda[0])
        testing.assert_equal(c0.Lambda_e, cat.Lambda_e[0])
        testing.assert_equal(c0.scaleval, cat.scaleval[0])

        # And make sure the numbers are correct
        testing.assert_almost_equal(richness, 23.86299324)
Пример #10
0
    def test_zred_runpixels(self):
        """
        Test redmapper.ZredRunPixels, computing zreds for all the galaxies
        in a pixelized galaxy catalog.
        """

        file_path = 'data_for_tests'
        configfile = 'testconfig.yaml'

        config = Configuration(os.path.join(file_path, configfile))

        config.d.hpix = 2163
        config.d.nside = 64
        config.border = 0.0

        self.test_dir = tempfile.mkdtemp(dir='./', prefix='TestRedmapper-')
        config.zredfile = os.path.join(self.test_dir, 'zreds',
                                       'testing_zreds_master_table.fit')

        # FIXME: try an illegal one...

        zredRunpix = ZredRunPixels(config)
        zredRunpix.run()

        # Check that the zred file has been built...

        self.assertTrue(os.path.isfile(config.zredfile))

        # Read in just the galaxies...
        gals0 = GalaxyCatalog.from_galfile(config.galfile,
                                           nside=config.d.nside,
                                           hpix=config.d.hpix,
                                           border=config.border)

        # And with the zreds...
        gals = GalaxyCatalog.from_galfile(config.galfile,
                                          zredfile=config.zredfile,
                                          nside=config.d.nside,
                                          hpix=config.d.hpix,
                                          border=config.border)

        # Confirm they're the same galaxies...
        testing.assert_array_almost_equal(gals0.ra, gals.ra)

        # Confirm the zreds are okay
        self.assertGreater(np.min(gals.zred), 0.0)
        self.assertGreater(np.min(gals.chisq), 0.0)
        self.assertLess(np.max(gals.lkhd), 0.0)

        zredfile = os.path.join(file_path, 'zreds_test',
                                'dr8_test_zreds_master_table.fit')
        gals_compare = GalaxyCatalog.from_galfile(config.galfile,
                                                  zredfile=zredfile,
                                                  nside=config.d.nside,
                                                  hpix=config.d.hpix,
                                                  border=config.border)

        zredstr = RedSequenceColorPar(config.parfile)
        mstar_input = zredstr.mstar(gals_compare.zred_uncorr)
        mstar = zredstr.mstar(gals_compare.zred_uncorr)

        ok, = np.where(
            (gals_compare.refmag < (mstar_input - 2.5 * np.log10(0.15)))
            | (gals_compare.refmag < (mstar - 2.5 * np.log10(0.15))))

        delta_zred_uncorr = gals.zred_uncorr[ok] - gals_compare.zred_uncorr[ok]

        use, = np.where(np.abs(delta_zred_uncorr) < 1e-3)
        testing.assert_array_less(0.98, float(use.size) / float(ok.size))
Пример #11
0
    def runTest(self):
        """
        Run the ClusterCatalog tests.
        """

        random.seed(seed=12345)

        file_path = 'data_for_tests'
        conffile = 'testconfig.yaml'

        config = Configuration(file_path + '/' + conffile)

        gals_all = GalaxyCatalog.from_galfile(config.galfile)

        zred_filename = 'test_dr8_pars.fit'
        zredstr = RedSequenceColorPar(file_path + '/' + zred_filename, fine=True)

        bkg_filename = 'test_bkg.fit'
        bkg = Background('%s/%s' % (file_path, bkg_filename))

        mask = HPMask(config)
        maskgal_index = mask.select_maskgals_sample(maskgal_index=0)
        depthstr = DepthMap(config)

        testcatfile = 'test_cluster_pos.fit'
        cat = ClusterCatalog.from_catfile(file_path + '/' + testcatfile,
                                          zredstr=zredstr,
                                          config=config,
                                          bkg=bkg)

        # test single neighbors...
        c0 = cat[0]
        c0.find_neighbors(0.2, gals_all)
        c1 = cat[1]
        c1.find_neighbors(0.2, gals_all)

        testing.assert_equal(c0.neighbors.size, 580)
        testing.assert_equal(c1.neighbors.size, 298)
        testing.assert_array_less(c0.neighbors.dist, 0.2)
        testing.assert_array_less(c1.neighbors.dist, 0.2)

        # and multi-match...
        i0, i1, dist = gals_all.match_many(cat.ra, cat.dec, 0.2)

        u0, = np.where(i0 == 0)
        testing.assert_equal(c0.neighbors.size, u0.size)

        u1, = np.where(i0 == 1)
        testing.assert_equal(c1.neighbors.size, u1.size)

        # and compute the richness on the first one...
        mask.set_radmask(c0)

        depthstr.calc_maskdepth(mask.maskgals, c0.ra, c0.dec, c0.mpc_scale)

        richness = c0.calc_richness(mask)

        # Make sure the numbers were propagated to the parent catalog
        testing.assert_equal(richness, cat.Lambda[0])
        testing.assert_equal(c0.Lambda_e, cat.Lambda_e[0])
        testing.assert_equal(c0.scaleval, cat.scaleval[0])

        # And make sure the numbers are correct
        testing.assert_almost_equal(richness, 24.4121723)