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)
def runTest(self): """ Run the apply_errormodels() test. """ file_path = 'data_for_tests' conf_filename = 'testconfig.yaml' config = Configuration(file_path + '/' + conf_filename) mask = HPMask(config) #Create the mask maskgal_index = mask.select_maskgals_sample() #set all the necessary inputs from test file mask.maskgals.exptime = 100. mask.maskgals.limmag = 20. mask.maskgals.zp[0] = 22.5 mask.maskgals.nsig[0] = 10. #necessary as mask.maskgals.exptime has shape (6000,) mag_in = np.full(6000, 1, dtype=float) mag_in[:6] = np.array([16., 17., 18., 19., 20., 21.]) #test without noise mag, mag_err = apply_errormodels(mask.maskgals, mag_in, nonoise=True) idx = np.array([0, 1, 2, 3, 4, 5]) mag_idl = np.array([16., 17., 18., 19., 20., 21.]) mag_err_idl = np.array( [0.00602535, 0.0107989, 0.0212915, 0.0463765, 0.108574, 0.264390]) testing.assert_almost_equal(mag[idx], mag_idl) testing.assert_almost_equal(mag_err[idx], mag_err_idl, decimal=6) #test with noise and set seed seed = 0 random.seed(seed=seed) mag, mag_err = apply_errormodels(mask.maskgals, mag_in) idx = np.array([0, 1, 2, 3, 4, 5, 1257, 2333, 3876]) mag_test = np.array([ 15.98942267, 16.99568733, 17.97935868, 18.90075284, 19.81409659, 21.29508236, 0.99999373, 1.00000663, 1.00000807 ]) mag_err_test = np.array([ 5.96693051e-03, 1.07560575e-02, 2.08905241e-02, 4.23251692e-02, 9.14877522e-02, 3.46958444e-01, 5.44154045e-06, 5.44160510e-06, 5.44161230e-06 ]) testing.assert_almost_equal(mag[idx], mag_test) testing.assert_almost_equal(mag_err[idx], mag_err_test)
def runTest(self): """ Run the apply_errormodels() test. """ file_path = 'data_for_tests' conf_filename = 'testconfig.yaml' config = Configuration(file_path + '/' + conf_filename) mask = HPMask(config) #Create the mask maskgal_index = mask.select_maskgals_sample() #set all the necessary inputs from test file mask.maskgals.exptime = 100. mask.maskgals.limmag = 20. mask.maskgals.zp[0] = 22.5 mask.maskgals.nsig[0] = 10. #necessary as mask.maskgals.exptime has shape (6000,) mag_in = np.full(6000, 1, dtype = float) mag_in[:6] = np.array([16., 17., 18., 19., 20., 21.]) #test without noise mag, mag_err = apply_errormodels(mask.maskgals, mag_in, nonoise = True) idx = np.array([0, 1, 2, 3, 4, 5]) mag_idl = np.array([16., 17., 18., 19., 20., 21.]) mag_err_idl = np.array([0.00602535, 0.0107989, 0.0212915, 0.0463765, 0.108574, 0.264390]) testing.assert_almost_equal(mag[idx], mag_idl) testing.assert_almost_equal(mag_err[idx], mag_err_idl, decimal = 6) #test with noise and set seed seed = 0 random.seed(seed = seed) mag, mag_err = apply_errormodels(mask.maskgals, mag_in) idx = np.array([0, 1, 2, 3, 4, 5, 1257, 2333, 3876]) mag_test = np.array([15.98942267, 16.99568733, 17.97935868, 18.90075284, 19.81409659, 21.29508236, 0.99999373, 1.00000663, 1.00000807]) mag_err_test = np.array([5.96693051e-03, 1.07560575e-02, 2.08905241e-02, 4.23251692e-02, 9.14877522e-02, 3.46958444e-01, 5.44154045e-06, 5.44160510e-06, 5.44161230e-06]) testing.assert_almost_equal(mag[idx], mag_test) testing.assert_almost_equal(mag_err[idx], mag_err_test)
def runTest(self): """ First test the filters: nfw, lum, and bkg """ # all new... file_path = 'data_for_tests' cluster = Cluster() conf_filename = 'testconfig.yaml' cluster.config = Configuration(file_path + '/' + conf_filename) filename = 'test_cluster_members.fit' neighbors = GalaxyCatalog.from_fits_file(file_path + '/' + filename) cluster.set_neighbors(neighbors) zred_filename = 'test_dr8_pars.fit' cluster.zredstr = RedSequenceColorPar(file_path + '/' + zred_filename, fine=True) bkg_filename = 'test_bkg.fit' cluster.bkg = Background('%s/%s' % (file_path, bkg_filename)) hdr=fitsio.read_header(file_path+'/'+filename,ext=1) #cluster.z = hdr['Z'] #cluster.update_z(hdr['Z']) cluster.redshift = hdr['Z'] richness_compare = hdr['LAMBDA'] richness_compare_err = hdr['LAMBDA_E'] scaleval_compare = hdr['SCALEVAL'] cpars_compare = np.array([hdr['CPARS0'], hdr['CPARS1'], hdr['CPARS2'], hdr['CPARS3']]) cval_compare = hdr['CVAL'] mstar_compare = hdr['MSTAR'] cluster.ra = hdr['RA'] cluster.dec = hdr['DEC'] mask = HPMask(cluster.config) mask.set_radmask(cluster) depthstr = DepthMap(cluster.config) depthstr.calc_maskdepth(mask.maskgals, cluster.ra, cluster.dec, cluster.mpc_scale) # Test the NFW profile on its own # (this works to 5 decimal places because of the 2*pi*r scaling) nfw_python = cluster._calc_radial_profile() testing.assert_almost_equal(nfw_python, neighbors.nfw/(2.*np.pi*neighbors.r),5) # Test the luminosity # The problem is that the IDL code has multiple ways of computing the index. # And this should be fixed here. I don't want to duplicate dumb ideas. #mstar = cluster.zredstr.mstar(cluster.z) #testing.assert_almost_equal(mstar, mstar_compare, 3) #maxmag = mstar - 2.5*np.log10(cluster.config.lval_reference) #lum_python = cluster._calc_luminosity(maxmag) #testing.assert_almost_equal(lum_python, neighbors.lumwt, 3) # Test theta_i #theta_i_python = calc_theta_i(neighbors.refmag, neighbors.refmag_err, # maxmag, cluster.zredstr.limmag) #testing.assert_almost_equal(theta_i_python, neighbors.theta_i, 3) # Test the background # Note that this uses the input chisq values bkg_python = cluster.calc_bkg_density(cluster.neighbors.r, cluster.neighbors.chisq, cluster.neighbors.refmag) # this is cheating here... to_test, = np.where((cluster.neighbors.refmag < cluster.bkg.refmagbins[-1])) #testing.assert_almost_equal(bkg_python[to_test], neighbors.bcounts[to_test], 3) #testing.assert_allclose(bkg_python[to_test], neighbors.bcounts[to_test], # rtol=1e-4, atol=0) # skip this test for now. Blah. # Now the cluster tests # cluster.neighbors.dist = np.degrees(cluster.neighbors.r / cluster.cosmo.Da(0, cluster.redshift)) seed = 0 random.seed(seed = 0) richness = cluster.calc_richness(mask) # these are regression tests. Various mask issues make the matching # to idl for the time being testing.assert_almost_equal(cluster.Lambda, 23.86299324) testing.assert_almost_equal(cluster.lambda_e, 2.4780307) #testing.assert_almost_equal(cluster.neighbors.theta_i, # neighbors.theta_i, 3) #testing.assert_almost_equal(cluster.neighbors.theta_r, # neighbors.theta_r, 3) #testing.assert_almost_equal(cluster.neighbors.p, # neighbors.p, 3) return
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)
def runTest(self): """ Run the ClusterTest """ # all new... random.seed(seed=12345) file_path = 'data_for_tests' cluster = Cluster() conf_filename = 'testconfig.yaml' cluster.config = Configuration(file_path + '/' + conf_filename) filename = 'test_cluster_members.fit' neighbors = GalaxyCatalog.from_fits_file(file_path + '/' + filename) cluster.set_neighbors(neighbors) zred_filename = 'test_dr8_pars.fit' cluster.zredstr = RedSequenceColorPar(file_path + '/' + zred_filename, fine=True) bkg_filename = 'test_bkg.fit' cluster.bkg = Background('%s/%s' % (file_path, bkg_filename)) hdr = fitsio.read_header(file_path + '/' + filename, ext=1) cluster.redshift = hdr['Z'] richness_compare = hdr['LAMBDA'] richness_compare_err = hdr['LAMBDA_E'] scaleval_compare = hdr['SCALEVAL'] cpars_compare = np.array( [hdr['CPARS0'], hdr['CPARS1'], hdr['CPARS2'], hdr['CPARS3']]) cval_compare = hdr['CVAL'] mstar_compare = hdr['MSTAR'] cluster.ra = hdr['RA'] cluster.dec = hdr['DEC'] mask = HPMask(cluster.config) maskgal_index = mask.select_maskgals_sample(maskgal_index=0) mask.set_radmask(cluster) depthstr = DepthMap(cluster.config) depthstr.calc_maskdepth(mask.maskgals, cluster.ra, cluster.dec, cluster.mpc_scale) # Test the NFW profile on its own # (this works to 5 decimal places because of the 2*pi*r scaling) nfw_python = cluster._calc_radial_profile() testing.assert_almost_equal(nfw_python, neighbors.nfw / (2. * np.pi * neighbors.r), 5) # Test the background # Note that this uses the input chisq values bkg_python = cluster.calc_bkg_density(cluster.neighbors.r, cluster.neighbors.chisq, cluster.neighbors.refmag) # this is cheating here... to_test, = np.where( (cluster.neighbors.refmag < cluster.bkg.refmagbins[-1])) seed = 0 random.seed(seed=0) richness = cluster.calc_richness(mask) # these are regression tests. Various mask issues make the matching # to idl for the time being testing.assert_almost_equal(cluster.Lambda, 24.366407, 5) testing.assert_almost_equal(cluster.lambda_e, 2.5137918, 5) return
def runTest(self): """ Run tests on redmapper.Zlambda """ random.seed(seed=12345) file_path = 'data_for_tests' conf_filename = 'testconfig.yaml' config = Configuration(file_path + '/' + conf_filename) filename = 'test_cluster_members.fit' neighbors = GalaxyCatalog.from_fits_file(file_path + '/' + filename) 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)) cluster = Cluster(config=config, zredstr=zredstr, bkg=bkg, neighbors=neighbors) hdr=fitsio.read_header(file_path+'/'+filename,ext=1) cluster.redshift = hdr['Z'] richness_compare = hdr['LAMBDA'] richness_compare_err = hdr['LAMBDA_E'] cluster.ra = hdr['RA'] cluster.dec = hdr['DEC'] #Set up the mask mask = HPMask(cluster.config) #Create the mask maskgal_index = mask.select_maskgals_sample(maskgal_index=0) mask.set_radmask(cluster) #depthstr depthstr = DepthMap(cluster.config) depthstr.calc_maskdepth(mask.maskgals, cluster.ra, cluster.dec, cluster.mpc_scale) cluster.neighbors.dist = np.degrees(cluster.neighbors.r/cluster.cosmo.Dl(0,cluster.redshift)) # make a zlambda object zlam = Zlambda(cluster) z_lambda, z_lambda_e = zlam.calc_zlambda(cluster.redshift, mask, calc_err=True, calcpz=True) # I am not sure why this isn't repeatable better than this testing.assert_almost_equal(cluster.z_lambda, 0.22666427, 6) testing.assert_almost_equal(cluster.z_lambda_err, 0.00443601, 4) # zlambda_err test z_lambda_err = zlam._zlambda_calc_gaussian_err(cluster.z_lambda) testing.assert_almost_equal(z_lambda_err, 0.0063738347, 5) # and test the correction on its own corr_filename = 'test_dr8_zlambdacorr.fit' zlambda_corr = ZlambdaCorrectionPar(file_path + '/' + corr_filename, zlambda_pivot=30.0) zlam_in = 0.227865 zlam_e_in = 0.00629995 zlam_out = 0.228654 zlam_e_out = 0.00840213 zlam_new, zlam_e_new = zlambda_corr.apply_correction(24.5, zlam_in, zlam_e_in) testing.assert_almost_equal(zlam_new, zlam_out, 5) testing.assert_almost_equal(zlam_e_new, zlam_e_out, 5)
def runTest(self): """ Run the ClusterTest """ # all new... random.seed(seed=12345) file_path = 'data_for_tests' cluster = Cluster() conf_filename = 'testconfig.yaml' cluster.config = Configuration(file_path + '/' + conf_filename) filename = 'test_cluster_members.fit' neighbors = GalaxyCatalog.from_fits_file(file_path + '/' + filename) cluster.set_neighbors(neighbors) zred_filename = 'test_dr8_pars.fit' cluster.zredstr = RedSequenceColorPar(file_path + '/' + zred_filename, fine=True) bkg_filename = 'test_bkg.fit' cluster.bkg = Background('%s/%s' % (file_path, bkg_filename)) hdr=fitsio.read_header(file_path+'/'+filename,ext=1) cluster.redshift = hdr['Z'] richness_compare = hdr['LAMBDA'] richness_compare_err = hdr['LAMBDA_E'] scaleval_compare = hdr['SCALEVAL'] cpars_compare = np.array([hdr['CPARS0'], hdr['CPARS1'], hdr['CPARS2'], hdr['CPARS3']]) cval_compare = hdr['CVAL'] mstar_compare = hdr['MSTAR'] cluster.ra = hdr['RA'] cluster.dec = hdr['DEC'] mask = HPMask(cluster.config) maskgal_index = mask.select_maskgals_sample(maskgal_index=0) mask.set_radmask(cluster) depthstr = DepthMap(cluster.config) depthstr.calc_maskdepth(mask.maskgals, cluster.ra, cluster.dec, cluster.mpc_scale) # Test the NFW profile on its own # (this works to 5 decimal places because of the 2*pi*r scaling) nfw_python = cluster._calc_radial_profile() testing.assert_almost_equal(nfw_python, neighbors.nfw/(2.*np.pi*neighbors.r),5) # Test the background # Note that this uses the input chisq values bkg_python = cluster.calc_bkg_density(cluster.neighbors.r, cluster.neighbors.chisq, cluster.neighbors.refmag) # this is cheating here... to_test, = np.where((cluster.neighbors.refmag < cluster.bkg.refmagbins[-1])) seed = 0 random.seed(seed = 0) richness = cluster.calc_richness(mask) # these are regression tests. Various mask issues make the matching # to idl for the time being testing.assert_almost_equal(cluster.Lambda, 24.366407, 5) testing.assert_almost_equal(cluster.lambda_e, 2.5137918, 5) return
def runTest(self): file_path = 'data_for_tests' #The configuration #Used by the mask, background and richness calculation conf_filename = 'testconfig.yaml' config = Configuration(file_path + '/' + conf_filename) filename = 'test_cluster_members.fit' neighbors = GalaxyCatalog.from_fits_file(file_path + '/' + filename) 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)) cluster = Cluster(config=config, zredstr=zredstr, bkg=bkg, neighbors=neighbors) hdr = fitsio.read_header(file_path + '/' + filename, ext=1) #cluster.z = hdr['Z'] #cluster.update_z(hdr['Z']) cluster.redshift = hdr['Z'] richness_compare = hdr['LAMBDA'] richness_compare_err = hdr['LAMBDA_E'] cluster.ra = hdr['RA'] cluster.dec = hdr['DEC'] #Set up the mask mask = HPMask(cluster.config) #Create the mask mask.set_radmask(cluster) #depthstr depthstr = DepthMap(cluster.config) depthstr.calc_maskdepth(mask.maskgals, cluster.ra, cluster.dec, cluster.mpc_scale) cluster.neighbors.dist = np.degrees( cluster.neighbors.r / cluster.cosmo.Dl(0, cluster.redshift)) #set seed seed = 0 random.seed(seed=seed) # make a zlambda object zlam = Zlambda(cluster) z_lambda, z_lambda_e = zlam.calc_zlambda(cluster.redshift, mask, calc_err=True, calcpz=True) testing.assert_almost_equal(cluster.z_lambda, 0.22700983) testing.assert_almost_equal(cluster.z_lambda_err, 0.00448909596) # zlambda_err test z_lambda_err = zlam._zlambda_calc_gaussian_err(cluster.z_lambda) testing.assert_almost_equal(z_lambda_err, 0.006303830) # and test the correction on its own corr_filename = 'test_dr8_zlambdacorr.fit' zlambda_corr = ZlambdaCorrectionPar(file_path + '/' + corr_filename, 30.0) zlam_in = 0.227865 zlam_e_in = 0.00629995 zlam_out = 0.228654 zlam_e_out = 0.00840213 zlam_new, zlam_e_new = zlambda_corr.apply_correction( 24.5, zlam_in, zlam_e_in) testing.assert_almost_equal(zlam_new, zlam_out, 5) testing.assert_almost_equal(zlam_e_new, zlam_e_out, 5)
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)