def runTest(self): """ """ 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([142.10934, 142.04090, 142.09242, 142.11448, 50.0]) Decs = np.array([65.022666, 65.133844, 65.084844, 65.109541, 50.0]) comp_limmag = np.array( [20.6847, 20.5915, 20.5966, 20.5966, -1.63750e+30], dtype='f4') comp_exptime = np.array( [70.3742, 63.5621, 63.5621, 63.5621, -1.63750e+30], dtype='f4') comp_m50 = np.array([20.8964, 20.8517, 20.8568, 20.8568, -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.hpix = 582972 config2.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.hpix = 8421 config3.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): """ 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 runTest(self): 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.nside = 128 config.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)