Ejemplo n.º 1
0
    def test_generatebkg(self):
        config_file = os.path.join('data_for_tests', 'testconfig.yaml')

        config = Configuration(config_file)

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

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

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

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

        bkg = fitsio.read(config.bkgfile, ext='CHISQBKG')

        # Some spot-testing...
        testing.assert_equal(bkg[0]['sigma_g'].shape, (48, 40, 5))
        testing.assert_equal(bkg[0]['sigma_lng'].shape, (48, 40, 5))
        testing.assert_almost_equal(bkg[0]['sigma_g'][30, 20, 2], 2.8444533)
        testing.assert_almost_equal(bkg[0]['sigma_g'][30, 10, 3], 7.4324579)
        testing.assert_almost_equal(bkg[0]['sigma_lng'][30, 10, 3], 3.7618985)
        testing.assert_almost_equal(bkg[0]['sigma_lng'][45, 10, 3], 0.0)

        if os.path.exists(test_dir):
            shutil.rmtree(test_dir, True)
Ejemplo n.º 2
0
    def test_generatebkg(self):
        """
        Test generation of a background file.
        """
        config_file = os.path.join('data_for_tests', 'testconfig.yaml')

        config = Configuration(config_file)
        config.calib_nproc = 1

        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]

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

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

        bkg = fitsio.read(config.bkgfile, ext='CHISQBKG')

        # Some spot-testing...
        testing.assert_equal(bkg[0]['sigma_g'].shape, (48, 40, 5))
        testing.assert_equal(bkg[0]['sigma_lng'].shape, (48, 40, 5))
        testing.assert_almost_equal(bkg[0]['sigma_g'][30, 20, 2], 2.8444533)
        testing.assert_almost_equal(bkg[0]['sigma_g'][30, 10, 3], 7.4324579)
        testing.assert_almost_equal(bkg[0]['sigma_lng'][30, 10, 3], 3.7618985)
        testing.assert_almost_equal(bkg[0]['sigma_lng'][45, 10, 3], 0.0)
Ejemplo n.º 3
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)
Ejemplo n.º 4
0
    def test_run_colormem(self):
        """
        Run tests of redmapper.RunColormem
        """

        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, we need the red galaxy model

        config.specfile_train = os.path.join(file_path, 'test_dr8_spec.fit')
        config.zrange = [0.1, 0.2]

        config.redgalfile = config.redmapper_filename('test_redgals')
        config.redgalmodelfile = config.redmapper_filename('test_redgalmodel')

        selred = SelectSpecRedGalaxies(config)
        selred.run()

        # Main test...
        config.zmemfile = config.redmapper_filename('test_zmem')

        rcm = RunColormem(config)
        rcm.run()
        rcm.output_training()

        # Check that the files are there...
        self.assertTrue(os.path.isfile(config.zmemfile))

        mem = fitsio.read(config.zmemfile, ext=1)

        testing.assert_equal(mem.size, 16)
        testing.assert_array_almost_equal(
            mem['pcol'][0:3], np.array([0.94829756, 0.83803916, 0.88315928]))
        testing.assert_array_almost_equal(
            mem['z'][0:3], np.array([0.191279, 0.188257, 0.186945]))
Ejemplo n.º 5
0
    def test_run_colormem(self):
        """
        Run tests of redmapper.RunColormem
        """

        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, we need the red galaxy model

        config.specfile_train = os.path.join(file_path, 'test_dr8_spec.fit')
        config.zrange = [0.1,0.2]

        config.redgalfile = config.redmapper_filename('test_redgals')
        config.redgalmodelfile = config.redmapper_filename('test_redgalmodel')

        selred = SelectSpecRedGalaxies(config)
        selred.run()

        # Main test...
        config.zmemfile = config.redmapper_filename('test_zmem')

        rcm = RunColormem(config)
        rcm.run()
        rcm.output_training()

        # Check that the files are there...
        self.assertTrue(os.path.isfile(config.zmemfile))

        mem = fitsio.read(config.zmemfile, ext=1)

        testing.assert_equal(mem.size, 16)
        testing.assert_array_almost_equal(mem['pcol'][0:3], np.array([0.94829756, 0.83803916, 0.88315928]))
        testing.assert_array_almost_equal(mem['z'][0:3], np.array([0.191279, 0.188257, 0.186945]))
Ejemplo n.º 6
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)