def TpkSZ_calc(r, tau, z, sigmadc, richmin, richmax, gamma=4. / 7.): ''' pkSZ = zeros(len(r)) for i in range(len(r)): ''' M200min = DESrichtomass(richmin, z) * h M200max = DESrichtomass(richmax, z) * h Mmin, Rnew, Cnew = mass_adv.changeMassDefinitionCModel( M200min, z, '200m', '200c') Mmax, Rnew, Cnew = mass_adv.changeMassDefinitionCModel( M200max, z, '200m', '200c') pkSZ = TpkSZmodel(tau, r, z, sigmadc, Mmin / h, Mmax / h, gamma) return pkSZ
def mass_to_M200c(M, z, cosmology): #{{{ # converts M200m mass into M200c mass M200c, R200c, c200c = mass_adv.changeMassDefinitionCModel( M, z, cosmology['mass_def_initial'], cosmology['mass_def_batt'], profile=cosmology['halo_profile'], c_model=cosmology['concentration_model']) return M200c
def virial_radius_small_masses(self, M, z, massdef): #{{{ if not self.initialized_colossus: self._initialize_colossus() _, rvir, _ = mass_adv.changeMassDefinitionCModel( M, z, massdef, 'vir', profile=self.halo_profile, c_model=self.small_mass_concentration_model) return rvir * 1e-3 # Mpc/h
def masstorich(mass, z, massdef='200c'): ''' Convert mass to richness in DES according to (McClintock 2018) ''' assert (len(mass) == len(z)) Mnew = np.zeros(len(mass)) for i in range(len(mass)): Mnew[i], Rnew, Cnew = mass_adv.changeMassDefinitionCModel( mass[i] * h, z[i], massdef, '200m') Mnew = Mnew / h return 40 * ((Mnew / M0) * (1.35 / (1 + z))**G)**(1. / F)
def virial_radius(M, z, numerics, cosmology): #{{{ #if cosmology['mass_def_initial'] != 'vir': # print 'Initial Mass definition not virial' M_vir, r_vir, c_vir = mass_adv.changeMassDefinitionCModel( M, z, cosmology['mass_def_initial'], 'vir', profile=cosmology['halo_profile'], c_model=cosmology['concentration_model']) return r_vir * 1e-3
def convert_mass(self, M, z, massdefin, massdefout): #{{{ if massdefin == massdefout: return M if not self.initialized_colossus: self._initialize_colossus() Mout, _, _ = mass_adv.changeMassDefinitionCModel( M, z, massdefin, massdefout, profile=self.halo_profile, c_model=self.concentration_model) return Mout
def mass_to_M200m(M, z, cosmology): #{{{ # converts Mvir mass into M200m mass if cosmology['mass_def_initial'] == '200m': return M else: M200m, R200m, c200m = mass_adv.changeMassDefinitionCModel( M, z, cosmology['mass_def_initial'], cosmology['mass_def_Tinker'], profile=cosmology['halo_profile'], c_model=cosmology['concentration_model']) return M200m
def masstoradvir(m, z): ''' Go mass to viral radius using the colossus package ''' Mnew, Rnew, Cnew = mass_adv.changeMassDefinitionCModel(m * h, z, '200c', 'vir', profile='nfw', c_model='diemer19') thetavir = Rnew * 1e-3 / cosmo.angularDiameterDistance( z) #Angular distance in radians return thetavir * 3437.75 / h #Return the angular size in arcmin
def richtoradvir(richness, z): ''' Convert Richness to virial radii from the DES RedMapper in (McClintock 2018) ''' h = cosmo.Hz(z) / 100 M200m = M0 * ((richness / 40)**F) * (((1 + z) / 1.35)**G) #M_sun Mnew, Rnew, Cnew = mass_adv.changeMassDefinitionCModel(M200m * h, z, '200m', 'vir', profile='nfw', c_model='diemer19') thetavir = Rnew * 1e-3 / cosmo.angularDiameterDistance( z) #Angular distance in radians return thetavir * 3437.75 / h #Return the angular size in arcmin
def load_xcs_file(fname): df = pd.read_csv(fname, sep='|', skiprows=4) df.drop(columns=['Unnamed: 0', 'Unnamed: 11'], inplace=True) df = df[df['r_200'] != ' '].reset_index() # exit() df['ra'] = df['ra '].map(radec_string_to_float) df['dec'] = df['dec '].map(radec_string_to_float) xcs_cat = {} xcs_cat['z'] = df['redshift'].astype(float).to_numpy() xcs_cat['ra'] = df['ra'].astype(float).to_numpy() xcs_cat['dec'] = df['dec'].to_numpy() xcs_cat['r200c'] = df['r_200'].astype(float) xcs_cat['r200c_upper'] = (df['r_200'].astype(float) + df['r_200_pos_err'].astype(float)).to_numpy() xcs_cat['r200c_lower'] = (df['r_200'].astype(float) + df['r_200_neg_err'].astype(float)).to_numpy() xcs_cat['m200c'] = mass_so.R_to_M(xcs_cat['r200c'] * 0.7, xcs_cat['z'], '200c') # collosus xcs_cat['m200c_upper'] = mass_so.R_to_M(xcs_cat['r200c_upper'] * 0.7, xcs_cat['z'], '200c') # collosus xcs_cat['m200c_lower'] = mass_so.R_to_M(xcs_cat['r200c_lower'] * 0.7, xcs_cat['z'], '200c') # collosus m200m = np.zeros_like(xcs_cat['z']) r200m = np.zeros_like(xcs_cat['z']) c200m = np.zeros_like(xcs_cat['z']) for i in range(0, len(m200m)): m200m[i], r200m[i], c200m[i] = mass_adv.changeMassDefinitionCModel( xcs_cat['m200c'][i], xcs_cat['z'][i], "200c", "200m", c_model='child18') xcs_cat['m200m'] = m200m xcs_cat['r200m'] = r200m xcs_cat['c200m'] = c200m # plt.figure() # plt.plot(xcs_cat['ra'], xcs_cat['dec'], 'o') # plt.show() # exit() return xcs_cat
def mass_estimate_spider(spider_cat): r200c_deg = spider_cat['r200c_deg'] rad = r200c_deg * 60 r200 = background.arcmin_to_r200(rad, spider_cat['z']) # kpc physical mass_old = background.r200c_to_m200c(r200, spider_cat['z']) #m200c (h?) mass_new = mass_so.R_to_M(r200 * 0.7, spider_cat['z'], '200c') # collosus mass = mass_so.R_to_M(r200 * 0.7, spider_cat['z'], '200c') # collosus spider_cat['m200c'] = mass # plt.figure() # plt.loglog(mass_new, mass_old, '.') # plt.figure() # plt.semilogx(mass_new, mass_new/mass_old, '.') # plt.show() m200m_list = [] m200m_richness_list = [] m200c_richness_list = [] for m200c, redshift, richness in zip(mass, spider_cat['z'], spider_cat['lambda']): m200m, r200m, c200m = mass_adv.changeMassDefinitionCModel( m200c, redshift, "200c", "200m", c_model='child18') m200m_list.append(m200m) m200m, r200m = background.lambda_to_m200_r200( richness, redshift, richness_mass_author="Simet_mean") m200c, r200c = background.lambda_to_m200_r200( richness, redshift, richness_mass_author="Simet_crit") m200m_richness_list.append(m200m) m200c_richness_list.append(m200c) mass = np.array(m200m_list) r200m_r200c_ratio = r200m / r200 rad *= r200m_r200c_ratio r200 *= r200m_r200c_ratio spider_cat['m200m'] = np.array(m200m_list) spider_cat['rad'] = rad spider_cat['m200m_lambda'] = np.array(m200m_richness_list) spider_cat['m200c_lambda'] = np.array(m200c_richness_list)
def check_halo_conversion(sod_location, time_step, redshift): a = 1.0/(1.0 + redshift) cat = load_halo_cat(sod_location.replace("${step}", str(time_step)), h_scaling) M200c_col, R200c_col, c200c_col = mass_adv.changeMassDefinitionCModel(cat['sod_halo_mass']/0.7, redshift, "200c","200c", c_model='child18')#cat['sod_cdelta'] plt.figure() plt.plot(cat['sod_halo_mass']/0.7, M200c_col, '.', alpha=0.3) plt.yscale('log') plt.xscale('log') plt.title('mass') plot_1to1() plt.figure() plt.plot(cat['sod_halo_radius'], R200c_col/1000.0/0.7*a, '.', alpha=0.3) plt.yscale('log') plt.xscale('log') plt.title('radius') plot_1to1() plt.figure() plt.plot(cat['sod_halo_radius'], (R200c_col/1000.0/0.7*a)/cat['sod_halo_radius'], '.', alpha=0.3) plt.xscale('log') plt.show()
def convert_halo_m200c_to_m200m( sod_location, sod_output, time_step, redshift , h_scaling, write_catalog=False): a = 1.0/(1.0+redshift) # rho_mean = get_rho_mean_over_rho_crit(redshift) # This catalog has h=0.7 cat = load_halo_cat(sod_location.replace("${step}", str(time_step)), h_scaling) M200m_col, R200m_col, c200m_col = mass_adv.changeMassDefinitionCModel(cat['sod_halo_mass']/0.7, redshift, "200c","200m", c_model='child18')#cat['sod_cdelta'] M200c_col, R200c_col, c200c_col = mass_adv.changeMassDefinitionCModel(cat['sod_halo_mass']/0.7, redshift, "200c","200c", c_model='child18')#cat['sod_cdelta'] R_200m = R200m_col/1000.0/0.7 M_200m = M200m_col*0.7 R_200c = R200c_col/1000.0/0.7 M_200c = M200c_col*0.7 cat['sod_halo_radius_r200m'] = R_200m*a cat['sod_halo_mass_m200m'] = M_200m cat['sod_halo_cdelta_200m'] = c200m_col cat['sod_halo_radius_r200c'] = R_200c*a cat['sod_halo_mass_m200c'] = M_200c cat['sod_halo_cdelta_200c'] = c200c_col if( write_catalog): print("writing catalog") write_halo_cat(sod_output.replace("${step}", str(time_step)), cat, h_scaling) exit() else: print("plotting tests") h, xbins, ybins = np.histogram2d(np.log10(cat['sod_halo_mass']), np.log10(M_200c), bins = 250) plt.figure() plt.pcolor(xbins, ybins, h.T, cmap = 'Blues', norm = clr.LogNorm()) plt.plot([np.min(xbins), np.max(xbins)], [np.min(xbins), np.max(xbins)], '--k') plt.ylabel('Col M200c') plt.xlabel('SOD M200c') print(np.mean(R_200c*a/cat['sod_halo_radius']), np.mean(cat['sod_halo_radius']/R_200c/a), a) h, xbins, ybins = np.histogram2d(cat['sod_halo_radius'],R_200c*a, bins = 250) plt.figure() plt.pcolor(xbins, ybins, h.T, cmap = 'Blues', norm = clr.LogNorm()) plt.plot([np.min(xbins), np.max(xbins)], [np.min(xbins), np.max(xbins)], '--k') plt.ylabel('Col R200c') plt.xlabel('SOD R200c') plt.show() h, xbins, ybins = np.histogram2d(np.log10(M_200c), R_200m/R_200c, bins = 250) plt.figure() plt.pcolor(xbins, ybins, h.T, cmap = 'Blues', norm = clr.LogNorm()) plt.ylabel('R_200m/R_200c') plt.xlabel('M_200c') h, xbins, ybins = np.histogram2d(np.log10(M_200c), M_200m/M_200c, bins = 250) plt.figure() plt.pcolor(xbins, ybins, h.T, cmap = 'Blues', norm = clr.LogNorm()) plt.ylabel('M_200m/M_200c') plt.xlabel('M_200c') h, xbins = np.histogram(cat['sod_halo_cdelta'], bins = 100) plt.figure() plt.plot(dtk.bins_avg(xbins), h, '-x') M200m_col, R200m_col, c200m_col = mass_adv.changeMassDefinitionCModel(cat['sod_halo_mass']/0.7, redshift, "200c","200m", c_model='child18')#cat['sod_cdelta'] plt.figure() h, xbins,ybins = np.histogram2d(np.log10(M_200m), np.log10(M200m_col), bins =256) plt.pcolor(xbins, ybins, h.T, cmap='Blues', norm=clr.LogNorm()) plt.plot([np.min(xbins), np.max(xbins)], [np.min(xbins), np.max(xbins)], '--k') plt.xlabel("my m200m") plt.ylabel('colossus m200m') plt.figure() h, xbins, ybins = np.histogram2d(np.log10(M_200c), M_200c/M_200m, bins=100) plt.pcolor(xbins, ybins, h.T, cmap='Blues', norm=clr.LogNorm()) xbins_cen = dtk.bins_avg(xbins) median = dtk.binned_median(np.log10(M_200c), M_200c/M_200m, xbins) plt.plot(xbins_cen, median, '-k', label='median') plt.legend(loc='best', framealpha=0.0) plt.xlabel("M200c") plt.ylabel("M200c/M200m") plt.figure() h, xbins, ybins = np.histogram2d(np.log10(M_200m), M_200c/M_200m, bins=100) plt.pcolor(xbins, ybins, h.T, cmap='Blues', norm=clr.LogNorm()) xbins_cen = dtk.bins_avg(xbins) median = dtk.binned_median(np.log10(M_200m), M_200c/M_200m, xbins) plt.plot(xbins_cen, median, '-k', label='median') plt.legend(loc='best', framealpha=0.0) plt.xlabel("M200m") plt.ylabel("M200c/M200m") plt.figure() M200m_col_lin, R200m_col_lin, c200m_col_lin = mass_adv.changeMassDefinitionCModel(np.logspace(12,15,100), redshift, "200c", "200m", c_model='child18') h, xbins, ybins = np.histogram2d(np.log10(M_200m), np.log10(R_200m), bins=100) plt.pcolor(xbins, ybins, h.T, cmap='Blues', norm=clr.LogNorm()) plt.plot(np.log10(M200m_col_lin), np.log10(R200m_col_lin), '--k', label='Colossus') plt.xlabel('M200m') plt.ylabel('R200m') plt.show()
def query_sdss_culster(file_loc, cat_ra, cat_dec, cat_z, cat_lambda, name, num, start=0, plot=False, spider_rad=None, spider_mean=False, query_galaxy_only=True, r200_factor=None, richness_mass_author=None): fails = [] if(query_galaxy_only): query_table = "Galaxy" else: query_table = "PhotoObj" print("querying...") hfile = h5py.File(file_loc+"query_results.hdf5",mode='a') for i in range(start,num): #try: start = time.time() print("%d/%d"%(i+1,num)) keys = hfile.keys() if("%s%d"%(name,i) in keys and "%s_prop%d"%(name,i) in keys): continue; if "%s%d"%(name,i) in keys: del hfile["%s%d"%(name,i)] if "%s_prop%d"%(name,i) in keys: del hfile["%s_prop%d"%(name,i)] #query columns are defined here: #http://skyserver.sdss.org/dr8/en/help/browser/browser.asp?n=PhotoObjAll&t=U ra = cat_ra[i] dec = cat_dec[i] z = cat_z[i] richness = cat_lambda[i] # Xray Spiders have their own r200c, so we don't need to compute it. if spider_rad is None: mass, r200 = background.lambda_to_m200_r200(richness,z, richness_mass_author=richness_mass_author) rad = background.r200_to_arcmin(r200, z) else: r200c_deg = spider_rad[i] rad = r200c_deg * 60 r200 = background.arcmin_to_r200(rad, z) mass = background.r200c_to_m200c(r200, z) if spider_mean: m200m, r200m, c200m =mass_adv.changeMassDefinitionCModel(mass, z, "200c", "200m", c_model='child18') mass = m200m r200m_r200c_ratio = r200m/r200 rad *= r200m_r200c_ratio r200 *= r200m_r200c_ratio hgroup = hfile.create_group("%s_prop%d"%(name,i)) hgroup.create_dataset("ra",data=ra) hgroup.create_dataset("dec",data=dec) hgroup.create_dataset("z",data=z) hgroup.create_dataset("mass",data=mass) hgroup.create_dataset("rad",data=rad) hgroup.create_dataset("r200",data=r200) hgroup.create_dataset("richness", data = richness) ## Query and save objects around target query_str = "select p.ra, p.dec, p.type,p.insidemask,p.flags_g,p.flags_i,p.flags_r,p.cModelMag_u, p.cModelMagErr_u,p.cModelMag_g, p.cModelMagErr_g,p.cModelMag_r, p.cModelMagErr_r,p.cModelMag_i, p.cModelMagErr_i,p.cModelMag_z, p.cModelMagErr_z from "+query_table+" p join dbo.fGetNearbyObjEq(%f,%f,%f) r on p.ObjID = r.ObjID"%(ra, dec, r200_factor*rad) result = sqlcl.query(query_str).read() # datagal = np.genfromtxt(StringIO(result),names=True,delimiter=', ',dtype=['f8','f8','i2','i1','i8','i8','i8', 'f4','f4', 'f4','f4', 'f4','f4', 'f4','f4', 'f4','f4']) try: datagal = np.genfromtxt(StringIO(result),names=True,skip_header=1,delimiter=',',dtype=['f8','f8','i2','i1','i8','i8','i8', 'f4','f4', 'f4','f4', 'f4','f4', 'f4','f4', 'f4','f4']) except ValueError as e: print(query_str) continue hgroup = hfile.create_group("%s%d"%(name,i)) hgroup.create_dataset("ra",data=datagal['ra']) hgroup.create_dataset("dec",data=datagal['dec']) hgroup.create_dataset("type",data=datagal['type']) hgroup.create_dataset("insidemask",data=datagal['insidemask']) hgroup.create_dataset("flags_g",data=datagal['flags_g']) hgroup.create_dataset("flags_i",data=datagal['flags_i']) hgroup.create_dataset("flags_r",data=datagal['flags_r']) hgroup.create_dataset("mag_u",data=datagal['cModelMag_u']) hgroup.create_dataset("mag_err_u",data=datagal['cModelMagErr_u']) hgroup.create_dataset("mag_g",data=datagal['cModelMag_g']) hgroup.create_dataset("mag_err_g",data=datagal['cModelMagErr_g']) hgroup.create_dataset("mag_r",data=datagal['cModelMag_r']) hgroup.create_dataset("mag_err_r",data=datagal['cModelMagErr_r']) hgroup.create_dataset("mag_i",data=datagal['cModelMag_i']) hgroup.create_dataset("mag_err_i",data=datagal['cModelMagErr_i']) hgroup.create_dataset("mag_z",data=datagal['cModelMag_z']) hgroup.create_dataset("mag_err_z",data=datagal['cModelMagErr_z']) end = time.time() print(" time: %.2f"%float(end-start)) if(plot): plt.figure() legends = ["uknown","cosmic_ray","defect","galaxy","ghost","knownobj","star","trail","sky","notatype"] slct1 = datagal['insidemask']==0 for i in range(0,10): slct = (datagal["type"] == i) & slct1 plt.plot(datagal['ra'][slct],datagal['dec'][slct],'x',label=legends[i]) plt.legend(loc='best') plt.xlabel('ra') plt.ylabel('dec') plt.show() # except ValueError as ie: # print ie # fails.append(i) # print "Failure" np.save(file_loc+"fail_indexs.npy",fails) hfile.close();
def m500c_to_m200c(m500c, z): cosmology.setCosmology('WMAP7') M200m_col, R200m_col, c200m_col = mass_adv.changeMassDefinitionCModel( m500c, z, "500c", "200c", c_model='child18') #cat['sod_cdelta'] return M200c_col
def m200c_to_m200m(m200c, z): #TODO More Accurate translation cosmology.setCosmology('WMAP7') M200m_col, R200m_col, c200m_col = mass_adv.changeMassDefinitionCModel( m200c, z, "200c", "200m", c_model='child18') #cat['sod_cdelta'] return M200c_col