コード例 #1
0
ファイル: test_zred.py プロジェクト: erykoff/redmapper
    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
ファイル: test_zred.py プロジェクト: erykoff/redmapper
    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))
コード例 #4
0
    def test_generatezredbkg(self):
        """
        Test generation of a zred background file.
        """

        config_file = os.path.join('data_for_tests', 'testconfig.yaml')

        config = Configuration(config_file)

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

        config.bkgfile = os.path.join(config.outpath,
                                      '%s_testbkg.fit' % (config.d.outbase))
        config.zrange = [0.1, 0.2]

        # First test without a zred file ...
        gen = ZredBackgroundGenerator(config)
        self.assertRaises(RuntimeError, gen.run)

        # And now fix it ...
        config.zredfile = os.path.join('data_for_tests', 'zreds_test',
                                       'dr8_test_zreds_master_table.fit')

        gen = ZredBackgroundGenerator(config)
        gen.run(clobber=True)

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

        zbkg = fitsio.read(config.bkgfile, ext='ZREDBKG')

        # Some spot-testing...
        # (The numbers have been checked to be consistent with the full run tested above
        #  but can't be directly compared because this is much noisier)
        testing.assert_equal(zbkg[0]['sigma_g'].shape, (48, 10))
        testing.assert_almost_equal(zbkg[0]['sigma_g'][30, 5],
                                    620.0223999,
                                    decimal=5)
        testing.assert_almost_equal(zbkg[0]['sigma_g'][47, 8],
                                    30501.8398438,
                                    decimal=5)
        testing.assert_almost_equal(zbkg[0]['sigma_g'][30, 0],
                                    384.3362732,
                                    decimal=5)
コード例 #5
0
ファイル: test_background.py プロジェクト: erykoff/redmapper
    def test_generatezredbkg(self):
        """
        Test generation of a zred background file.
        """

        config_file = os.path.join('data_for_tests', 'testconfig.yaml')

        config = Configuration(config_file)

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

        config.bkgfile = os.path.join(config.outpath, '%s_testbkg.fit' % (config.d.outbase))
        config.zrange = [0.1, 0.2]

        # First test without a zred file ...
        gen = ZredBackgroundGenerator(config)
        self.assertRaises(RuntimeError, gen.run)

        # And now fix it ...
        config.zredfile = os.path.join('data_for_tests', 'zreds_test', 'dr8_test_zreds_master_table.fit')

        gen = ZredBackgroundGenerator(config)
        gen.run(clobber=True)


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

        zbkg = fitsio.read(config.bkgfile, ext='ZREDBKG')

        # Some spot-testing...
        # (The numbers have been checked to be consistent with the full run tested above
        #  but can't be directly compared because this is much noisier)
        testing.assert_equal(zbkg[0]['sigma_g'].shape, (48, 10))
        testing.assert_almost_equal(zbkg[0]['sigma_g'][30, 5], 620.0223999, decimal=5)
        testing.assert_almost_equal(zbkg[0]['sigma_g'][47, 8], 30501.8398438, decimal=5)
        testing.assert_almost_equal(zbkg[0]['sigma_g'][30, 0], 384.3362732, decimal=5)
コード例 #6
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))
コード例 #7
0
    def test_redmapper_run(self):
        """
        Run test of redmapper.RedmapperRun.
        """

        random.seed(seed=12345)

        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

        # First, test the splitting
        config.calib_run_nproc = 4

        redmapper_run = RedmapperRun(config)

        splits = redmapper_run._get_pixel_splits()

        self.assertEqual(splits[0], 64)
        testing.assert_array_equal(splits[1],
                                   np.array([2163, 2296, 2297, 2434]))

        # Now, this will just run on 1 but will test consolidation code
        config.calib_run_nproc = 2
        # Note you need these to be set to get same answer with nproc = 1 because
        # of mask rounding
        # config.d.hpix = 570
        # config.d.nside = 32
        config.seedfile = os.path.join(file_path, 'test_dr8_specseeds.fit')
        config.zredfile = os.path.join(file_path, 'zreds_test',
                                       'dr8_test_zreds_master_table.fit')

        redmapper_run = RedmapperRun(config)
        redmapper_run.run(specmode=True,
                          consolidate_like=True,
                          keepz=True,
                          seedfile=config.seedfile)

        # Now let's check that we got the final file...
        self.assertTrue(
            os.path.isfile(
                os.path.join(config.outpath,
                             '%s_final.fit' % (config.d.outbase))))
        self.assertTrue(
            os.path.isfile(
                os.path.join(config.outpath,
                             '%s_final_members.fit' % (config.d.outbase))))
        self.assertTrue(
            os.path.isfile(
                os.path.join(config.outpath,
                             '%s_like.fit' % (config.d.outbase))))

        cat = Catalog.from_fits_file(
            os.path.join(config.outpath, '%s_final.fit' % (config.d.outbase)))

        # Spot checks to look for regressions
        testing.assert_equal(cat.size, 24)
        self.assertGreater(cat.Lambda.min(), 3.0)
        testing.assert_array_almost_equal(
            cat.Lambda[0:3], np.array([24.396917, 17.944063, 7.738485]))

        # And check that the members are all accounted for...
        mem = Catalog.from_fits_file(
            os.path.join(config.outpath,
                         '%s_final_members.fit' % (config.d.outbase)))
        a, b = esutil.numpy_util.match(cat.mem_match_id, mem.mem_match_id)
        testing.assert_equal(a.size, mem.size)