def ln_likelihood_2d(mu_obs, sig_obs, z_vector, theta): #print (h) cosmo = LambdaCDM(Om0=theta[0], Ode0=theta[1], H0=100 * h) mu_pred = cosmo.distmod(z_vector).value #print ('pred', ) chi_2 = np.sum(np.power(((mu_obs - mu_pred) / sig_obs), 2.0)) return (-chi_2 / 2.0)
def lumdis(z, key): Ho = cosmology[key].H #hubble constant mo = cosmology[key].Om #matter l = cosmology[key].Ol #dark energyH k = cosmology[key].Ok #curvature cos = LambdaCDM(H0=Ho, Om0=mo, Ode0=l) #Ok0 = k should work but it doesn't return cos.luminosity_distance(z)
def test_redshifts_from_comoving_density(): from skypy.galaxy.redshift import redshifts_from_comoving_density from astropy.cosmology import LambdaCDM # random cosmology H0 = np.random.uniform(50, 100) Om = np.random.uniform(0.1, 0.9) Ol = np.random.uniform(0.1, 0.9) cosmo = LambdaCDM(H0=H0, Om0=Om, Ode0=Ol) # fixed comoving density of Ngal galaxies total Ngal = 1000 redshift = np.arange(0.0, 2.001, 0.1) density = Ngal/cosmo.comoving_volume(redshift[-1]).to_value('Mpc3') fsky = 1.0 # sample galaxies over full sky without Poisson noise z_gal = redshifts_from_comoving_density(redshift, density, fsky, cosmo, noise=False) # make sure number of galaxies is correct (no noise) assert np.isclose(len(z_gal), Ngal, atol=1, rtol=0) # test the distribution of the sample against the analytical CDF V_max = cosmo.comoving_volume(redshift[-1]).to_value('Mpc3') D, p = kstest(z_gal, lambda z: cosmo.comoving_volume(z).to_value('Mpc3')/V_max) assert p > 0.01, 'D = {}, p = {}'.format(D, p)
def NFW_fit(e, theta, Lambda, z, h=0.7): a = np.linspace(-10, 10, 100) x, y = np.meshgrid(a, a) q = (1. - e) / (1. + e) r = np.sqrt(q * (x**2) + (y**2) / q) # SIMET RELATION FOR M200 M0 = (2.21e14) / h alpha = 1.33 M200 = M0 * ((Lambda / 40.)**alpha) # Compute cosmological parameters cosmo = LambdaCDM(H0=h * 100, Om0=0.3, Ode0=0.7) H = cosmo.H(z).value / (1.0e3 * pc) #H at z_pair s-1 roc = (3.0 * (H**2.0)) / (8.0 * np.pi * G) #critical density at z_pair (kg.m-3) roc_mpc = roc * ((pc * 1.0e6)**3.0) # Compute R_200 R200 = r200_nfw(M200, roc_mpc) # S_nfw R_200 S_nfw = SIGMA_nfw((r, sigma_c, z, h), R200) x_rot = (x * np.cos(t) + y * np.sin(t)) y_rot = (-1. * x * np.sin(t) + y * np.cos(t)) w = np.ones(len(x_rot[mask])) e, ang = momentos(x_rot[mask], y_rot[mask], w) return e, np.rad2deg(ang)
def lumdis(z, key): Ho = cosmology[key].H mo = cosmology[key].Om deo = cosmology[key].Ode l = cosmology[key].Ok cos = LambdaCDM(H0=Ho, Om0=mo, Ode0=l) return cos.luminosity_distance(z)
def get_circle_rad(reffile, inp): z = reffile['z'] re_UV = reffile['hlr_f814w_kpc'] re_opt = reffile['hlr_f160w_kpc'] scalar_list = [] for i in z: cosmo = LambdaCDM(H0=70 * u.km / u.s / u.Mpc, Tcmb0=2.725 * u.K, Om0=0.3, Ode0=.7) scale = cosmo.kpc_proper_per_arcmin(i).to('kpc/arcsec') scalar = float(scale / (1.0 * (u.kpc / u.arcsec))) scalar_list.append(scalar) new_scale = [] for i in scalar_list: a = (1 / 3600) * (1 / i) new_scale.append(a) UV_rad = [] opt_rad = [] if inp == 'UV': for i, j in zip(new_scale, re_UV): a = i * j UV_rad.append(a) return UV_rad if inp == 'opt': for i, j in zip(new_scale, re_opt): b = i * j opt_rad.append(b) return opt_rad
class LambdaCDMBenchmarks: H0 = 65 * u.km / u.s / u.Mpc TCMB0 = 2.7 * u.K params = [ LambdaCDM(H0, 0.6, 0.7, 0), LambdaCDM(H0, 0.25, 0.65, TCMB0, 3.04), LambdaCDM(H0, 0.6, 0.7, TCMB0, 4), LambdaCDM(H0, 0.4, 0.2, TCMB0, 3.04), FlatLambdaCDM(H0, 0.25, 0), FlatLambdaCDM(H0, 0.25, TCMB0, 3.04), FlatLambdaCDM(H0, 0.25, TCMB0, 3.04, [0.05, 0.1, 0.15] * u.eV) ] def setup(self, cosmo): self.cosmology = cosmo self.test_zs = np.linspace(0.1, 5.0, 200) def teardown(self, cosmo): del self.cosmology del self.test_zs def time_lumdist(self, cosmo): self.cosmology.luminosity_distance(self.test_zs) def time_age(self, cosmo): self.cosmology.age(self.test_zs)
def _init_from_params(self, H0, Omega_b0, Omega_dm0, Omega_k0): Om0 = Omega_b0 + Omega_dm0 Ob0 = Omega_b0 Ode0 = 1.0 - Om0 - Omega_k0 self.be_cosmo = LambdaCDM(H0=H0, Om0=Om0, Ob0=Ob0, Ode0=Ode0)
def calc_absmag(rmag, galZ, gmag, imag, h, O_matter, O_lambda): # Calculating the distance modulus cosmo = LambdaCDM(H0=h * 100, Om0=O_matter, Ode0=O_lambda) galDl = (cosmo.luminosity_distance(galZ).to('pc')).value DM = 5. * np.log10(galDl / 10.) # Calculating the K-corrections kcorfile = np.loadtxt('kcorrection_list.txt').T zbins = kcorfile[5] kparams = kcorfile[6:9] # Calculating the K-correction per redshift bin galKcor = np.zeros(len(galZ)) for k in range(len(zbins)): zmask = (zbins[k] - 0.005 <= galZ) & (galZ < zbins[k] + 0.005) a, b, c = kparams[:, k] Kcor = a * (gmag - imag)**2 + b * (gmag - imag) + c galKcor[zmask] = Kcor[zmask] # Calculating the absolute magnitude rmag_abs = rmag - DM + galKcor return rmag_abs
def z_angular_mpc(zmean): '''returns the minimum angular cut to be applied in order to discard nonlinearities ''' cosmo = LambdaCDM(H0=67, Om0=0.319, Ode0=0.681, Ob0=0.049) angle = cosmo.arcsec_per_kpc_comoving(zmean).value * 12000. / 60 return angle
def scale_einstein_radius(z_lens, z_src, H0=70, Om0=0.3, Ode0=0.7): cosmo = LambdaCDM(H0=H0, Om0=Om0, Ode0=Ode0) d_ls = cosmo.angular_diameter_distance_z1z2(z_lens, z_src) d_s = cosmo.angular_diameter_distance_z1z2(0, z_src) d = d_ls / d_s return d.value
def partial_profile(RA0, DEC0, Z, RIN, ROUT, ndots, h): ndots = int(ndots) cosmo = LambdaCDM(H0=100 * h, Om0=0.25, Ode0=0.75) dl = cosmo.angular_diameter_distance(Z).value KPCSCALE = dl * (((1.0 / 3600.0) * np.pi) / 180.0) * 1000.0 delta = ROUT / (3600 * KPCSCALE) t0 = time.time() mask = (S.ra < (RA0 + delta)) & (S.ra > (RA0 - delta)) & ( S.dec > (DEC0 - delta)) & (S.dec < (DEC0 + delta)) & (S.z_v > (Z + 0.1)) catdata = S[mask] ds = cosmo.angular_diameter_distance(catdata.z_v).value dls = cosmo.angular_diameter_distance_z1z2(Z, catdata.z_v).value BETA_array = dls / ds Dl = dl * 1.e6 * pc sigma_c = (((cvel**2.0) / (4.0 * np.pi * G * Dl)) * (1. / BETA_array)) * (pc**2 / Msun) rads, theta, test1, test2 = eq2p2(np.deg2rad(catdata.ra), np.deg2rad(catdata.dec), np.deg2rad(RA0), np.deg2rad(DEC0)) r = np.rad2deg(rads) * 3600 * KPCSCALE e1 = catdata.gamma1 e2 = -1. * catdata.gamma2 #get tangential ellipticities et = (-e1 * np.cos(2 * theta) - e2 * np.sin(2 * theta)) * sigma_c k = catdata.kappa * sigma_c r = np.rad2deg(rads) * 3600 * KPCSCALE bines = np.logspace(np.log10(RIN), np.log10(ROUT), num=ndots + 1) dig = np.digitize(r, bines) SIGMA = [] DSIGMA = [] for nbin in range(ndots): mbin = dig == nbin + 1 SIGMA = np.append(SIGMA, np.average(k[mbin])) DSIGMA = np.append(DSIGMA, np.average(k[mbin])) return [SIGMA, DSIGMA]
def setup(self): self.H0_true = 70 self.omega_m_true = 0.3 self._ok_true = 0.1 self.cosmo = FlatLambdaCDM(H0=self.H0_true, Om0=self.omega_m_true, Ob0=0.05) self.cosmo_interp = CosmoInterp(cosmo=self.cosmo, z_stop=3, num_interp=100) self.cosmo_ok = LambdaCDM(H0=self.H0_true, Om0=self.omega_m_true, Ode0=1.0 - self.omega_m_true - self._ok_true) self.cosmo_interp_ok = CosmoInterp(cosmo=self.cosmo_ok, z_stop=3, num_interp=100) self.cosmo_ok_neg = LambdaCDM(H0=self.H0_true, Om0=self.omega_m_true, Ode0=1.0 - self.omega_m_true + self._ok_true) self.cosmo_interp_ok_neg = CosmoInterp(cosmo=self.cosmo_ok_neg, z_stop=3, num_interp=100)
def generate_model_data_vector(self, times, parameters): # parameters = get_parameter_set() cosmo = LambdaCDM(H0=parameters[0], Om0=parameters[1], Ode0=parameters[2], Ob0=parameters[3], Tcmb0=2.725) model_data_vector = cosmo.age(times).value #not keeping units here return model_data_vector
def test_redshifts_from_comoving_density(): from skypy.galaxy.redshift import redshifts_from_comoving_density from astropy.cosmology import LambdaCDM from astropy import units # random cosmology H0 = np.random.uniform(50, 100) Om = np.random.uniform(0.1, 0.9) Ol = np.random.uniform(0.1, 0.9) cosmo = LambdaCDM(H0=H0, Om0=Om, Ode0=Ol) # fixed comoving density of Ngal galaxies total Ngal = 1000 redshift = np.arange(0.0, 2.001, 0.1) density = Ngal / cosmo.comoving_volume(redshift[-1]).to_value('Mpc3') sky_area = 4 * np.pi * units.steradian # sample galaxies over full sky without Poisson noise z_gal = redshifts_from_comoving_density(redshift, density, sky_area, cosmo, noise=False) # make sure number of galaxies is correct (no noise) assert np.isclose(len(z_gal), Ngal, atol=1, rtol=0) # test the distribution of the sample against the analytical CDF V_max = cosmo.comoving_volume(redshift[-1]).to_value('Mpc3') D, p = kstest(z_gal, lambda z: cosmo.comoving_volume(z).to_value('Mpc3') / V_max) assert p > 0.01, 'D = {}, p = {}'.format(D, p) # Test that an error is raised if sky_area has the wrong units sky_area = 1 * units.degree with pytest.raises(units.UnitsError): redshifts_from_comoving_density(redshift, density, sky_area, cosmo, noise=False) # Test that an error is raised if sky_area has no units sky_area = 1 with pytest.raises(TypeError): redshifts_from_comoving_density(redshift, density, sky_area, cosmo, noise=False)
def ln_likelihood_2d(mu_obs, inv_covmat, z_vector, theta, choice): if choice=='FL2': cosmo=FlatLambdaCDM(Om0=theta[0], H0=100*theta[1]) if choice=='OL2': cosmo = LambdaCDM(H0=70, Om0=theta[0], Ode0=theta[1]) if choice=='FW2': cosmo=FlatwCDM(H0=73.8, Om0=theta[0], w0=theta[1]) if choice=='FW3': cosmo=FlatwCDM(Om0=theta[0], w0=theta[1], H0=100*theta[2]) if choice=='OL3': cosmo=LambdaCDM(Om0=theta[0], Ode0=theta[1], H0=100*theta[2]) mu_th=cosmo.distmod(z_vector).value r=(mu_obs-mu_th).reshape(-1, 1) #Check bracketing chi_2=np.sum(np.matmul(np.matmul(r.T, inv_covmat), r)) return (-chi_2/2.0)
def astropyify_ccl_cosmo(cosmoin): """ Given a CCL cosmology object, create an astropy cosmology object Parameters ---------- cosmoin : astropy.cosmology.FlatLambdaCDM or pyccl.core.Cosmology astropy or CCL cosmology object Returns ------- cosmodict : astropy.cosmology.LambdaCDM Astropy cosmology object Notes ----- Need to replace: `import pyccl as ccl cosmo_ccl = ccl.Cosmology(Omega_c=0.27, Omega_b=0.045, h=0.67, A_s=2.1e-9, n_s=0.96)` with `from astropy.cosmology import FlatLambdaCDM astropy_cosmology_object = FlatLambdaCDM(H0=70, Om0=0.27, Ob0=0.045) cosmo_ccl = cclify_astropy_cosmo(astropy_cosmology_object)`` """ if isinstance(cosmoin, LambdaCDM): return cosmoin if isinstance(cosmoin, dict): omega_m = cosmoin['Omega_b'] + cosmoin['Omega_c'] return LambdaCDM(H0=cosmoin['H0'], Om0=omega_m, Ob0=cosmoin['Omega_b'], Ode0=1.0 - omega_m) raise TypeError( "Only astropy LambdaCDM objects or dicts can be converted to astropy.")
def __init__(self, h5file, verbose=True): """ Tool to replicate functionality of `PhotoZ.show_fit` but with data read from a stored HDF5 file rather than a "live" object """ from astropy.cosmology import LambdaCDM self.h5file = h5file self.param = params_from_hdf5(h5file) photoz.PhotoZ.set_zgrid(self) self.NZ = len(self.zgrid) self.templates = templates_from_hdf5(h5file, verbose=verbose) self.NTEMP = len(self.templates) self.set_attrs_from_hdf5() self.set_template_error() self.cosmology = LambdaCDM(H0=self.param['H0'], Om0=self.param['OMEGA_M'], Ode0=self.param['OMEGA_L'], Tcmb0=2.725, Ob0=0.048) self.set_tempfilt()
def time_est(): max_only = True times = np.zeros(len(ndata)) K = 10 pimax = 40. #Mpc/h rpmax = 40 #Mpc/h basisfunc = estimator.tophat rpbins = np.logspace(np.log10(0.1), np.log10(rpmax), K) cosmo = LambdaCDM(H0=70, Om0=0.3, Ode0=0.7) wp = True for i in range(len(ndata)): nd = ndata[i] data1fn = '../../lss/mangler/samples/a0.6452_0001.v5_ngc_ifield_ndata{}.rdzw'.format( nd) rand1fn = '../../lss/mangler/samples/a0.6452_rand20x.dr12d_cmass_ngc_ifield_ndata{}.rdz'.format( nd) start1 = time.time() rps, wprp = run.run(data1fn, rand1fn, data1fn, rand1fn, pimax, rpmax, basisfunc, K, cosmo, wp, rpbins) end1 = time.time() times[i] = end1 - start1 time_arrs = [times] plot_times(time_arrs, ndata)
def load_cosmology(H0 = 69.7, Ob0 = 0.0464, Om0 = 0.1138 / (69.7/100)**2, Ode0 = 0.721, \ Tcmb0 = 2.73, m_nu = 0): new_model = LambdaCDM(H0 = H0, Om0 = Om0, Ob0 = Ob0, Ode0 = Ode0, Tcmb0 = Tcmb0, \ m_nu = m_nu*u.eV) return new_model
def test_cclify_astropy_cosmo(): """ Unit tests for md.cllify_astropy_cosmo """ # Make some base objects truth = {'H0': 70., 'Om0': 0.3, 'Ob0': 0.05} apycosmo_flcdm = FlatLambdaCDM(**truth) apycosmo_lcdm = LambdaCDM(Ode0=1.0 - truth['Om0'], **truth) cclcosmo = { 'Omega_c': truth['Om0'] - truth['Ob0'], 'Omega_b': truth['Ob0'], 'h': truth['H0'] / 100., 'H0': truth['H0'] } # Test for exception if missing baryon density (everything else required) missbaryons = FlatLambdaCDM(H0=truth['H0'], Om0=truth['Om0']) assert_raises(KeyError, md.cclify_astropy_cosmo, missbaryons) # Test output if we pass FlatLambdaCDM and LambdaCDM objects assert_equal(md.cclify_astropy_cosmo(apycosmo_flcdm), cclcosmo) assert_equal(md.cclify_astropy_cosmo(apycosmo_lcdm), cclcosmo) # Test output if we pass a CCL object (a dict right now) assert_equal(md.cclify_astropy_cosmo(cclcosmo), cclcosmo) # Test for exception if anything else is passed in assert_raises(TypeError, md.cclify_astropy_cosmo, 70.) assert_raises(TypeError, md.cclify_astropy_cosmo, [70., 0.3, 0.25, 0.05])
def general_fit(H0, Om, Ol, Ok=0): cozmol = LambdaCDM(H0=H0, Om0=Om, Ode0=Ol) #again, Ok0 = k should work but it doent def cosmol_x(row, z, err, cosmology): z = row[z] model = float(cosmology.luminosity_distance(z) / u.Mpc) x = ((row['dis_mpc'] - model)**2) / row[err]**2 return x #makes a column with a name based off of the cosmology you are testing and produces indivitual values for the sum #format: 'x^2_H0_OM_OL_OK' current_column = 'x^2_%(H0)f_%(OM)f_%(OL)f_%(OK)f' % { 'H0': H0, 'OM': Om, 'OL': Ol, 'OK': Ok } full[current_column] = full.apply( lambda row: cosmol_x(row, 'z', 'dis_Ftab_err', cozmol), axis=1) full1[current_column] = full1.apply( lambda row: cosmol_x(row, 'redshift', 'dis_FTab_averr', cozmol), axis=1) full.loc['X_sum', current_column] = full[current_column].sum() full1.loc['X_sum', current_column] = full1[current_column].sum() return x_sum([full, full1], current_column)
def print_close_cosmo(): """Print cosmological functions for a close cosmology.""" H0 = 70. Om0 = 0.27 Ode0 = 0.7 cosmo = LambdaCDM(H0=H0, Om0=Om0, Ode0=Ode0) print('================') print('Close cosmology:') print('================') print('H0={} [km/s/Mpc], Om0={}, Ode0={}, Orel0={}, Ok0={}\n'.format( H0, Om0, Ode0, cosmo.Ogamma(0.) + cosmo.Onu(0.), cosmo.Ok(0.))) redshifts = (0., 0.1, 10., 1000.) print_curves(redshifts, cosmo)
def myloglike_H0(cube, ndim, nparams): H0 = cube[0] Om0 = cube[1] Ode0 = cube[2] cosmo = LambdaCDM(H0=H0, Om0=Om0, Ode0=Ode0) c = 299792458.0*1e-3 vr_mean, vr_std = redshift*c, redshift_error*c dc = cosmo.comoving_distance(redshift).value prob = np.log(kde_eval_single(kdedir_dist,[dc])[0]) if np.isnan(prob): prob = -np.inf return prob
def test_astropyify_ccl_cosmo(modeling_data): """ Unit tests for astropyify_ccl_cosmo """ # Make a bse object truth = {'H0': 70., 'Om0': 0.3, 'Ob0': 0.05} apycosmo_flcdm = FlatLambdaCDM(**truth) apycosmo_lcdm = LambdaCDM(Ode0=1.0-truth['Om0'], **truth) cclcosmo = {'Omega_c': truth['Om0']-truth['Ob0'], 'Omega_b': truth['Ob0'], 'h': truth['H0']/100., 'H0': truth['H0']}
def H0_to_theta(hubble, omega_nu, omnuh2, omega_m, ommh2, omega_c, omch2, omega_b, ombh2, omega_lambda, omlamh2): h = hubble / 100. if np.isnan(omnuh2): omnuh2 = omega_nu * h**2 if np.isnan(omega_m): omega_m = ommh2 / h**2 if np.isnan(omega_b): omega_b = ombh2 / h**2 if np.isnan(omega_lambda): omega_lambda = omlamh2 / h**2 if np.isnan(omega_c): omega_c = omch2 / h**2 if np.isnan(omega_m): omega_m = omega_c + omega_b + omega_nu if np.isnan(omega_m): omega_m = (omch2 + ombh2 + omnuh2) / h**2 if np.isnan([omnuh2, hubble, omega_m, omega_lambda, omega_b]).any(): return np.nan m_nu = 93.14 * omnuh2 * units.eV cosmo = LambdaCDM(hubble, omega_m, omega_lambda, m_nu=m_nu / 3, Ob0=omega_b, Tcmb0=2.7255, Neff=3.046) ombh2 = cosmo.Ob0 * cosmo.h**2 omdmh2 = cosmo.Om0 * cosmo.h**2 zstar = 1048 * (1 + 0.00124 * ombh2**(-0.738)) * ( 1 + (0.0783 * ombh2**(-0.238) / (1 + 39.5 * ombh2**0.763)) * (omdmh2 + ombh2)**(0.560 / (1 + 21.1 * ombh2**1.81))) astar = 1 / (1 + zstar) rs = scipy.integrate.romberg(dsound_da, 1e-8, astar, rtol=5e-5, args=(cosmo, ), divmax=10) # in Mpc DA = cosmo.angular_diameter_distance(zstar).to("Mpc").value / astar return rs / DA
def __init__(self, Om_L=0.68440, Om_b=0.04911, Om_c=0.26442, H0=67.27, Om_M=None, Om_k=None, **kwargs): """ Default parameter values are Planck 2015 TT,TE,EE+lowP. (Table 4 of https://doi.org/10.1051/0004-6361/201525830) Parameters: ----------- Om_L : float, Omega Lambda naught, default=0.68440 cosmological constant energy density fraction at z=0 Om_b : float, Omega baryon naught, default=0.04911 baryon energy density fraction at z=0 Om_c : float, Omega cold dark matter naught, default=0.26442 cdm energy density fraction at z=0 H0 : float, Hubble constant, default=67.31 km s-1 Mpc-1 Om_M : float, Omega matter naught, default=None [optional] matter energy density faction at z=0 Om_k : float, Omega curvature naught, default=None [optional] curvature energy density at z=0 """ # Setup parameters if Om_M is not None: if np.isclose(Om_b + Om_c, Om_M, atol=1e-5) is False: Om_b = Om_M * 0.156635 Om_c = Om_M * 0.843364 else: Om_M = Om_b + Om_c if Om_k is None: Om_k = 1 - Om_L - Om_M ### TODO add radiation component to class and to distance functions self.Om_L = Om_L self.Om_b = Om_b self.Om_c = Om_c self.Om_M = Om_M self.Om_k = Om_k self.H0 = H0 self.h = self.H0 / 100.0 self.params = ["Om_L", "Om_b", "Om_c", "Om_M", "Om_k", "H0"] if _astropy: self.lcdm = LambdaCDM(H0=self.H0, Om0=self.Om_M, Ode0=self.Om_L)
def test_dxdz(): # Default cosmology (Vanilla) Xz = cosm_xz(3.) np.isclose(Xz, 7.68841320742732) dxdz = cosm_xz(3., flg_return=1) np.isclose(dxdz, 3.5847294011983) # Open copen = LambdaCDM(H0=70., Om0=0.3, Ode0=0.) dxdz = cosm_xz(3., cosmo=copen, flg_return=1) np.isclose(dxdz, 2.90092902756)
def getHeader(self): header = Gadget2Header(ext._gadget2.getHeader(self.fp)) header["files"] = [self.fp.name] header["w0"] = -1.0 header["wa"] = 0.0 header["comoving_distance"] = LambdaCDM(H0=header["h"]*100,Om0=header["Om0"],Ode0=header["Ode0"]).comoving_distance(header["redshift"]).to(u.kpc).value * header["h"] return header
def __init__(self, r, M200=1.e14, ellip=0.25, z=0.2, h=0.7, misscentred=False, s_off=0.4, components=['t0', 't', 'tcos', 'xsin'], verbose=True, Yanmiss=False): """ init method, it sets up all variables """ if not isinstance(r, (np.ndarray)): r = np.array([r]) self.r = r self.M200 = M200 self.ellip = ellip self.z = z self.h = h self.misscentred = misscentred self.s_off = s_off self.components = components self.verbose = verbose self.Yanmiss = Yanmiss # Compute cosmological parameters self.cosmo = LambdaCDM(H0=self.h * 100, Om0=0.3, Ode0=0.7) # H at z_pair s-1 self.H = self.cosmo.H(self.z).value / (1.0e3 * self.pc) # critical density at z_pair (kg.m-3) self.roc = (3.0 * (self.H**2.0)) / (8.0 * np.pi * self.G) self.roc_mpc = self.roc * ((self.pc * 1.0e6)**3.0) # Compute R_200 self.R200 = profiles_fit.r200_nfw(self.M200, self.roc_mpc) # Scaling sigma_off self.s_off = self.s_off / self.h
M_g = m_r - DM - delta_g + g_r - z_cal return M_g ## Read in the fits file hdulist = pyfits.open('/hd0/Research/Clustering/Boss/dr11/dr11v2/cmass-dr11v2-N-Anderson.dat.fits') ## Uncomment the following line to view the info about the table #print hdulist.info() ## Read the tabular portion of the fits file into the variable 'table'. This assumes that the table of interest is located in extension 1 table = hdulist[1].data cosmo = LambdaCDM(H0=100, Om0=0.274, Ode0=0.726) ra=table.field('RA') dec=table.field('DEC') redshift=table.field('Z') fibcol=table.field('WEIGHT_CP') poly=table.field('IPOLY') sector=table.field('ISECT') extinction=table.field('EXTINCTION') extinction_r=extinction[:,3] flux=table.field('MODELFLUX') flux_r=flux[:,3] M_g=Calculate_Magnitude(flux_r,extinction_r,redshift) array=np.column_stack((ra,dec,redshift,fibcol,poly,M_g))
from astropy.cosmology import LambdaCDM import astropy.cosmology from astropy.io import fits import numpy as np import astropy.units as u """ created arrays of the Spectra IDs for relations between data sets EpA data set contained calculated ages of the galaxies """ cat_ID = cat['BESTOBJID'] EpA = fits.getdata('~/EpA_Results.fits') cosmo = LambdaCDM(H0=70, Om0=0.3, Ode0=0.7) """ two sections below for converting the age data to Z values and GYrs so that they could be plotted """ sb_age_list_gyr=[] sb_age_list_z = [] zrange = np.arange(0,1396) for i in zrange: age = cosmo.age(cat_z[i]) age_diff = age.value - (EpA['AGE'][i] / 1000) sb_age_list_gyr.append(age_diff * age.unit) if age_diff >= 0: sb_age_list_z.append(astropy.cosmology.z_at_value(cosmo.age, sb_age_list_gyr[i]))