def disterr(self): """ Distance error (given WMAP7 cosmology/H0) """ from astropy.cosmology import WMAP7 dist = WMAP7.luminosity_distance(self.zdist) dp = abs(dist - WMAP7.luminosity_distance(self.zdist + self.zdisterr)) dm = abs(dist - WMAP7.luminosity_distance(self.zdist - self.zdisterr)) return (dp + dm) / 2
def dist(self): """ Distance to host (given WMAP7 cosmology/H0) """ from astropy.cosmology import WMAP7 return WMAP7.luminosity_distance(self.zdist)
def getAbsMag(self, z, appmag, Lbol, Filter): # Calculate value of fractions in K-correction tempflux, zeroflux = self.getFluxes(z, Lbol, Filter)[2:] frac1 = 10**(-0.4*appmag) frac2 = zeroflux/tempflux # Calculate K-correction KQR = -2.5 * np.log10(frac1*frac2) # Calculate distance modulus DLpc = WMAP7.luminosity_distance(z).to_value(u.pc) DM = 5 * np.log10(0.1 * DLpc) # Calculate apparent magnitude based on the apparent-absolute magnitude relationship absMag = appmag - DM - KQR return absMag
def getFluxes(self, z, Lbol, Filter): # Redshift to object's z DLcm = WMAP7.luminosity_distance(z).to_value(u.cm) waveZ = self.QSOtemp['Wave']*(1.+z) filtZ = np.interp(waveZ, Filter['lambda'], Filter['trans']) # Normalise spectral densities L5100 = Lbol / (9.*5100.) lum = L5100 * self.QSOtemp['FluxD']/self.QSOtemp['FluxD'][4300] flux = lum / (4*np.pi*DLcm*DLcm * (1.+z)) # Compute flux through filter tempflux = igrt.trapz(waveZ * flux * filtZ, x=waveZ) zeroflux = igrt.trapz(self.c/waveZ * self.AB * filtZ, x=waveZ) return waveZ, lum, tempflux, zeroflux
def getQSOmag(self, Lbol, z, Filter): # Return apparent magnitude of QSO at redshift z in filter # Redshift the QSO to z waveZ = self.QSOTemplate['Wave'] * (1.0+z) # Normalise spectrum from relative to absolute flux units # Index 4300 is 5100.5 Angstroms L5100 = Lbol/(5100.0*9.0) lumZ = self.QSOTemplate['FluxD'] * L5100 / self.QSOTemplate['FluxD'][4300] # Calculate fluxes based on luminosity distance DL in cm DL = WMAP7.luminosity_distance(z) * 1.0e6 * 3.0857e18 # cm fluxZ = lumZ / (4*np.pi*DL.value**2) # ergs/s/cm^2 # Convolve with Filter and report flux in AB mag return self.QSOConv(waveZ, fluxZ, Filter)
def _init_code(self): """Compute the age of the Universe at a given redshift """ self.redshift = float(self.parameters["redshift"]) # Raise an error when applying a negative redshift. This module is # not for blue-shifting. if self.redshift < 0.: raise Exception("The redshift provided is negative <{}>." .format(self.redshift)) self.universe_age = cosmology.age(self.redshift).value * 1000. if self.redshift == 0.: self.luminosity_distance = 10. * parsec else: self.luminosity_distance = ( cosmology.luminosity_distance(self.redshift).value * 1e6 * parsec) # We do not define the values of the IGM attenuation component yet. # This is because we need the wavelength grid for that first. This # will be assigned on the first call. self.igm_attenuation = {}
import numpy as np import matplotlib.pyplot as plt import matplotlib.colors as clr import h5py import dtk import sys from astropy.cosmology import WMAP7 as cosmo import time from scipy.interpolate import interp1d h = 0.702 stepz = dtk.StepZ(200, 0, 500) zs = np.linspace(0, 1.5, 1000) z_to_dl = interp1d(zs, cosmo.luminosity_distance(zs)) step2nan_str_z = {} param = dtk.Param(sys.argv[1]) output = param.get_string('output') output_mod = output.replace('.hdf5', '_mod.hdf5') hfile = h5py.File(output_mod, 'a') redshift = hfile['galaxyProperties/redshiftHubble'].value dl = z_to_dl(redshift) print "done getting the luminosity distance..." adjust = -2.5 * np.log10(1 + redshift) + 5 * np.log10(dl) + 25.0 def recal_obs(hgroup):
def dLum(z): return cosmo.luminosity_distance(z).value * h #in Mpc/h
g = np.array(f[ch[1] + p]) b = np.array(f[ch[2] + p]) if plot: print('Origional') print(np.max(np.dstack((r, g, b)))) plt.imshow( np.dstack( (r[96:160, 96:160] / np.max(r[96:160, 96:160]), g[96:160, 96:160] / np.max(g[96:160, 96:160]), b[96:160, 96:160] / np.max(b[96:160, 96:160])))) plt.show() print('Pixel size of', round(px, 3), ' arcsec at z =', table[z_col][rand_idx]) #correct brightness for distance d_redsh = cosmo.luminosity_distance( table[z_col][rand_idx]).value r *= (d_eagle * d_eagle) / (d_redsh * d_redsh) g *= (d_eagle * d_eagle) / (d_redsh * d_redsh) b *= (d_eagle * d_eagle) / (d_redsh * d_redsh) #Convert from maggies to mJy (do now to prevent overflow) r *= 3.631e6 g *= 3.631e6 b *= 3.631e6 #Scale to match g-band observations r *= scale g *= scale b *= scale else: r = np.array(f[ch[0] + p]) #Load data g = np.array(f[ch[1] + p]) b = np.array(f[ch[2] + p])
from astropy.cosmology import WMAP7 as cosmo from astroML.stats import binned_statistic_2d import matplotlib as mpl plt.rc('xtick', labelsize=16) plt.rc('ytick', labelsize=16) plt.rc('xtick', direction='inout') plt.rc('ytick', direction='inout') plt.rc('axes', linewidth=1.5) plt.rc('font', family='sans-serif') plt.rc('font', size=16) f1 = fits.open( '/Users/jarmijo/Documents/Mocks/mocks_MBlue_SDSSphot_mi23cut.fits') data1 = f1[1].data dL = cosmo.luminosity_distance(data1['Z']) Ns = 9 zmin = 0.11 zmax = 0.9 M_min = -16. M_max = -23.5 b = 30 #N of bins LF dM = abs(M_max - M_min) / b zbins = np.linspace(0.11, 0.9, Ns, endpoint=True) # ============================================================================= # f,ax = plt.subplots(1,1,figsize=(7,6)) # ax.hist(data1['M_I'],bins=b,color='r',histtype='step',label='Mock') # ax.set_yscale('log') # ax.vlines(M_min,1,len(data1['M_I']),linestyles='--',colors='k')
F_in[c] *= ((dx2 - abs(Ix[c] - xi)) / dx) elif (0 < (xi - Ix[c]) < dx2): F_in[c] *= ((dx2 + abs(Ix[c] - xi)) / dx) if c == len(Ix) - 1: if (0 < (xf - Ix[c]) < dx2): F_in[c] *= ((dx2 - abs(Ix[c] - xf)) / dx) elif (0 < (Ix[c] - xf) < dx2): F_in[c] *= ((dx2 + abs(Ix[c] - xf)) / dx) P_B.append(np.sum(F_in * dx) / dx0) PB = np.array(P_B) PAUS_BLUE = PB[(table[:, 2] < 0.9) & (table[:, 2] > 0.11)] new_table = table[(table[:, 2] < 0.9) & (table[:, 2] > 0.11)] mB = -2.5 * np.log10( PAUS_BLUE ) - 48 # from flux to PAUS magnitud e dL = cosmo.luminosity_distance(new_table[:, 2]).value * cosmo.h MB = mB - 25 - 5 * np.log10(dL) new_table = np.vstack([new_table.T, MB]).T t = Table( new_table, names=[ 'RA', 'DEC', 'Z', 'SDSS_g', 'SDSS_i', 'SDSS_r', 'SDSS_u', 'SDSS_G', 'SDSS_I', 'SDSS_R', 'SDSS_U', 'SFR Mdot', 'MB' ], ) print "saving data from " + str(len(MB)) + " of " + str( i ) + "galaxies in fits format... at /cosma/home/durham/jarmijo/PAU_test/catalogs/mocks_MBlue_SDSSphot.fits\n" t.write( '/cosma/home/dp004/dc-armi2/PAU_test/catalogs/mocks_radecz_MIMB_SFRHaplha_' + icut + 'cut.fits',