def runTest(self): """ Run redmapper.DepthMap tests. """ file_path = "data_for_tests" conf_filename = "testconfig.yaml" config = Configuration(file_path + "/" + conf_filename) # Check the regular depth depthstr = DepthMap(config) 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_limmag = np.array( [20.810108, 20.59153, 20.59663, 20.59663, -1.63750e+30], dtype='f4') comp_exptime = np.array( [78.849754, 63.56208, 63.56208, 63.56209, -1.63750e+30], dtype='f4') comp_m50 = np.array( [20.967576, 20.85170, 20.85677, 20.85677, -1.63750e+30], dtype='f4') limmag, exptime, m50 = depthstr.get_depth_values(RAs, Decs) testing.assert_almost_equal(limmag, comp_limmag, 4) testing.assert_almost_equal(exptime, comp_exptime, 4) testing.assert_almost_equal(m50, comp_m50, 4) # And check the areas... mags = np.array([20.0, 20.2, 20.4, 20.6, 20.8, 21.0]) areas_idl = np.array( [3.29709, 3.29709, 3.29709, 3.29709, 2.86089, 0.0603447]) areas = depthstr.calc_areas(mags) testing.assert_almost_equal(areas, areas_idl, 4) config2 = Configuration(file_path + "/" + conf_filename) config2.d.hpix = 582972 config2.d.nside = 1024 config2.border = 0.02 depthstr2 = DepthMap(config2) limmag2, exptime2, m502 = depthstr2.get_depth_values(RAs, Decs) comp_limmag[0] = hp.UNSEEN comp_exptime[0] = hp.UNSEEN comp_m50[0] = hp.UNSEEN testing.assert_almost_equal(limmag2, comp_limmag, 4) testing.assert_almost_equal(exptime2, comp_exptime, 4) testing.assert_almost_equal(m502, comp_m50, 4) config3 = Configuration(file_path + "/" + conf_filename) config3.d.hpix = 8421 config3.d.nside = 128 config3.border = 0.0 depthstr3 = DepthMap(config3) areas3 = depthstr3.calc_areas(np.array([20.0, 20.5, 21.0])) testing.assert_almost_equal(areas3[0], 0.20457271, 6)
def runTest(self): """ Run redmapper.DepthMap tests. """ file_path = "data_for_tests" conf_filename = "testconfig.yaml" config = Configuration(file_path + "/" + conf_filename) # Check the regular depth depthstr = DepthMap(config) 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_limmag = np.array([20.810108, 20.59153, 20.59663, 20.59663, -1.63750e+30], dtype='f4') comp_exptime = np.array([78.849754, 63.56208, 63.56208, 63.56209, -1.63750e+30], dtype='f4') comp_m50 = np.array([20.967576, 20.85170, 20.85677, 20.85677, -1.63750e+30], dtype='f4') limmag, exptime, m50 = depthstr.get_depth_values(RAs, Decs) testing.assert_almost_equal(limmag, comp_limmag, 4) testing.assert_almost_equal(exptime, comp_exptime, 4) testing.assert_almost_equal(m50, comp_m50, 4) # And check the areas... mags = np.array([20.0, 20.2, 20.4, 20.6, 20.8, 21.0]) areas_idl = np.array([3.29709, 3.29709, 3.29709, 3.29709, 2.86089, 0.0603447]) areas = depthstr.calc_areas(mags) testing.assert_almost_equal(areas, areas_idl, 4) config2 = Configuration(file_path + "/" + conf_filename) config2.d.hpix = 582972 config2.d.nside = 1024 config2.border = 0.02 depthstr2 = DepthMap(config2) limmag2, exptime2, m502 = depthstr2.get_depth_values(RAs, Decs) comp_limmag[0] = hp.UNSEEN comp_exptime[0] = hp.UNSEEN comp_m50[0] = hp.UNSEEN testing.assert_almost_equal(limmag2, comp_limmag, 4) testing.assert_almost_equal(exptime2, comp_exptime, 4) testing.assert_almost_equal(m502, comp_m50, 4) config3 = Configuration(file_path + "/" + conf_filename) config3.d.hpix = 8421 config3.d.nside = 128 config3.border = 0.0 depthstr3 = DepthMap(config3) areas3 = depthstr3.calc_areas(np.array([20.0, 20.5, 21.0])) testing.assert_almost_equal(areas3[0], 0.20457271, 6)
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))
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)
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)
def runTest(self): """ Run the ColorBackground and ColorBackgroundGenerator tests. """ file_name = 'test_dr8_col_bkg.fit' file_path = 'data_for_tests' cbkg = ColorBackground('%s/%s' % (file_path, file_name)) col1 = np.array([0.572300, 1.39560]) col2 = np.array([0.7894, 0.9564]) refmags = np.array([17.587, 18.956]) refmagindex = np.array([258, 395]) col1index = np.array([1, 17]) col2index = np.array([15, 19]) idl_bkg1 = np.array([0.148366, 0.165678]) idl_bkg2 = np.array([0.00899471, 0.0201531]) idl_bkg12 = np.array([0.0111827, 0.0719981]) # Test color1 py_outputs = cbkg.lookup_diagonal(1, col1, refmags) testing.assert_almost_equal(py_outputs, idl_bkg1, decimal=5) # Test color2 py_outputs = cbkg.lookup_diagonal(2, col2, refmags) testing.assert_almost_equal(py_outputs, idl_bkg2, decimal=5) # Test off-diagonal py_outputs = cbkg.lookup_offdiag(1, 2, col1, col2, refmags) testing.assert_almost_equal(py_outputs, idl_bkg12, decimal=5) # And a test sigma_g with the usehdrarea=True cbkg2 = ColorBackground('%s/%s' % (file_path, file_name), usehdrarea=True) col1 = np.array([0.572300, 1.39560, 1.0]) col2 = np.array([0.7894, 0.9564, 1.0]) refmags = np.array([17.587, 18.956, 25.0]) idl_sigma_g1 = np.array([123.382, 611.711, np.inf]) idl_sigma_g2 = np.array([8.48481, 82.8938, np.inf]) # Test color1 py_outputs = cbkg2.sigma_g_diagonal(1, col1, refmags) testing.assert_almost_equal(py_outputs, idl_sigma_g1, decimal=3) # Test color2 py_outputs = cbkg2.sigma_g_diagonal(2, col2, refmags) testing.assert_almost_equal(py_outputs, idl_sigma_g2, decimal=3) ##################################################### # Now a test of the generation of a color background conf_filename = 'testconfig.yaml' config = Configuration(file_path + "/" + conf_filename) tfile = tempfile.mkstemp() os.close(tfile[0]) config.bkgfile_color = tfile[1] config.d.nside = 128 config.d.hpix = 8421 config.border = 0.0 cbg = ColorBackgroundGenerator(config, minrangecheck=5) # Need to set clobber=True because the tempfile was created cbg.run(clobber=True) fits = fitsio.FITS(config.bkgfile_color) # Make sure we have 11 extensions testing.assert_equal(len(fits), 11) # Check the 01_01 and 01_02 bkg11 = fits['01_01_REF'].read() bkg11_compare = fitsio.read(file_path + "/test_dr8_bkg_zredc_sub.fits", ext='01_01_REF') testing.assert_almost_equal(bkg11['BC'], bkg11_compare['BC'], 3) testing.assert_almost_equal(bkg11['N'], bkg11_compare['N'], 3) bkg12 = fits['01_02_REF'].read() bkg12_compare = fitsio.read(file_path + "/test_dr8_bkg_zredc_sub.fits", ext='01_02_REF') testing.assert_almost_equal(bkg12['BC'], bkg12_compare['BC'], 2) testing.assert_almost_equal(bkg12['N'], bkg12_compare['N'], 4) # And delete the tempfile os.remove(config.bkgfile_color)
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)
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))