def mk_mock_coords(radeczfile, outfile, simul_cosmo):

    if simul_cosmo == "Planck":
        Planck13.__init__(100.0, Planck13.Om0)
        cosmo = Planck13
    elif simul_cosmo == "WMAP":
        WMAP5.__init__(100.0, WMAP5.Om0)
        cosmo = WMAP5

    rad = np.arange(1.0, 67.0, 5.0)

    radecz = h5_arr(radeczfile, "radecz")

    cart = np.zeros(radecz.shape)

    for i, rdz in enumerate(radecz):

        ra = Angle(rdz[0], u.deg)
        dec = Angle(rdz[1], u.deg)

        losd = cosmo.comoving_distance(rdz[2])
        dis = Distance(losd)

        coord = ICRSCoordinates(ra, dec, distance=dis)

        cart[i, :] = np.array([coord.x.value, coord.y.value, coord.z.value])

    np.savetxt(outfile, cart)
Exemple #2
0
def mk_mock_coords(radeczfile, outfile, simul_cosmo):

    if simul_cosmo == "Planck":
        Planck13.__init__(100.0, Planck13.Om0)
        cosmo = Planck13
    elif simul_cosmo == "WMAP":
        WMAP5.__init__(100.0, WMAP5.Om0)
        cosmo = WMAP5

    rad = np.arange(1.0, 67.0, 5.0)

    radecz = h5_arr(radeczfile, "radecz")

    cart = np.zeros(radecz.shape)

    for i, rdz in enumerate(radecz):

        ra = Angle(rdz[0], u.deg)
        dec = Angle(rdz[1], u.deg)

        losd = cosmo.comoving_distance(rdz[2])
        dis = Distance(losd, u.Mpc)

        coord = ICRSCoordinates(ra, dec, distance=dis)

        cart[i, :] = np.array([coord.x, coord.y, coord.z])

    arr2h5(cart, outfile, "coords", mode='w')
def LumFunc(mr, name=None, mr_bin=None):
    ''' luminosity function 

    :param mr: 
        array of r-band luminosities
    :param name: 
        string specifying data set, which is used to get comoving volume in
        units of (Mpc/h)^3

    :return mr_bin_mid: 
        middle values of M_r bins 
    :return phi: 
        luminosity function (Mpc/h)^-3
    '''
    assert name is not None, "specify name for comoving volume"
    if mr_bin is None:
        mr_bin = np.linspace(-25., -20., 11)
    dmr = mr_bin[1:] - mr_bin[:-1]

    if name == 'sdss':  # volume of SDSS
        from astropy.cosmology import Planck13 as cosmo
        vol = (cosmo.comoving_volume(0.033390).value -
                cosmo.comoving_volume(0.01069).value) * \
                        (7966./41253.) * cosmo.h**3 # (Mpc/h)^3
    else:
        vol = {'simba': 100.**3, 'tng': 75.**3}[name]

    Ngal, _ = np.histogram(mr, bins=mr_bin)
    phi = Ngal.astype(float) / vol / dmr

    return 0.5 * (mr_bin[1:] + mr_bin[:-1]), phi
    def __init__(self, CE):

        self._base_dir = '/virgo/simulations/Hydrangea/10r200/CE-{:.0f}/'\
            'HYDRO/highlev/'.format(CE)
        self._propfile = path.join(self._base_dir, 'FullGalaxyTables.hdf5')
        self._posfile = path.join(self._base_dir, 'GalaxyPositionsSnap.hdf5')
        self._snepfile = path.join(self._base_dir, 'GalaxyPaths.hdf5')
        self._interp_file = path.join(self._base_dir,
                                      'GalaxyCoordinates10Myr.hdf5')
        with h5py.File(self._snepfile, 'r') as f:
            self.snep_redshifts = np.array([
                f['Snepshot_{:04d}'.format(sn_i)].attrs['Redshift'][0]
                for sn_i in f['RootIndex/Basic']
            ])
            self.snap_redshifts = np.array([
                f['Snepshot_{:04d}'.format(sn_i)].attrs['Redshift'][0]
                for sn_i in f['SnapshotIndex']
            ])
            self.snip_redshifts = np.array([
                f['Snepshot_{:04d}'.format(sn_i)].attrs['Redshift'][0]
                for sn_i in f['SnipshotIndex']
            ])
            self.snap_scales = 1 / (1 + self.snap_redshifts)
            self.snap_times = cosmo.age(self.snap_redshifts)
            self.snip_scales = 1 / (1 + self.snip_redshifts)
            self.snip_times = cosmo.age(self.snip_redshifts)
            self.snep_scales = 1 / (1 + self.snep_redshifts)
            self.snep_times = cosmo.age(self.snep_redshifts)
        self._data = dict()
        return
Exemple #5
0
    def __init__(self):
        """
        Container class to compute window functions due to resolution and volume effects. See for example https://arxiv.org/pdf/1907.10067.pdf

        """

        # Set constants
        self.fromHztoeV = 6.58e-16
        self.gramstoeV = 1 / (1.78 * 1e-33)
        self.mtoev = 1 / (1.97 * 1e-7)
        self.H0 = cosmo.H(0).value * 1e3 / (1e3 * const.kpc.value
                                            )  #expressed in 1/s
        self.rhocritical = cosmo.critical_density(0).value * self.gramstoeV / (
            1e-2)**3  # eV/m**3
        self.Om0 = cosmo.Om0  #total matter
        self.OLambda0 = cosmo.Ode0  # cosmological constant
        self.DM0 = self.Om0 - cosmo.Ob0  # dark matter
        self.evtonJoule = 1.60218 * 1e-10  # from eV to nJ
        self.evtoJoule = 1.60218 * 1e-19  # from eV to J
        self.h = 0.6766
        self.Mpc = 1e3 * const.kpc.value
        self.zmin = 0.001
        self.zmax = 30.001
        self.zbins = 301
        self.h = cosmo.h
def main():
    fil = pysysp.StarSpectrum()
    fil.setwavelength(np.arange(1000, 30000, 0.4))
    fil.setflux( 1e-15 * (fil.wavelength/10000.0)**(-1.5))
    i = pysysp.BandPass('/Users/jselsing/github/pysysp/pysysp/filters/ugriz/i.dat')


    dl = (cosmo.luminosity_distance(1.2)) * 1e5
    Mz0 = -5 * np.log10(dl.value) + fil.apmag(band=i, mag='AB')
    print('Mz0 = '+str(Mz0))


    i.wavelength /= (1 + 2)
    # fil.flux = fil.flux * (1 + 2)   

    i.update_bandpass()

    dl = (cosmo.luminosity_distance(1.2)) * 1e5
    Mz2 = -5 * np.log10(dl.value) + fil.apmag(band=i, mag='AB') #- 2.5 * np.log10(1 + 2)
    print('Mz2 = '+str(Mz2))




    # i.wavelength *= (1 + 2)

    # i.update_bandpass()

    # fil.wavelength = fil.wavelength * (1 + 2)
    # fil.flux = fil.flux / (1 + 2)
    # dl = (cosmo.luminosity_distance(1.2)) * 1e5
    # Mz2 = -5 * np.log10(dl.value) + fil.apmag(band=i, mag='AB')
    # print('Mz2 = '+str(Mz2))
    print('Mz0 - Mz2 = '+str(Mz0 - Mz2))
	def parse_input(self, ConfigFile):
		"""
		Parse the geom. parameters from the configuration file to the object

		Parameters
		----------
		ConfigFile : string
			path to the configuration file (filename)

		Self consistent calculations of the cosmological luminosity distance}
		and the angular diameter distance are also performed and added as
		attributes of the object

		"""

		run_config = configparser.SafeConfigParser({}, allow_no_value=True)
		run_config.read(ConfigFile)
		self.incl = run_config.getfloat('geometry','incl')
		self.pa = run_config.getfloat('geometry','pa')
		self.x0 = run_config.getfloat('geometry','x0')
		self.y0 = run_config.getfloat('geometry','y0')
		self.vsys = run_config.getfloat('geometry','Vsys')
		self.z = run_config.getfloat('geometry','z')
		self.dl = cosmo.luminosity_distance(self.z).to('Mpc').value
		# note that the following could have been computed from the angular
		# diameter distance as well, it is equivalent
		self.dtheta = cosmo.kpc_proper_per_arcmin(self.z).to('kpc / arcsec').value
def mk_coords(radecfile, outfile, cosmology):

    # Set the cosmology with h free
    if cosmology == "Planck":
        Planck13.__init__(100.0, Planck13.Om0)
        cosmo = Planck13
    elif cosmology == "WMAP":
        WMAP5.__init__(100.0, WMAP5.Om0)
        cosmo = WMAP5

    f_in = h5.File(radecfile)
    radecz = f_in["radecz"]

    f_out = h5.File(outfile)
    cart = f_out.create_dataset("cart_pts", shape=(radecz.shape[0], 3),
                                dtype='float64')

    for i in range(radecz.shape[0]):
        ra = Angle(radecz[i, 0], u.deg)
        dec = Angle(radecz[i, 1], u.deg)

        losd = cosmo.comoving_distance(radecz[i, 2])
        dis = Distance(losd)

        coord = ICRSCoordinates(ra, dec, distance=dis)

        cart[i, :] = np.array([coord.x, coord.y, coord.z])

    f_in.close()
    f_out.close()
Exemple #9
0
def getPhysical(z, radio_data):
    DAkpc = float(cosmo.angular_diameter_distance(z) /
                  u.kpc)  #angular diameter distance in kpc
    DLm = float(cosmo.luminosity_distance(z) / u.m)  #luminosity distance in m
    maxPhysicalExtentKpc = DAkpc * radio_data['radio'][
        'max_angular_extent'] * np.pi / 180 / 3600  #arcseconds to radians
    totalCrossSectionKpc2 = np.square(
        DAkpc) * radio_data['radio']['total_solid_angle'] * np.square(
            np.pi / 180 / 3600)  #arcseconds^2 to radians^2
    totalLuminosityWHz = radio_data['radio'][
        'total_flux'] * 1e-29 * 4 * np.pi * np.square(
            DLm)  #mJy to W/(m^2 Hz), kpc to m
    totalLuminosityErrWHz = radio_data['radio'][
        'total_flux_err'] * 1e-29 * 4 * np.pi * np.square(DLm)
    peakLuminosityErrWHz = radio_data['radio'][
        'peak_flux_err'] * 1e-29 * 4 * np.pi * np.square(DLm)
    for component in radio_data['radio']['components']:
        component['physical_extent'] = DAkpc * component[
            'angular_extent'] * np.pi / 180 / 3600
        component['cross_section'] = np.square(
            DAkpc) * component['solid_angle'] * np.square(np.pi / 180 / 3600)
        component['luminosity'] = component[
            'flux'] * 1e-29 * 4 * np.pi * np.square(DLm)
        component['luminosity_err'] = component[
            'flux_err'] * 1e-29 * 4 * np.pi * np.square(DLm)
    for peak in radio_data['radio']['peaks']:
        peak['luminosity'] = peak['flux'] * 1e-29 * 4 * np.pi * np.square(DLm)
    physical = {'max_physical_extent':maxPhysicalExtentKpc, 'total_cross_section':totalCrossSectionKpc2, \
       'total_luminosity':totalLuminosityWHz, 'total_luminosity_err':totalLuminosityErrWHz, \
       'peak_luminosity_err':peakLuminosityErrWHz}
    return physical
def mk_coords(radecfile, outfile, cosmology):

    # Set the cosmology with h free
    if cosmology == "Planck":
        Planck13.__init__(100.0, Planck13.Om0)
        cosmo = Planck13
    elif cosmology == "WMAP":
        WMAP5.__init__(100.0, WMAP5.Om0)
        cosmo = WMAP5

    f_in = h5.File(radecfile)
    radecz = f_in["radecz"]

    f_out = h5.File(outfile)
    cart = f_out.create_dataset("cart_pts",
                                shape=(radecz.shape[0], 3),
                                dtype='float64')

    for i in range(radecz.shape[0]):
        ra = Angle(radecz[i, 0], u.deg)
        dec = Angle(radecz[i, 1], u.deg)

        losd = cosmo.comoving_distance(radecz[i, 2])
        dis = Distance(losd)

        coord = ICRSCoordinates(ra, dec, distance=dis)

        cart[i, :] = np.array([coord.x, coord.y, coord.z])

    f_in.close()
    f_out.close()
Exemple #11
0
    def __init__(self):
        """
        Container class to compute the Cl due to high-z contributions; we first define the window functions 

        """

        # Set constants
        self.fromHztoeV = 6.58e-16
        self.gramstoeV = 1 / (1.78 * 1e-33)
        self.mtoev = 1 / (1.97 * 1e-7)
        self.H0 = cosmo.H(0).value * 1e3 / (1e3 * const.kpc.value
                                            )  #expressed in 1/s
        self.rhocritical = cosmo.critical_density(0).value * self.gramstoeV / (
            1e-2)**3  # eV/m**3
        self.Om0 = cosmo.Om0  #total matter
        self.OLambda0 = cosmo.Ode0  # cosmological constant
        self.DM0 = self.Om0 - cosmo.Ob0  # dark matter
        self.evtonJoule = 1.60218 * 1e-10  # from eV to nJ
        self.evtoJoule = 1.60218 * 1e-19  # from eV to J
        self.h = 0.6766
        PS1h = np.loadtxt(
            "/Users/andreacaputo/Desktop/Phd/AxionDecayCrossCorr/Codes/NIRB_PS/PS_DM_1h.dat"
        )
        PS2h = np.loadtxt(
            "/Users/andreacaputo/Desktop/Phd/AxionDecayCrossCorr/Codes/NIRB_PS/PS_DM_2h.dat"
        )
        self.Mpctometer = 3.086e+22  # from Mpc to meters
        self.Mpc = 1e3 * const.kpc.value
        self.zmin = 0.001
        self.zmax = 30.001
        self.zbins = 301
        self.h = cosmo.h
        self.TotPower = PS1h + PS2h
        self.z_vect = np.linspace(self.zmin, self.zmax, self.zbins)
        self.k_vect = PS1h[:, 0] * self.h
        self.Power = self.TotPower[:, 1:] / self.h**3
        self.Praw_prova = interp2d(self.k_vect, self.z_vect,
                                   np.transpose(self.Power))
        self.Msun = const.M_sun.value  #Kg
        self.Lsun = const.L_sun.value  # in W
        self.Sb = const.sigma_sb.value  # Stefan-Boltzmann constant in  W/m**2/K**4
        self.Rsun = const.R_sun.value  # in meters
        self.hplanck = const.h.value  # Js
        self.cc = const.c.value  #m/s
        self.kb = const.k_B.value  # kb constant J/K
        self.mp = const.m_p.value  # proton mass in Kg
        self.Hseconds = cosmo.H(0).value / (1e6 * u.parsec.to(u.km))  # in 1/s
        self.nHnebula = 1e4 / (
            1e-2)**3  # in m**-3, is also equal to the electron number density
        self.eVtoK = 1.16e4  # from eV to K
        self.year = 3.154e+7  # from year to seconds
        self.Ry = 1.1e7  #1/m Rydberg constant
        self.ergtoJoule = 1e-7  # from erg to Joule
        self.fromJouletoeV = 6.242e+18  # from Joule to eV
        self.Mpc = 1e3 * const.kpc.value
        self.RyK = 13.6057 * self.eVtoK
        self.Tgas = 3e4  # Kelvin, below Eq.9 in the paper, said to be used to calculate alphaB
        self.nuly = 2.4663495e15  # Lyman alpha frequency in Hz, which corresponds to a photon energy of
Exemple #12
0
def get_inv_efunc(cosmology):

    if cosmology == "Planck":
        Planck13.__init__(100.0, Planck13.Om0)
        cosmo = Planck13
    elif cosmology == "WMAP":
        WMAP5.__init__(100.0, WMAP5.Om0)
        cosmo = WMAP5

    return cosmo.inv_efunc
Exemple #13
0
def get_comv(cosmology):

    if cosmology == "Planck":
        Planck13.__init__(100.0, Planck13.Om0)
        cosmo = Planck13
    elif cosmology == "WMAP":
        WMAP5.__init__(100.0, WMAP5.Om0)
        cosmo = WMAP5

    return cosmo.comoving_distance
Exemple #14
0
def slice_z_cosmo(slice, z, radius):
    """Slices in redshift considering a distance to cut"""
    zmax = z_at_value(cosmo.comoving_distance, cosmo.comoving_distance(z) + radius)
    zmin = z_at_value(cosmo.comoving_distance, cosmo.comoving_distance(z) - radius)

    print zmin - zmax

    slice = slice[np.where(slice["zb_1"] < zmax)]
    slice = slice[np.where(slice["zb_1"] > zmin)]
    return slice
Exemple #15
0
def r200(z,M_200): ## unit: arcsec

	critical_density = Planck13.critical_density(z).si.value # unit: kg/m^3
	m2arcs = np.degrees(1.0/Planck13.angular_diameter_distance(z).si.value)*3600.
	critical_density  = critical_density*Planck13.H0/100./m2arcs**3/2e30 # unit: Msun/arcsec^3/h

	r200_cube = 200*critical_density/M_200/(4./3.*np.pi)
	r200 = r200_cube**(1./3.)

	return r200
Exemple #16
0
def r200(z, M_200):  ## unit: arcsec

    critical_density = Planck13.critical_density(z).si.value  # unit: kg/m^3
    m2arcs = np.degrees(
        1.0 / Planck13.angular_diameter_distance(z).si.value) * 3600.
    critical_density = critical_density * Planck13.H0 / 100. / m2arcs**3 / 2e30  # unit: Msun/arcsec^3/h

    r200_cube = 200 * critical_density / M_200 / (4. / 3. * np.pi)
    r200 = r200_cube**(1. / 3.)

    return r200.value
def mk_mock_srch(radecfile, nzdictfile, Nsph, simul_cosmo):

    if simul_cosmo == "Planck":
        # First make h free
        Planck13.__init__(100.0, Planck13.Om0)
        cosmo = Planck13
    elif simul_cosmo == "WMAP":
        WMAP5.__init__(100.0, WMAP5.Om0)
        cosmo = WMAP5
    comv = cosmo.comoving_distance

    radecarr = h5_arr(radecfile, "good_pts")
    nzdict = json.load(open(nzdictfile))

    Nrands = radecarr.shape[0]
    Narrs = Nsph / Nrands
    remain = Nsph % Nrands

    radecz = np.zeros((Nsph, 3))

    for i in range(Narrs):

        start = Nrands * i
        stop = Nrands * (i + 1)
        radecz[start:stop, :2] = radecarr[:, :]

    endchunk = Nrands * (Narrs)
    radecz[endchunk:, :2] = radecarr[:remain, :]

    rad = np.arange(1.0, 67.0, 5.0)
    zlo = nzdict["zlo"]
    zhi = nzdict["zhi"]

    radeczlist = len(rad) * [radecz]

    for r_i, r in enumerate(rad):

        dis_near = Distance(comv(zlo).value + r, u.Mpc)
        dis_far = Distance(comv(zhi).value - r, u.Mpc)

        z_a = dis_near.compute_z(cosmology=cosmo)

        z_b = dis_far.compute_z(cosmology=cosmo)

        randz = (z_a ** 3 + \
                 (z_b ** 3 - z_a ** 3) * np.random.rand(Nsph)) ** (1. / 3.)

        radeczlist[r_i][:, 2] = randz[:]

        arr2h5(
            radeczlist[r_i], "{0}/{1}/mocks/mock_srch_pts.hdf5".format(
                os.path.dirname(radecfile), simul_cosmo),
            "radecz_{0}".format(str(r_i * 5 + 1)))
def calc_ages(z, a_born):
    # Convert scale factor into redshift
    z_born = 1 / a_born - 1

    # Convert to time in Gyrs
    t = cosmo.age(z)
    t_born = cosmo.age(z_born)

    # Calculate the VR
    ages = (t - t_born).to(u.Myr)

    return ages.value
def M_to_sigma(M, z=0, mode='3D'):
    if mode == '3D':
        ndim_scale = np.sqrt(3)
    elif mode == '1D':
        ndim_scale = 1.
    # return prefac * .00989 * U.km / U.s \
    #     * np.power(M.to(U.Msun).value, 1 / 3)
    # Note: Delta_vir returns the overdensity in units of background,
    # which is Delta_c * Om in B&N98 notation.
    return 0.016742 * U.km * U.s**-1 * np.power(
        np.power(M.to(U.Msun).value, 2) * Delta_vir(z) / Delta_vir(0) *
        cosmo.Om(z) / cosmo.Om0 * np.power(cosmo.H(z) / cosmo.H0, 2),
        1 / 6) / ndim_scale
Exemple #20
0
def mk_mock_srch(radecfile, nzdictfile, Nsph, simul_cosmo):

    if simul_cosmo == "Planck":
        # First make h free
        Planck13.__init__(100.0, Planck13.Om0)
        cosmo = Planck13
    elif simul_cosmo == "WMAP":
        WMAP5.__init__(100.0, WMAP5.Om0)
        cosmo = WMAP5
    comv = cosmo.comoving_distance

    radecarr = h5_arr(radecfile, "good_pts")
    nzdict = json.load(open(nzdictfile))

    Nrands = radecarr.shape[0]
    Narrs = Nsph / Nrands
    remain = Nsph % Nrands

    radecz = np.zeros((Nsph, 3))

    for i in range(Narrs):

        start = Nrands * i
        stop = Nrands * (i + 1)
        radecz[start:stop, :2] = radecarr[:, :]

    endchunk = Nrands * (Narrs)
    radecz[endchunk:, :2] = radecarr[:remain, :]

    rad = np.arange(1.0, 67.0, 5.0)
    zlo = nzdict["zlo"]
    zhi = nzdict["zhi"]

    radeczlist = len(rad) * [radecz]

    for r_i, r in enumerate(rad):

        dis_near = Distance(comv(zlo) + r, u.Mpc)
        dis_far = Distance(comv(zhi) - r, u.Mpc)

        z_a = dis_near.compute_z(cosmology=cosmo)

        z_b = dis_far.compute_z(cosmology=cosmo)

        randz = (z_a ** 3 + \
                 (z_b ** 3 - z_a ** 3) * np.random.rand(Nsph)) ** (1. / 3.)

        radeczlist[r_i][:, 2] = randz[:]

        arr2h5(radeczlist[r_i], "{0}/{1}/mocks/mock_srch_pts.hdf5".format(os.path.dirname(radecfile), simul_cosmo), "radecz_{0}".format(str(r_i * 5 + 1)))
    def __init__(self):
        """
        Container class to compute various quantities for low-z Galaxy as studied here --> https://arxiv.org/pdf/1201.4398.pdf

        """

        # Set constants
        self.fromHztoeV = 6.58e-16
        self.gramstoeV = 1 / (1.78 * 1e-33)
        self.mtoev = 1 / (1.97 * 1e-7)
        self.H0 = cosmo.H(0).value * 1e3 / (1e3 * const.kpc.value
                                            )  #expressed in 1/s
        self.rhocritical = cosmo.critical_density(0).value * self.gramstoeV / (
            1e-2)**3  # eV/m**3
        self.Om0 = cosmo.Om0  #total matter
        self.OLambda0 = cosmo.Ode0  # cosmological constant
        self.DM0 = self.Om0 - cosmo.Ob0  # dark matter
        self.evtonJoule = 1.60218 * 1e-10  # from eV to nJ
        self.evtoJoule = 1.60218 * 1e-19  # from eV to J
        self.h = 0.6766
        self.Mpc = 1e3 * const.kpc.value
        self.zmin = 0.001
        self.zmax = 30.001
        self.zbins = 301
        self.h = cosmo.h
        self.lambda_eff = np.array([
            0.15, 0.36, 0.45, 0.55, 0.65, 0.79, 0.91, 1.27, 1.63, 2.20, 3.60,
            4.50
        ])
        self.Mstar0_vect = np.array([
            -19.62, -20.20, -21.35, -22.13, -22.40, -22.80, -22.86, -23.04,
            -23.41, -22.97, -22.40, -21.84
        ])
        self.q_vect = np.array(
            [1.1, 1.0, 0.6, 0.5, 0.5, 0.4, 0.4, 0.4, 0.5, 0.4, 0.2, 0.3])
        self.phistar0_vect = np.array([
            2.43, 5.46, 3.41, 2.42, 2.25, 2.05, 2.55, 2.21, 1.91, 2.74, 3.29,
            3.29
        ])
        self.p_vect = np.array(
            [0.2, 0.5, 0.4, 0.5, 0.5, 0.4, 0.4, 0.6, 0.8, 0.8, 0.8, 0.8])
        self.alpha0_vect = np.array(
            [-1., -1., -1., -1., -1., -1., -1., -1., -1., -1., -1., -1.])
        self.r_vect = np.array([
            0.086, 0.076, 0.055, 0.060, 0.070, 0.070, 0.060, 0.035, 0.035,
            0.035, 0.035, 0.035
        ])
        self.zmax_vect = np.array(
            [8.0, 4.5, 4.5, 3.6, 3.0, 3.0, 2.9, 3.2, 3.2, 3.8, 0.7, 0.7])
def mock_vpf(mock_cart_coords, spheresfile, simul_cosmo, rad):

    gals = h5_arr(mock_cart_coords, "coords")

    print gals

    name = mock_cart_coords.split("/")[-1].split(".")[0]

    if simul_cosmo == "Planck":
        # First make h free
        Planck13.__init__(100.0, Planck13.Om0)
        cosmo = Planck13
    elif simul_cosmo == "WMAP":
        WMAP5.__init__(100.0, WMAP5.Om0)
        cosmo = WMAP5
    comv = cosmo.comoving_distance

    gal_baum = cKDTree(gals)

    spheres = h5_arr(spheresfile, "radecz_{0}".format(str(int(rad))))

    print spheres

    for i, sphere in enumerate(spheres):

        rang = Angle(sphere[0], u.deg)
        decang = Angle(sphere[1], u.deg)

        dis = Distance(comv(sphere[2]), u.Mpc)

        coord = ICRSCoordinates(rang, decang, distance=dis)

        sph_cen = np.array([coord.x, coord.y, coord.z])

        nn = gal_baum.query(sph_cen)

        print "rad: ", rad, ", sphere: ", i

        f = open(
            "{0}/vpf_out/ascii/{1}_{2}.dat".format(
                os.path.dirname(spheresfile), name, str(int(rad))), 'a')

        if not nn[0] < rad:
            f.write("1\n")
        else:
            f.write("0\n")

        f.close()
Exemple #23
0
def read_data(fnm, desi=None, template=None, desi_dir=None):
	if desi_dir:
		wave_obs, flux_obs_in, flux_obs_err_in = spec_desi.parse_1D_spectra(desi_dir + fnm)
		redshift = spec_desi.get_redshift(desi_dir+fnm)
		flux_obs_in = flux_obs_in*1e-17*1e-7*1e4 #from 10-17 ergs/s/cm2/AA to W/AA/m^2
		flux_obs_err_in = flux_obs_err_in*1e-17*1e-7*1e4 #from 10-17 ergs/s/cm2/AA to W/AA/m^2
	if template:
		hdu = fits.open(spectradir + fnm)
		redshift = hdu[0].header['redshift']

		data = hdu[1].data
		wave_obs = np.array(data['wave'])
		flux_obs_in = np.array(data['flux_nodust_noise'])
		flux_obs_err_in = np.array(data['flux_nodust_noise_err']) #flux in W/AA/m^2

		wave_obs = wave_obs[flux_obs_in > 0]
		flux_obs_err_in = flux_obs_err_in[flux_obs_in > 0]
		flux_obs_in = flux_obs_in[flux_obs_in > 0]

	#shift to rest-frame
	wave_gal = wave_obs / (1.0 + redshift)

	dL = cosmo.luminosity_distance(redshift) #luminosity distance in meters
	dL = dL.to(u.m)

	#interpolate to models wavelength resolution - DO BETTER
	flux_obs = np.interp(wave, wave_gal, flux_obs_in) *  (4*np.pi*dL.value**2*(1+redshift)) #convert to luminosity in W/AA
	flux_obs_err = np.interp(wave, wave_gal, flux_obs_err_in) * (4*np.pi*dL.value**2*(1+redshift))

	return wave, flux_obs, flux_obs_err
Exemple #24
0
    def ClHighCooray(self, nuobs, l, T, fesc):  #zmin,zmax,N

        arrayz = np.logspace(np.log10(6), np.log10(30), 60)
        arraytoint = np.array([self.to_integrateCooray(nuobs,l/cosmo.comoving_distance(z).value,z, T,fesc)[0] \
                           for z in arrayz])

        return np.trapz(arraytoint, arrayz)  # (nW/m^2/sr)**2
Exemple #25
0
def get_catalog(df, weights=None, shear=False, lens=False, z_lens=None):
    """Return TreeCorr Catalog in Mpc."""
    if z_lens is None:
        raise ValueError('must enter a value for z_lens')
    else:
        dA_lens = cosmo.angular_diameter_distance(z_lens)
    if type(df) != pd.core.frame.DataFrame:
        raise TypeError('df must be a dataframe')

    if lens is True:
        cdf_zslice = df[np.isclose(df.z, z_lens)]
        x_lens_mpc = pix2rad(cdf_zslice['x[0]']) * dA_lens
        y_lens_mpc = pix2rad(cdf_zslice['x[1]']) * dA_lens
        cat = treecorr.Catalog(x=x_lens_mpc, y=y_lens_mpc)

    elif shear is True:
        # insert function to select on zphot & P(z) conditions
        # sdf_z = df[df.zphot > z_lens && 90% P(z) above z_lens]
        x_shear_mpc = pix2rad(df['x[0]']) * dA_lens  # tbr
        y_shear_mpc = pix2rad(df['x[1]']) * dA_lens  # tbr

        cat = treecorr.Catalog(x=x_shear_mpc, y=y_shear_mpc,
                               g1=df['e[0]'], g2=df['e[1]'])
    else:
        x_mpc = pix2rad(df['x[0]']) * dA_lens
        y_mpc = pix2rad(df['x[1]']) * dA_lens
        cat = treecorr.Catalog(x=x_mpc, y=y_mpc)

    if weights is not None:
        cat.k = np.ones(df.shape[0])
        for w in weights:
            cat.k *= df[w].values

    return cat
def get_redmapper(objID, ir, z, z_err, transverse, dz):
	'''
	Find the corresponding galaxy cluster in the redMaPPer catalog
	First check against member catalog, then check radially
	If multiple clusters match, choose the one with least angular separation
	'''
	
	# If the galaxy is too close, physical separations become too great on the sky
	# Restrict redshifts to at least 0.01
	if z < 0.01:
		return None
	
	member = rm_m.find_one({'ObjID':objID})
	if member is not None:
		return rm_c.find_one({'ID':member['ID']})
	
	# Maximum separation
	max_sep = float(transverse * u.Mpc / cosmo.angular_diameter_distance(z) * u.rad / u.deg)
	
	best_sep = np.inf
	cluster = None
	for temp_c in rm_c.find({'RAdeg':{'$gt':ir.ra.deg-max_sep, '$lt':ir.ra.deg+max_sep}, 'DEdeg':{'$gt':ir.dec.deg-max_sep, '$lt':ir.dec.deg+max_sep}, \
							 '$or':[{'zspec':{'$gt':z-dz, '$lt':z+dz}}, {'zlambda':{'$gt':z-dz, '$lt':z+dz}}]}):
		current_sep = ir.separation( coord.SkyCoord(temp_c['RAdeg'], temp_c['DEdeg'], unit=(u.deg,u.deg), frame='icrs') )
		if (current_sep < best_sep) and (current_sep < max_sep*u.deg):
			best_sep = current_sep
			cluster = temp_c
	
	return cluster
Exemple #27
0
def tab_L(X):
    m, a, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, z, d, lm = X

    sp.params['dust2'] = d
    sp.params['dust1'] = d
    sp.params['logzsol'] = np.log10(m)

    time, sfr, tmax = convert_sfh(agebins,
                                  [m1, m2, m3, m4, m5, m6, m7, m8, m9, m10])

    sp.set_tabular_sfh(time, sfr)

    wave, flux = sp.get_spectrum(tage=a, peraa=True)

    D_l = cosmo.luminosity_distance(z).value  # in Mpc

    mass_transform = (10**lm /
                      sp.stellar_mass) * lsol_to_fsol / (4 * np.pi *
                                                         (D_l * conv)**2)

    Gmfl, Pmfl = Full_forward_model(sim2, wave, flux * mass_transform, z)

    Gchi, Pchi = Full_fit(sim2, Gmfl, Pmfl)

    return -0.5 * (Gchi + Pchi)
Exemple #28
0
def producing_lensed_images(xi1, xi2, source_cat, lens_cat):

    xlc1 = lens_cat[0]
    xlc2 = lens_cat[1]
    ql = lens_cat[2]
    rlc = 0.0
    rle = re_sv(lens_cat[3], lens_cat[5],
                source_cat[7])  #Einstein radius of lens Arc Seconds.

    phl = lens_cat[4]
    #----------------------------------------------------------------------
    ai1, ai2, mua = lens_equation_sie(xi1, xi2, xlc1, xlc2, ql, rlc, rle, phl)

    yi1 = xi1 - ai1 * 0.0
    yi2 = xi2 - ai2 * 0.0

    ysc1 = source_cat[0]
    ysc2 = source_cat[1]
    mag_tot = source_cat[2]
    Reff_arc = np.sqrt(source_cat[3] * source_cat[4])
    qs = np.sqrt(source_cat[3] / source_cat[4])
    phs = source_cat[5]
    ndex = source_cat[6]
    zs = source_cat[7]

    #g_limage = sersic_SB_2D_tot(yi1,yi2,ysc1,ysc2,mag_tot,Reff_arc,qs,phs,zs)
    Da_s = p13.angular_diameter_distance(2.0).value
    Reff = Reff_arc * Da_s / apr * 1e6  # pc
    Ieff = sersic_mag_tot_to_Ieff(mag_tot, Reff, ndex, zs)
    g_limage = sersic_2d(yi1, yi2, ysc1, ysc2, Ieff, Reff_arc, qs, phs, ndex)

    return g_limage
Exemple #29
0
def tuple_to_sfh_stand_alone(sfh_tuple, zval):
    mass_quantiles = np.array([0., 0., 0.25, 0.5, 0.75, 1., 1., 1., 1., 1.])
    time_quantiles = np.array([
        0, 0.01, sfh_tuple[3], sfh_tuple[4], sfh_tuple[5], 0.96, 0.97, 0.98,
        0.99, 1
    ])

    time_arr_interp, mass_arr_interp = gp_interpolator(time_quantiles,
                                                       mass_quantiles,
                                                       Nparam=3)
    sfh_scale = 10**(sfh_tuple[0]) / (cosmo.age(zval).value * 1e9 / 1000)
    sfh = np.diff(mass_arr_interp) * sfh_scale
    sfh[sfh < 0] = 0
    sfh = np.insert(sfh, 0, [0])

    return sfh, time_arr_interp * cosmo.age(zval).value
def find_rvirial(dd, ds, center, start_rad = 0, delta_rad_coarse = 20, delta_rad_fine = 1, rad_units = 'kpc'):
    vir_check = 0
    r0 = ds.arr(start_rad, rad_units)
    critical_density = cosmo.critical_density(ds.current_redshift).value   #is in g/cm^3
    max_ndens_arr=center

    while True:
        r0_prev = r0
        r0 = r0_prev + ds.arr(delta_rad_coarse, rad_units)
        v_sphere = ds.sphere(max_ndens_arr, r0)
        dark_mass 	= v_sphere[('DarkMatter', 'Mass')].in_units('Msun').sum()	
        rho_internal = dark_mass.in_units('g')/((r0.in_units('cm'))**3.*(pi*4/3.))
        print rho_internal, r0, dark_mass
        if rho_internal < 200*ds.arr(critical_density,'g')/ds.arr(1.,'cm')**3.:
            #now run fine test
            print('\tNow running fine search on the virial radius')
            r0 = r0_prev
            while True:
                r0 += ds.arr(delta_rad_fine, rad_units)
                v_sphere = ds.sphere(max_ndens_arr, r0)
                dark_mass 	= v_sphere[('DarkMatter', 'Mass')].in_units('Msun').sum()	
                rho_internal = dark_mass.in_units('g')/((r0.in_units('cm'))**3.*(pi*4/3.))
                print rho_internal, r0
                if rho_internal < 200*ds.arr(critical_density,'g')/ds.arr(1.,'cm')**3.:
                    rvir = r0
                    print dark_mass.in_units('Msun'), rvir.in_units('kpc')
                    return rvir
def producing_lensed_images(xi1,xi2,source_cat,lens_cat):

    xlc1 = lens_cat[0]
    xlc2 = lens_cat[1]
    ql   = lens_cat[2]
    rlc  = 0.0
    rle  = re_sv(lens_cat[3],lens_cat[5],source_cat[7])       #Einstein radius of lens Arc Seconds.

    phl = lens_cat[4]
    #----------------------------------------------------------------------
    ai1,ai2,mua = lens_equation_sie(xi1,xi2,xlc1,xlc2,ql,rlc,rle,phl)

    yi1 = xi1-ai1*0.0
    yi2 = xi2-ai2*0.0

    ysc1 = source_cat[0]
    ysc2 = source_cat[1]
    mag_tot = source_cat[2]
    Reff_arc = np.sqrt(source_cat[3]*source_cat[4])
    qs   = np.sqrt(source_cat[3]/source_cat[4])
    phs  = source_cat[5]
    ndex = source_cat[6]
    zs = source_cat[7]

    #g_limage = sersic_SB_2D_tot(yi1,yi2,ysc1,ysc2,mag_tot,Reff_arc,qs,phs,zs)
    Da_s = p13.angular_diameter_distance(2.0).value
    Reff = Reff_arc*Da_s/apr*1e6 # pc
    Ieff = sersic_mag_tot_to_Ieff(mag_tot,Reff,ndex,zs)
    g_limage = sersic_2d(yi1,yi2,ysc1,ysc2,Ieff,Reff_arc,qs,phs,ndex)

    return g_limage
def luminosity(z, flux):
    from astropy.cosmology import Planck13 as cosmo
    #cosmo = {'omega_M_0':0.3, 'omega_lambda_0':0.7, 'omega_k_0':0.0, 'h':0.72}
    #d_lum= cd.luminosity_distance(z, **cosmo)*(3.08*10**24)
    d_lum = cosmo.luminosity_distance(z) * (3.08 * 10**24)
    L = 4 * pi * (d_lum**2) * flux
    return np.array(L.value, dtype=float)
Exemple #33
0
def lensed_sersic(xi1,xi2,source_cat,lens_cat):

    xlc1 = lens_cat[0]          # x position of the lens, arcseconds
    xlc2 = lens_cat[1]          # y position of the lens, arcseconds
    rlc  = 0.0                  # core size of Non-singular Isothermal Ellipsoid
    rle  = re_sv(lens_cat[2],lens_cat[5],source_cat[7])       #Einstein radius of lens, arcseconds.
    ql   = lens_cat[3]          # axis ratio b/a
    phl = lens_cat[4]           # orientation, degree
    #----------------------------------------------------------------------
    ai1,ai2,mua = lens_equation_sie(xi1,xi2,xlc1,xlc2,ql,rlc,rle,phl)

    yi1 = xi1-ai1
    yi2 = xi2-ai2

    ysc1 = source_cat[0]        # x position of the source, arcseconds
    ysc2 = source_cat[1]        # y position of the source, arcseconds
    mag_tot = source_cat[2]     # total magnitude of the source
    Reff_arc = source_cat[3]    # Effective Radius of the source, arcseconds
    qs   = source_cat[4]        # axis ratio of the source, b/a
    phs  = source_cat[5]        # orientation of the source, degree
    ndex = source_cat[6]        # index of the source
    zs = source_cat[7]          # redshift of the source

    Da_s = p13.angular_diameter_distance(zs).value
    Reff = Reff_arc*Da_s/apr*1e6 # pc
    Ieff = sersic_mag_tot_to_Ieff(mag_tot,Reff,ndex,zs) #L_sun/kpc^2
    g_limage = sersic_2d(yi1,yi2,ysc1,ysc2,Ieff,Reff_arc,qs,phs,ndex)
    g_source = sersic_2d(xi1,xi2,ysc1,ysc2,Ieff,Reff_arc,qs,phs,ndex)

    mag_lensed = mag_tot - np.log(np.sum(g_limage)/np.sum(g_source))

    return mag_lensed, g_limage
def vmax_profile(ds, DDname, center, start_rad=5, end_rad=220., delta_rad=5):

    rs = np.arange(start_rad, end_rad, delta_rad)
    r_arr = zeros(len(rs))
    m_arr = zeros(len(r_arr))

    for rr, r in enumerate(rs):
        print(rr, r)
        r0 = ds.arr(r, 'kpc')
        r_arr[rr] = r0
        critical_density = cosmo.critical_density(ds.current_redshift).value
        r0 = ds.arr(delta_rad, 'kpc')
        v_sphere = ds.sphere(center, r0)
        cell_mass, particle_mass = v_sphere.quantities.total_quantity(
            ["cell_mass", "particle_mass"])

        m_arr[rr] = cell_mass.in_units('Msun') + particle_mass.in_units('Msun')

    m_arr = yt.YTArray(m_arr, 'Msun')
    r_arr = yt.YTArray(r_arr, 'kpc')
    to_save = {}
    to_save['m'] = m_arr
    to_save['r'] = r_arr
    G = yt.YTArray([c.G.value], 'm**3/kg/s**2')
    to_save['v'] = sqrt(2 * G * m_arr / r_arr).to('km/s')

    np.save(
        '/nobackupp2/rcsimons/foggie_momentum/catalogs/vescape/%s_%s_vescape.npy'
        % (DDname, simname), to_save)
Exemple #35
0
def test_redshift_temperature():
    """Test :func:`astropy.cosmology.units.redshift_temperature`."""
    cosmo = Planck13.clone(Tcmb0=3 * u.K)
    default_cosmo = default_cosmology.get()
    z = 15 * cu.redshift
    Tcmb = cosmo.Tcmb(z)

    # 1) Default (without specifying the cosmology)
    with default_cosmology.set(cosmo):
        equivalency = cu.redshift_temperature()
        assert_quantity_allclose(z.to(u.K, equivalency), Tcmb)
        assert_quantity_allclose(Tcmb.to(cu.redshift, equivalency), z)

    # showing the answer changes if the cosmology changes
    # this test uses the default cosmology
    equivalency = cu.redshift_temperature()
    assert_quantity_allclose(z.to(u.K, equivalency), default_cosmo.Tcmb(z))
    assert default_cosmo.Tcmb(z) != Tcmb

    # 2) Specifying the cosmology
    equivalency = cu.redshift_temperature(cosmo)
    assert_quantity_allclose(z.to(u.K, equivalency), Tcmb)
    assert_quantity_allclose(Tcmb.to(cu.redshift, equivalency), z)

    # Test `atzkw`
    equivalency = cu.redshift_temperature(cosmo, ztol=1e-10)
    assert_quantity_allclose(Tcmb.to(cu.redshift, equivalency), z)
Exemple #36
0
def myFirefly_lgal_sourceSpec(galid, dust=False, lib='bc03', model='m11', model_lib='MILES', imf='kr'): 
    ''' run firefly on simulated source spectra from testGalIDs LGal
    '''
    # read in source spectra
    specin = lgal_sourceSpectra(galid, lib=lib)
    redshift = specin['meta']['REDSHIFT']
    print('z = %f' % redshift) 
    
    wave = specin['wave']
    wave_rest = wave / (1.+redshift) 
    if not dust: 
        flux = specin['flux_nodust_nonoise'] 

    # output firefly file 
    f_specin = f_Source(galid, lib=lib)
    if not dust: 
        f_firefly = ''.join([UT.dat_dir(), 'spectral_challenge/bgs/', 
            'myFirefly.', model, '.', model_lib, '.imf_', imf, '.nodust__', 
            f_specin.rsplit('/', 1)[1].rsplit('.fits', 1)[0], '.nodust.hdf5']) 

    ffly = Fitters.myFirefly(
            Planck13, # comsology
            model=model, 
            model_lib=model_lib, 
            imf=imf, 
            dust_corr=False,                            # no dust correction
            age_lim=[0., Planck13.age(redshift).value],     # can't have older populations
            logZ_lim=[-2.,1.])

    mask = ffly.emissionlineMask(wave_rest)
    ff_fit, ff_prop = ffly.Fit(wave, flux, flux*0.001, redshift, mask=mask, flux_unit=1e-17, f_output=f_firefly, silent=False)
    print ff_prop['logM_total'] 
    return None 
def sersic_mag_tot_to_Ieff(mag_tot,Reff,ndex,z,Rcut=100): # g band
    bn = 2.0*ndex-1/3.0+0.009876/ndex
    xtmp = bn*(Rcut)**(1.0/ndex)
    ktmp = 2.0*np.pi*ndex*(np.e**bn/(bn**(2.0*ndex)))*spf.gammainc(2.0*ndex,xtmp)*spf.gamma(2.0*ndex)
    Dl_s = p13.luminosity_distance(z).value*1e6

    Ieff = 10.0**((5.12-2.5*np.log10(ktmp)-5.0*np.log10(Reff)+5.0*np.log10(Dl_s/10)-mag_tot)*0.4) # L_sun/pc^2
    return Ieff
Exemple #38
0
 def test_fast_comoving_distance(self):
     z_params = {'z_start': 1.8, 'z_end': 3.7, 'z_step': 0.001}
     cd = comoving_distance.ComovingDistance(**z_params)
     ar_z = np.arange(1.952, 3.6, 0.132)
     ar_dist = cd.fast_comoving_distance(ar_z)
     ar_dist_reference = Planck13.comoving_transverse_distance(ar_z) / u.Mpc
     print(ar_dist - ar_dist_reference)
     self.assertTrue(np.allclose(ar_dist, ar_dist_reference))
def mock_vpf(mock_cart_coords, spheresfile, simul_cosmo, rad):

    gals = h5_arr(mock_cart_coords, "coords")

    print gals

    name = mock_cart_coords.split("/")[-1].split(".")[0]

    if simul_cosmo == "Planck":
        # First make h free
        Planck13.__init__(100.0, Planck13.Om0)
        cosmo = Planck13
    elif simul_cosmo == "WMAP":
        WMAP5.__init__(100.0, WMAP5.Om0)
        cosmo = WMAP5
    comv = cosmo.comoving_distance

    gal_baum = cKDTree(gals)

    spheres = h5_arr(spheresfile, "radecz_{0}".format(str(int(rad))))

    print spheres

    for i, sphere in enumerate(spheres):

        rang = Angle(sphere[0], u.deg)
        decang = Angle(sphere[1], u.deg)

        dis = Distance(comv(sphere[2]), u.Mpc)

        coord = ICRSCoordinates(rang, decang, distance=dis)

        sph_cen = np.array([coord.x, coord.y, coord.z])

        nn = gal_baum.query(sph_cen)

        print "rad: ", rad, ", sphere: ", i

        f = open("{0}/vpf_out/ascii/{1}_{2}.dat".format(os.path.dirname(spheresfile), name, str(int(rad))), 'a')

        if not nn[0] < rad:
            f.write("1\n")
        else:
            f.write("0\n")

        f.close()
Exemple #40
0
    def __init__(self, redshifts, cosmology='Planck13', cm='DuttonMaccio'):
        if type(redshifts) != np.ndarray:
            redshifts = np.array(redshifts)
        if redshifts.ndim != 1:
            raise ValueError("Input redshift array must have 1 dimension.")
        if np.sum(redshifts < 0.) > 0:
            raise ValueError("Redshifts cannot be negative.")

        if cosmology == 'Planck13':
            from astropy.cosmology import Planck13 as cosmo
        elif cosmology == 'WMAP9':
            from astropy.cosmology import WMAP9 as cosmo
        elif cosmology == 'WMAP7':
            from astropy.cosmology import WMAP7 as cosmo
        elif cosmology == 'WMAP5':
            from astropy.cosmology import WMAP5 as cosmo
        else:
            raise ValueError('Input cosmology must be one of: \
                              Planck13, WMAP9, WMAP7, WMAP5.')
        self._cosmo = cosmo

        if cm == 'DuttonMaccio':
            self._cm = 'DuttonMaccio'
        elif cm == 'Prada':
            self._cm = 'Prada'
        elif cm == 'Duffy':
            self._cm = 'Duffy'
        else:
            raise ValueError('Input concentration-mass relation must be \
                              one of: DuttonMaccio, Prada, Duffy.')

        self.describe = "Ensemble of galaxy clusters and their properties."
        self.number = redshifts.shape[0]
        self._z = redshifts
        self._rho_crit = cosmo.critical_density(self._z)
        self._massrich_norm = 2.7 * (10**13) * units.Msun
        self._massrich_slope = 1.4
        self._df = pd.DataFrame(self._z, columns=['z'])
        self._Dang_l = cosmo.angular_diameter_distance(self._z)
        self._m200 = None
        self._n200 = None
        self._r200 = None
        self._rs = None
        self._c200 = None
        self._deltac = None
Exemple #41
0
def mock_vpf(mock_cart_coords, spheresfile, simul_cosmo):

    gals = h5_arr(mock_cart_coords, "coords")
    name = mock_cart_coords.split("/")[-1].split(".")[0]

    if simul_cosmo == "Planck":
        # First make h free
        Planck13.__init__(100.0, Planck13.Om0)
        cosmo = Planck13
    elif simul_cosmo == "WMAP":
        WMAP5.__init__(100.0, WMAP5.Om0)
        cosmo = WMAP5
    comv = cosmo.comoving_distance

    gal_baum = cKDTree(gals)

    rad = np.arange(1.0, 67.0, 5.0)

    for r_i, r in enumerate(rad):

        spheres = h5_arr(spheresfile, "radecz_{0}".format(str(r_i * 5 + 1)))
        voids = np.zeros(spheres.shape[0])

        for i, sphere in enumerate(spheres):

            rang = Angle(sphere[0], u.deg)
            decang = Angle(sphere[1], u.deg)

            dis = Distance(comv(sphere[2]), u.Mpc)

            coord = ICRSCoordinates(rang, decang, distance=dis)

            sph_cen = np.array([coord.x.value, coord.y.value, coord.z.value])

            nn = gal_baum.query(sph_cen)

            print "rad: ", r, ", sphere: ", i

            if not nn[0] < r:

                voids[i] = 1

        arr2h5(voids,
                "{0}/vpf_out/{1}.hdf5".format(os.path.dirname(spheresfile), name),
                "voids_{0}".format(str(r_i * 5 + 1)))
Exemple #42
0
def bolometric(model, luminosity=True):
    phase = model.source._phase
    flux = np.sum(model.source.flux(phase, model.source._wave) * dwave, axis=1)
    if luminosity:
        z = model.get('z')
        dl = Planck13.luminosity_distance(z).to('cm').value
        L = 4 * np.pi * flux * dl * dl
        return L
    return flux
Exemple #43
0
 def JeansLength(self,z):
     """
     Computes Jeans length in unitless Delta z
     lambda_J=2.3 Mpc (1+z)^-3/2 Pshirkov 2016
     """
     dist=Planck13.lookback_distance(z).value # in Mpc
     jeanslength=2.3*(1+z)**(-1.5)              # in Mpc
     z1=z_at_value(Planck13.lookback_distance,(dist+jeanslength)*u.Mpc)
     return z1-z
Exemple #44
0
def luminosity_X(z, flux, gamma):
    #cosmo = {'omega_M_0':0.3, 'omega_lambda_0':0.7, 'omega_k_0':0.0, 'h':0.72}
    #d_lum= cd.luminosity_distance(z, **cosmo)*(3.08*10**24)
    d_lum = (cosmo.luminosity_distance(z) * (3.08 * 10**24)).value
    d_lum = np.array(d_lum)

    L = 4 * pi * (d_lum**2) * flux * (1 + z)**(gamma - 2)

    return L
def z_to_time(z,cosmology=None):
    """
    gives the time, in years, since the big bang given an astropy cosmology
    and a redshift.  if no cosmology passed in, assumes Planck13
    """
    if cosmology is None:
        from astropy.cosmology import Planck13 as cosmology
    from yt import YTArray
    t = cosmology.age(z)
    return YTArray(t*t.unit.in_units('yr'),'yr')
def sersic_SB_2D_tot(xi1,xi2,xc1,xc2,mag_tot,Reff_arc,ql,pha,z,ndex=4.0):

    #Dl_s = p13.luminosity_distance(z).value
    Da_s = p13.angular_diameter_distance(z).value
    Reff = Reff_arc*Da_s/apr*1e6
    mueff=sersic_mag_tot_to_mueff(mag_tot,Reff,ndex,z)
    bn = 2.0*ndex-1/3.0+0.009876/ndex
    (xi1new,xi2new) = xy_rotate(xi1, xi2, xc1, xc2, pha)
    R_arc = np.sqrt((xi1new**2)*ql+(xi2new**2)/ql)/Reff_arc
    res = mueff + (2.5*bn)/np.log(10.0)*((R_arc/Reff_arc)**(1.0/ndex)-1.0)
    return res
Exemple #47
0
def bolometric(model, luminosity=True, dl=None):
    phase = model.source._phase
    dwave = np.gradient(model.source._wave)
    flux = np.sum(model.source.flux(phase, model.source._wave) * dwave, axis=1)
    if luminosity:
        z = model.get('z')
        if dl is None:
            dl = Planck13.luminosity_distance(z).to('cm').value
        else:
            dl = (dl * u.Mpc).to('cm').value
        L = 4 * np.pi * flux * dl * dl
        return L
    return flux
Exemple #48
0
def get_densities(slice, large_slice):
    """Measures the density for each galaxy in the slice
    using a larger slice, because of borders effects from z
    (RA Dec not taken in accounts) and also to include all masses
    and not only the current mass bin"""

    radius = .5*u.Mpc

    densities = np.array([])
    meanmasses = np.array([])
    medianmasses = np.array([])

    print datetime.datetime.now()

    for galaxy in slice:
        z = galaxy["zb_1"]
        RA = galaxy["RA"]
        Dec = galaxy["Dec"]

        Mpc_per_deg = cosmo.kpc_comoving_per_arcmin(z).to(u.Mpc/u.deg)
        dRA = radius / Mpc_per_deg
        dDec = dRA

        slicetmp = large_slice

        slicetmp = slice_RA(slicetmp, RA, dRA)
        slicetmp = slice_Dec(slicetmp, Dec, dDec)
        #slicetmp = slice_z_cosmo(slicetmp, z, radius)
        velocity_limit = 500 #km/s

        #print zobs(-(velocity_limit), z) - zobs(velocity_limit, z)

        slicetmp = slice_z_minmax(slicetmp, zobs(-(velocity_limit), z), zobs(velocity_limit, z))

        meanmass_comp = np.mean(slicetmp["Stell_Mass_1"][np.where(slicetmp["ID"] != galaxy["ID"])])
        medianmass_comp = np.median(slicetmp["Stell_Mass_1"][np.where(slicetmp["ID"] != galaxy["ID"])])

        densities = np.append(densities, len(slicetmp)-1)
        meanmasses = np.append(meanmasses, meanmass_comp)
        medianmasses = np.append(medianmasses, medianmass_comp)

        #print len(slicetmp)-1

    slice.add_column(Column(data=densities, name="densities"))
    slice.add_column(Column(data=meanmasses, name="meanmasses"))
    slice.add_column(Column(data=medianmasses, name="medianmasses"))

    print datetime.datetime.now()

    return slice
def lens_img_cat(lens_cat):
    xlc1 = lens_cat[0]
    xlc2 = lens_cat[1]
    ql = lens_cat[2]
    sigmav = lens_cat[3]
    phl = lens_cat[4]
    zl = lens_cat[5]
    ndex = 4

    zl_array, sv_array, re_array, le_array=np.loadtxt("./apj512628t1_ascii.txt",comments='#', usecols=(0,1,2,3),unpack=True)
    Reff_r,Iebar_r = vd_matching(sigmav,sv_array, re_array, le_array)
    Ieff_r = sersic.sersic_Iebar_to_Ieff(Iebar_r,Reff_r,ndex)
    mag_tot = sersic.sersic_mag_in_Rcut(Ieff_r,Reff_r*1e3,ndex,zl)

    Da_l = p13.angular_diameter_distance(zl).value
    Reff_arc = Reff_r*0.001/Da_l*apr
    return [xlc1, xlc2, mag_tot, Reff_arc/np.sqrt(ql), Reff_arc*np.sqrt(ql), phl, ndex, zl, lens_cat[6]]
def lens_img_cat(lens_cat):
    xlc1 = lens_cat[0]
    xlc2 = lens_cat[1]
    ql = lens_cat[2]
    sigmav = lens_cat[3]
    phl = lens_cat[4]
    zl = lens_cat[5]

    zl_array, sv_array, re_array, le_array=np.loadtxt("./apj512628t1_ascii.txt",comments='#', usecols=(0,1,2,3),unpack=True)

    Reff_r,log10_Ieff_r = return_re_le(sigmav,sv_array, re_array, le_array)
    #Dl_l = p13.luminosity_distance(zl)
    Da_l = p13.angular_diameter_distance(zl).value
    Reff_arc = Reff_r/Da_l*apr*0.001 # arcsec
    Ieff_r = 10.0**(log10_Ieff_r) #/3.61 # http://www.astro.spbu.ru/staff/resh/Lectures/lec2.pdf
    ndex = 4
    mag_tot = sersic.sersic_mag_in_Rcut(Ieff_r,Reff_r,ndex)

    return [xlc1, xlc2, mag_tot, Reff_arc/np.sqrt(ql), Reff_arc*np.sqrt(ql), phl, ndex, zl]
def get_amf(ir, z, z_err, transverse, dz):
	'''
	Find the corresponding galaxy cluster in the WHL15 catalog
	If multiple clusters match, choose the one with least angular separation
	'''
	
	# If the galaxy is too close, physical separations become too great on the sky
	# Restrict redshifts to at least 0.01
	if z < 0.01:
		return None
	
	# Maximum separation
	max_sep = float(transverse * u.Mpc / cosmo.angular_diameter_distance(z) * u.rad / u.deg)
	
	best_sep = np.inf
	cluster = None
	for temp_c in amf.find({'ra':{'$gt':ir.ra.deg-max_sep, '$lt':ir.ra.deg+max_sep}, 'dec':{'$gt':ir.dec.deg-max_sep, '$lt':ir.dec.deg+max_sep}, \
							'z':{'$gt':z-dz, '$lt':z+dz}}):
		current_sep = ir.separation( coord.SkyCoord(temp_c['ra'], temp_c['dec'], unit=(u.deg,u.deg), frame='icrs') )
		if (current_sep < best_sep) and (current_sep < max_sep*u.deg):
			best_sep = current_sep
			cluster = temp_c
	
	return cluster
def single_run_test(ind,ysc1,ysc2,q,vd,pha,zl,zs):
    dsx_sdss     = 0.396         # pixel size of SDSS detector.
    R  = 3.0000     #
    nnn = 300      #Image dimension
    bsz = 9.0 # arcsecs
    dsx = bsz/nnn         # pixel size of SDSS detector.
    nstd = 59 #^2

    xx01 = np.linspace(-bsz/2.0,bsz/2.0,nnn)+0.5*dsx
    xx02 = np.linspace(-bsz/2.0,bsz/2.0,nnn)+0.5*dsx
    xi2,xi1 = np.meshgrid(xx01,xx02)
    #----------------------------------------------------------------------
    dsi = 0.03
    g_source = pyfits.getdata("./439.0_149.482739_1.889989_processed.fits")
    g_source = np.array(g_source,dtype="<d")*10.0
    g_source[g_source<=0.0001] = 1e-6
    #----------------------------------------------------------------------
    xc1 = 0.0       #x coordinate of the center of lens (in units of Einstein radius).
    xc2 = 0.0       #y coordinate of the center of lens (in units of Einstein radius).
    #q   = 0.7       #Ellipticity of lens.
    rc  = 0.0       #Core size of lens (in units of Einstein radius).
    re  = re_sv(vd,zl,zs)       #Einstein radius of lens.
    #pha = 45.0      #Orintation of lens.
    lpar = np.asarray([xc1,xc2,q,rc,re,pha])
    #----------------------------------------------------------------------
    ai1,ai2,mua = lens_equation_sie(xi1,xi2,lpar)

    yi1 = xi1-ai1
    yi2 = xi2-ai2

    g_limage = lv4.call_ray_tracing(g_source,xi1,xi2,ysc1,ysc2,dsi)
    g_limage[g_limage<=0.0001] = 1e-6
    g_limage = p2p.cosccd2mag(g_limage)
    g_limage = p2p.mag2sdssccd(g_limage)

    #-------------------------------------------------------------
    # Need to be Caliborate the mags
    dA = Planck13.comoving_distance(zl).value*1000./(1+zl)
    Re = dA*np.sin(R*np.pi/180./3600.)
    counts  =Brightness(Re,vd)
    vpar = np.asarray([counts,R,xc1,xc2,q,pha])
    #g_lens = deVaucouleurs(xi1,xi2,xc1,xc2,counts,R,1.0-q,pha)
    g_lens = de_vaucouleurs_2d(xi1,xi2,vpar)

    #pl.figure()
    #pl.contourf(g_lens)
    #pl.colorbar()

    g_clean_ccd1 = g_lens*0.0+g_limage
    g_clean_ccd2 = g_lens*1.0+g_limage
    from scipy.ndimage.filters import gaussian_filter
    pl.figure()
    pl.contourf(g_clean_ccd1)
    pl.colorbar()
    pl.savefig("/Users/uranus/GitHub/data_arc_finding_cnn/unlensed_output_pngs/"+str(i)+"_lensed_imgs_only.png")
    #-------------------------------------------------------------
    g_images_psf1 = gaussian_filter(g_clean_ccd1, 2.0)
    g_images_psf2 = gaussian_filter(g_clean_ccd2, 2.0)
    #g_images_psf = ss.convolve(g_clean_ccd,g_psf,mode="same")
    #g_images_psf = g_clean_ccd
    #-------------------------------------------------------------
    # Need to be Caliborate the mags
    g_noise = noise_map(nnn,nnn,np.sqrt(nstd),"Gaussian")
    #output_filename = "./output_fits/noise_map.fits"
    #pyfits.writeto(output_filename,g_noise,clobber=True)
    #-------------------------------------------------------------
    g_final1 = g_images_psf1+g_noise
    output_filename = "/Users/uranus/GitHub/data_arc_finding_cnn/unlensed_output_fits/"+str(i)+"_lensed_imgs_only.fits"
    pyfits.writeto(output_filename,g_final1,clobber=True)
    #-------------------------------------------------------------
    g_final2 = g_images_psf2+g_noise
    output_filename = "/Users/uranus/GitHub/data_arc_finding_cnn/unlensed_output_fits/"+str(i)+"_all_imgs.fits"
    pyfits.writeto(output_filename,g_final2,clobber=True)

    return 0
def single_run_test(ind, ysc1, ysc2, q, vd, pha, zl, zs, lens_tag=1):
    # dsx_sdss     = 0.396         # pixel size of SDSS detector.
    R = 3.0
    nnn = 400  # Image dimension
    bsz = 9.0  # arcsecs
    dsx = bsz / nnn         # pixel size of SDSS detector.
    nstd = 59  # ^2

    xi1, xi2 = make_r_coor(nnn, dsx)
# ----------------------------------------------------------------------
    dsi = 0.03
    g_source = pyfits.getdata(
        "./gals_sources/439.0_149.482739_1.889989_processed.fits")
    g_source = np.array(g_source, dtype="<d") * 10.0
    g_source[g_source <= 0.0001] = 1e-6
# ----------------------------------------------------------------------
    # x coordinate of the center of lens (in units of Einstein radius).
    xc1 = 0.0
    # y coordinate of the center of lens (in units of Einstein radius).
    xc2 = 0.0
    rc = 0.0  # Core size of lens (in units of Einstein radius).
    re = re_sv(vd, zl, zs)  # Einstein radius of lens.
    print "re = ", re
    re_sub = 0.0 * re
    a_sub = a_b_bh(re_sub, re)
    ext_shears = 0.06
    ext_angle = -0.39
    ext_kappa = 0.08

    # ext_shears = 0.0
    # ext_angle = 0.0
    # ext_kappa = 0.0

# ----------------------------------------------------------------------
    #lpar = np.asarray([xc1, xc2, q, rc, re, pha])
    #ai1, ai2, kappa_out, shr1, shr2, mua = lensing_signals_sie(xi1, xi2, lpar)
    #ar = np.sqrt(ai1 * ai1 + ai2 * ai2)

    # psi_nie = psk.potential_nie(xc1, xc2, pha, q, re, rc, ext_shears, ext_angle,
    #                            ext_kappa, xi1, xi2)
    #ai1, ai2 = np.gradient(psi_nie, dsx)

    ai1, ai2 = psk.deflection_nie(xc1, xc2, pha, q, re, rc, ext_shears, ext_angle,
                                  ext_kappa, xi1, xi2)

    as1, as2 = psk.deflection_sub_pJaffe(0.0, -2.169, re_sub, 0.0, a_sub, xi1, xi2)

    yi1 = xi1 - ai1 - as1
    yi2 = xi2 - ai2 - as2

    g_limage = lv4.call_ray_tracing(g_source, yi1, yi2, ysc1, ysc2, dsi)
    g_limage[g_limage <= 0.25] = 1e-6

    # pl.figure()
    # pl.contourf(g_limage)
    # pl.colorbar()

    g_limage = cosccd2mag(g_limage)
    g_limage = mag2sdssccd(g_limage)

    # pl.figure()
    # pl.contourf(g_limage)
    # pl.colorbar()
# -------------------------------------------------------------
    dA = Planck13.comoving_distance(zl).value * 1000. / (1.0 + zl)
    Re = dA * np.sin(R * np.pi / 180. / 3600.)
    counts = Brightness(Re, vd)
    vpar = np.asarray([counts, R, xc1, xc2, q, pha])
    g_lens = de_vaucouleurs_2d(xi1, xi2, vpar)

    g_clean_ccd = g_lens * lens_tag + g_limage
    output_filename = "./fits_outputs/clean_lensed_imgs.fits"
    pyfits.writeto(output_filename, g_clean_ccd, overwrite=True)
# -------------------------------------------------------------
    from scipy.ndimage.filters import gaussian_filter
    g_images_psf = gaussian_filter(g_clean_ccd, 2.0)
# -------------------------------------------------------------
    g_noise = noise_map(nnn, nnn, np.sqrt(nstd), "Gaussian")
    output_filename = "./fits_outputs/noise_map.fits"
    pyfits.writeto(output_filename, g_noise, overwrite=True)
    g_final = g_images_psf + g_noise
# -------------------------------------------------------------
    g_clean_ccd = g_limage
    g_images_psf = gaussian_filter(g_clean_ccd, 2.0)
    g_final = g_images_psf + g_noise
    output_filename = "./fits_outputs/lensed_imgs_only.fits"
    pyfits.writeto(output_filename, g_final, overwrite=True)
# -------------------------------------------------------------
    output_filename = "./fits_outputs/full_lensed_imgs.fits"
    pyfits.writeto(output_filename, g_final + g_lens, overwrite=True)

    # pl.figure()
    # pl.contourf(g_final)
    # pl.colorbar()

    return 0
def single_run_test(ind,ysc1,ysc2,q,vd,pha,zl,zs):
    dsx_sdss     = 0.396         # pixel size of SDSS detector.
    R  = 3.0000     #
    #zl = 0.2     #zl is the redshift of the lens galaxy.
    #zs = 1.0
    #vd = 520    #Velocity Dispersion.
    nnn = 128      #Image dimension
    bsz = dsx_sdss*nnn # arcsecs
    dsx = bsz/nnn         # pixel size of SDSS detector.
    nstd = 59 #^2

    xx01 = np.linspace(-bsz/2.0,bsz/2.0,nnn)+0.5*dsx
    xx02 = np.linspace(-bsz/2.0,bsz/2.0,nnn)+0.5*dsx
    xi2,xi1 = np.meshgrid(xx01,xx02)
    #----------------------------------------------------------------------
    #ysc1 = 0.2
    #ysc2 = 0.5
    dsi = 0.03
    g_source = pyfits.getdata("./439.0_149.482739_1.889989_processed.fits")
    g_source = np.array(g_source,dtype="<d")*10.0
    g_source[g_source<=0.0001] = 1e-6
    #print np.sum(g_source)
    #print np.max(g_source)
    #pl.figure()
    #pl.contourf(g_source)
    #pl.colorbar()
    #g_source = p2p.cosccd2mag(g_source)
    ##g_source = p2p.mag2sdssccd(g_source)
    ##print np.max(g_source*13*13*52.0)
    #pl.figure()
    #pl.contourf(g_source)
    #pl.colorbar()
    #----------------------------------------------------------------------
    xc1 = 0.0       #x coordinate of the center of lens (in units of Einstein radius).
    xc2 = 0.0       #y coordinate of the center of lens (in units of Einstein radius).
    #q   = 0.7       #Ellipticity of lens.
    rc  = 0.0       #Core size of lens (in units of Einstein radius).
    re  = re_sv(vd,zl,zs)       #Einstein radius of lens.
    #pha = 45.0      #Orintation of lens.
    lpar = np.asarray([xc1,xc2,q,rc,re,pha])
    #----------------------------------------------------------------------
    ai1,ai2,mua = lens_equation_sie(xi1,xi2,lpar)

    yi1 = xi1-ai1
    yi2 = xi2-ai2

    g_limage = lv4.call_ray_tracing(g_source,yi1,yi2,ysc1,ysc2,dsi)
    g_limage[g_limage<=0.0001] = 1e-6
    g_limage = p2p.cosccd2mag(g_limage)
    g_limage = p2p.mag2sdssccd(g_limage)

    #pl.figure()
    #pl.imshow((g_limage),interpolation='lanczos',cmap=cm.gray)
    #pl.colorbar()

    #-------------------------------------------------------------
    # Need to be Caliborate the mags
    dA = Planck13.comoving_distance(zl).value*1000./(1+zl)
    Re = dA*np.sin(R*np.pi/180./3600.)
    counts  =Brightness(Re,vd)
    vpar = np.asarray([counts,R,xc1,xc2,q,pha])
    #g_lens = deVaucouleurs(xi1,xi2,xc1,xc2,counts,R,1.0-q,pha)
    g_lens = de_vaucouleurs_2d(xi1,xi2,vpar)

    #pl.figure()
    #pl.imshow((g_lens),interpolation='nearest',cmap=cm.gray)
    #pl.colorbar()

    g_clean_ccd = g_lens+g_limage

    #pl.figure()
    #pl.imshow((g_clean_ccd),interpolation='nearest',cmap=cm.gray)
    #pl.colorbar()

    g_clean_ccd = congrid.congrid(g_clean_ccd,[128,128])

    #-------------------------------------------------------------
    file_psf = "../PSF_and_noise/sdsspsf.fits"
    g_psf = pyfits.getdata(file_psf)-1000.0
    g_psf = g_psf/np.sum(g_psf)

    #new_shape=[0,0]
    #new_shape[0]=np.shape(g_psf)[0]*dsx_sdss/dsx
    #new_shape[1]=np.shape(g_psf)[1]*dsx_sdss/dsx
    #g_psf = rebin_psf(g_psf,new_shape)

    g_images_psf = ss.fftconvolve(g_clean_ccd,g_psf,mode="same")
    #g_images_psf = ss.convolve(g_clean_ccd,g_psf,mode="same")
    #g_images_psf = g_clean_ccd

    #pl.figure()
    #pl.imshow((g_psf),interpolation='nearest',cmap=cm.gray)
    #pl.colorbar()

    #-------------------------------------------------------------
    # Need to be Caliborate the mags
    #g_noise = noise_map(nnn,nnn,np.sqrt(nstd),"Gaussian")
    g_noise = noise_map(128,128,np.sqrt(nstd),"Gaussian")
    g_final = g_images_psf+g_noise

    #pl.figure()
    #pl.imshow((g_final.T),interpolation='nearest',cmap=cm.gray)
    #pl.colorbar()

    g_final_rebin = congrid.congrid(g_final,[128,128])

    #pl.figure()
    #pl.imshow((g_final_rebin.T),interpolation='nearest',cmap=cm.gray)
    #pl.colorbar()

    #-------------------------------------------------------------

    output_filename = "../output_fits/"+str(ind)+".fits"
    pyfits.writeto(output_filename,g_final_rebin,clobber=True)

    pl.show()

    return 0
Exemple #55
0
from astropy.constants import c as speed_of_light



# prefix, target = 'M2FS16', 'A04'
# outfile = os.path.abspath(os.path.join(os.curdir,'..','..', 'OneDrive - umich.edu','Research','M2FSReductions','catalogs','merged_target_lists', 'mtlz_{}_{}_full.fits'.format(prefix,target)))
prefix, target = 'M2FS17', 'B09'
outfile = os.path.abspath(os.path.join(os.curdir,'..','data','catalogs','merged_target_lists', 'mtlz_{}_{}_full.fits'.format(prefix,target)))


complete_table = Table.read(outfile,format='fits')

ra_clust = float(complete_table.meta['RA_TARG'])
dec_clust= float(complete_table.meta['DEC_TARG'])
z_clust  = float(complete_table.meta['Z_TARG'])
kpc_p_amin = Planck13.kpc_comoving_per_arcmin(z_clust)
cluster = SkyCoord(ra=ra_clust*u.deg,dec=dec_clust*u.deg)
scalar_c = consts.c.to(u.km/u.s).value

measured_table = complete_table[np.bitwise_not(complete_table['SDSS_only'])]

corcut = 0.3

spec_overlap = measured_table[np.logical_not(measured_table['sdss_zsp'].mask)]
spec_overlap = spec_overlap[((spec_overlap['cor']>corcut))]
if len(spec_overlap)==0:
    raise(TypeError,"There were no overlapping spectra and SDSS")
blue_cam = np.array([fib[0]=='b' for fib in spec_overlap['FIBNAME']])
red_cam = np.bitwise_not(blue_cam)

plt.figure()
Exemple #56
0
#Find the RA, DEC, Z
#galra=galdat.RA[:100]
#galdec=galdat.DEC[:100]
#galz=galdat.Z[:100]

cutra=cutdat.RA
cutdec=cutdat.DEC
cutz=cutdat.Z
randra=randat.RA
randdec=randat.DEC
randz=randat.Z


#Convert redshift to Mpc (Using Planck Results stored in astropy.cosmology)
#comoving=Planck13.comoving_distance(galz)
cutX=Planck13.comoving_distance(cutz)
randX=Planck13.comoving_distance(randz)
end2=time.time()
print end2-start, 'Comoving distances calculated'

'''
#From working cosmology code
def Horizon(x, t, Om, Og, Ol, Ok):
	F=(x**-2)*(Om/x**3+Og/x**4+Ol+Ok/x**2)**-0.5
	return F
Om=0.307
Og=0
Ol=0.693
Ok=1-(Om+Og+Ol)
t=linspace(0,1,100000)
DA=[]