def lens_weight_nofz2(z_l1, z_l2, nofz_s, cosmo): """ It calculates the mean lensing kernel given nofz of lens and source bin. """ nofz_s = nofz_s / np.sum(nofz_s) z_subbins = np.linspace(0, 1.8, 200) nofz_l = np.ones(200) * 1.0 mask = (z_subbins <= z_l1) | (z_subbins > z_l2) nofz_l[mask] = 0 nofz_l = nofz_l / np.sum(nofz_l) dz_cd = cd.comoving_distance( z_subbins[1:], **cosmo) - cd.comoving_distance(z_subbins[:-1], **cosmo) w = 0 for i in range(200 - 1): # try other way around mask = (z_subbins > z_subbins[i]) if len(z_subbins[mask]) > 1: w += np.sum( w_kernel2(z_subbins[i], z_subbins[mask], cosmo) * nofz_s[mask] * dz_cd[mask[1:]]) * cd.comoving_distance( z_subbins[i], ** cosmo) * nofz_l[i] / (1.0 / (1 + z_subbins[i])) * dz_cd[i] return w
def find_dist_correlation_lines(meanZ,l1,l2): ''' ''' verbose = False ### Cosmology cosmo = {'omega_M_0':omegaM0__, 'omega_lambda_0':omegaLambda0__, 'omega_k_0':0., 'h':h__} lObs = (2.*meanZ+2.)/(1./l1+1./l2) z1 = lObs/l1-1. z2 = lObs/l2-1. if (verbose): print if (verbose): print ' z1 = ', z1 if (verbose): print ' z2 = ', z2 d1 = cosmology.comoving_distance(z1, **cosmo)*h__ d2 = cosmology.comoving_distance(z2, **cosmo)*h__ if (verbose): print if (verbose): print ' d1 = ',d1 if (verbose): print ' d2 = ',d2 return d1-d2
def w_kernel(z_l, z_s, cosmo): """ [script from Arnau] It defines the lensing kernel for a given comoving distance of lens and source. """ a = 1.0 / (1 + z_l) cd_l = cd.comoving_distance(z_l, **cosmo) cd_s = cd.comoving_distance(z_s, **cosmo) return ((cd_l * (cd_s - cd_l) / cd_s)) / a
def find_range_QSO_redshift(): ''' ''' verbose = False ### range of the correlation maxX__ = 200. ### Cosmology cosmo = {'omega_M_0':omegaM0__, 'omega_lambda_0':omegaLambda0__, 'omega_k_0':0., 'h':h__} ### Distance max of correlation dist_max = maxX__*numpy.sqrt(2.)/h__ if (verbose): print ' dist_max = ', dist_max z_pixel_min = (lambdaObsMin__/lambdaRFLine__)-1. z_pixel_max = (lambdaObsMax__/lambdaRFLine__)-1. if (verbose): print if (verbose): print ' z_pixel_min = ', z_pixel_min if (verbose): print ' z_pixel_max = ', z_pixel_max d_pixel_min = cosmology.comoving_distance(z_pixel_min, **cosmo) d_pixel_max = cosmology.comoving_distance(z_pixel_max, **cosmo) if (verbose): print if (verbose): print ' d_pixel_min = ', d_pixel_min if (verbose): print ' d_pixel_max = ', d_pixel_max d_QSO_min = d_pixel_min-dist_max d_QSO_max = d_pixel_max+dist_max if (verbose): print if (verbose): print ' d_QSO_min = ', d_QSO_min if (verbose): print ' d_QSO_max = ', d_QSO_max distfunc, redfunc = cosmology.quick_distance_function(cosmology.comoving_distance, zmax=20.0, zmin=0.0, zstep=0.001, return_inverse=True, **cosmo) d1 = distfunc(z_pixel_min) d2 = distfunc(z_pixel_max) if (verbose): print '\n',d1, d2 z_QSO_min = redfunc(d_QSO_min) z_QSO_max = redfunc(d_QSO_max) if (verbose): print if (verbose): print ' z_QSO_min = ', z_QSO_min if (verbose): print ' z_QSO_max = ', z_QSO_max return z_QSO_min,z_QSO_max
def kappag_map_bin(N2d, mask, fraction, z_l1, z_l2, z_s, cosmo, smooth_kernal, smooth_scale): """ Calculate kappa_g map for a lens redshift bin from z_l1 to z_l2 and a source redshift of z_s. """ c_light = 3.0e5 if smooth_kernal == 'box': kernel = Box2DKernel(smooth_scale) if smooth_kernal == 'tophat': kernel = Tophat2DKernel(smooth_scale / 2) # make 2D galaxy over-density maps ######## if fraction == None: fraction = mask.copy() N2d = N2d * mask area_fraction = np.sum(fraction[mask == 1]) / len(fraction[mask == 1]) dN2d = N2d * 0.0 ave = np.mean(N2d[mask == 1]) / area_fraction dN2d[mask == 1] = (N2d[mask == 1] - (ave * fraction[mask == 1])) / (ave * fraction[mask == 1]) # print(ave) # make 2D kappa_g maps ######## zl1_cd = cd.comoving_distance(z_l1, **cosmo) # Mpc zl2_cd = cd.comoving_distance(z_l2, **cosmo) # Mpc zs_cd = cd.comoving_distance(z_s, **cosmo) # Mpc delta_cd = zl2_cd - zl1_cd const = ((100. * cosmo['h'])**2 * cosmo['omega_M_0']) * (3 / 2.) * (1 / c_light**2) integ = lens_weight(np.array([z_l1, z_l2]), z_s, cosmo)[0] temp_dN = dN2d * 1.0 temp_dN[mask == 0] = 'nan' kg = const * delta_cd * integ * convolution.convolve_fft( temp_dN, kernel, normalize_kernel=True, ignore_edge_zeros=True, interpolate_nan=True) kg[mask == 0] = 0 return kg
def efficiency(self, z, dNdz): """Given dN/dz, it calculate both normalize and unnormalized lensing efficiency function. The inputs are the z array at which dN/dz is estimated. See notebook """ self.a = 1 / (1+ z) self.zarr = z.copy() self.dz = self.zarr[1] - self.zarr[0] c_light = 3e5 #km/s constant = ((100. * self.cosmo['h'])**2 * self.cosmo['omega_M_0']) * \ (3/2.) * (1/c_light**2) chi = cd.comoving_distance(self.zarr, **self.cosmo) chi_pz = [] for chi_l in chi: con = (chi > chi_l) f1 = (chi[con] - chi_l) * dNdz[con] f1 = (f1[1:] + f1[:-1]) / 2. dDs = (chi[con][1:] + chi[con][:-1]) / 2. chi_pz.append(np.sum(f1 * dDs)) chi_pz = np.array(chi_pz) self.e = chi * chi_pz / self.a self.de = (self.e[1:] + self.e[:-1]) / 2. self.int_e = np.sum(self.de * self.dz) self.norm_e = self.e / self.int_e
def redshift_grid(self): d = self.distance_from_observer() zgrid = np.arange(0,2,1e-3) dgrid = distance.comoving_distance(zgrid, **cosmo) from scipy import interpolate f = interpolate.interp1d(dgrid, zgrid) return f(d)
def comoving_d(self): self.cosmo = {'omega_M_0':0.3, 'omega_lambda_0':0.7, 'omega_k_0':0.0, 'h':0.72} comoving_edges = cd.comoving_distance(self.zedges, **self.cosmo) #Mpc #comoving_edges /= (1. + self.zedges) self.d_c = cd.comoving_distance(self.zavg, **self.cosmo) #Mpc #There is some subtilities in this case. When using MICE, the answer #makes sense when commenting the following line. When using BCC #it requires the following line #self.d_c /= (1. + self.zavg) #self.d_s = comoving_edges[-1] #source distance self.d_s = cd.comoving_distance(self.zs, **self.cosmo) #source distance #self.d_s /= (1. + self.zs) self.delta_d = comoving_edges[1:] - comoving_edges[:-1] self.a = 1 / (1 + self.zavg)
def interp_comoving_distance(z, deltaz=1e-3): # It should be fine to do linear interpolation between points # separated by deltaz=1e-3. The comoving distance function will be # very linear across that deltaz. I checked and yes, agrees with # truth to ~1e-4 Mpc. zgrid = np.arange(np.min(z)-deltaz, np.max(z)+deltaz, deltaz) dgrid = distance.comoving_distance(zgrid, **cosmo) from scipy import interpolate f = interpolate.interp1d(zgrid, dgrid) return f(z)
def plot_yy_theta(color): z = 0.1 cosmo = {'omega_M_0' : 0.3, 'omega_lambda_0' : 0.7, \ 'h' : 0.72, 'omega_k_0':0.0} DA = cd.comoving_distance(z, **cosmo) / (1 + z) #Mpc ang_dis = (np.pi/180/3600.) * DA #Mpc/arcsec ang_dis *= 60. #Mpc/arcmin f = np.genfromtxt('/home/vinu/Lensing/DES/SZ/test_yy_theta.txt') pl.plot(f[:,0]/ang_dis, f[:,1], lw=2, ls='-', label='yy',c=color)
def efficiency_single(self, zs): self.zs = zs self.zarr = np.linspace(0, self.zs+.0, 100) self.a = 1 / (1+ self.zarr) self.dz = self.zarr[1] - self.zarr[0] c_light = 3e5 #km/s constant = ((100. * self.cosmo['h'])**2 * self.cosmo['omega_M_0']) * \ (3/2.) * (1/c_light**2) chi = cd.comoving_distance(self.zarr, **self.cosmo) chi_s = cd.comoving_distance(self.zs, **self.cosmo) self.e = chi * (chi_s - chi) / (chi_s * self.a) self.de = (self.e[1:] + self.e[:-1]) / 2. self.int_e = np.sum(self.de * self.dz) self.norm_e = self.e / self.int_e
def plot_battaglia(color, scale): z = 0.1 cosmo = {'omega_M_0' : 0.3, 'omega_lambda_0' : 0.7, \ 'h' : 0.72, 'omega_k_0':0.0} DA = cd.comoving_distance(z, **cosmo) / (1 + z) #Mpc ang_dis = (np.pi/180/3600.) * DA #Mpc/arcsec ang_dis *= 60. #Mpc/arcmin f = np.genfromtxt(\ '/home/vinu/Lensing/DES/SZ/yproj_m14_batt_zw_0.1_cofm.txt') pl.plot(f[:,0]/ang_dis, f[:,3]/scale, lw=2, ls='-', label='Battaglia z=0.1 logM=14',c=color)
def find_dist_pixels(): ''' ''' verbose = True ### Cosmology cosmo = {'omega_M_0':omegaM0__, 'omega_lambda_0':omegaLambda0__, 'omega_k_0':0., 'h':h__} z_pixel_min = (lambdaObsMin__/lambdaRFLine__)-1. z_pixel_max = (lambdaObsMax__/lambdaRFLine__)-1. #if (verbose): print #if (verbose): print ' z_pixel_min = ', z_pixel_min #if (verbose): print ' z_pixel_max = ', z_pixel_max d_pixel_min = cosmology.comoving_distance(z_pixel_min, **cosmo)*h__ d_pixel_max = cosmology.comoving_distance(z_pixel_max, **cosmo)*h__ if (verbose): print if (verbose): print ' d_pixel_min = ', d_pixel_min if (verbose): print ' d_pixel_max = ', d_pixel_max return d_pixel_min, d_pixel_max
def plot_DM(): """The dimensionless proper motion distance DM/DH. """ # Set up an array of redshift values. dz = 0.01 z = numpy.arange(0., 10. + 1.1 * dz, dz) # Set up a cosmology dictionary, with an array of matter density values. cosmo = {} dom = 0.01 om = numpy.atleast_2d(numpy.linspace(0.1, 1.0, (1.-0.1)/dom)).transpose() dzt = 0.01 zt = numpy.atleast_2d(numpy.linspace(0.1, 1.0, (1.-0.1)/dzt)).transpose() cosmo['omega_M_0'] = om cosmo['transition_redshift'] = zt cosmo['omega_lambda_0'] = 1/2 * cosmo['omega_M_0'] * (1 + cosmo['transition_redshift'])**3 cosmo['h'] = 0.701 cosmo['omega_k_0'] = 1 - cosmo['omega_M_0'] - 1/2 * cosmo['omega_M_0'] * ( cosmo['transition_redshift'] + 1 )**3 # Calculate the hubble distance. dhc = cd.comoving_distance(z,z0=0, **cosmo) # Calculate the comoving distance. dm = cd.comoving_distance_transverse(z, **cosmo) # Make plots print om.ravel() fig = plt.figure() ax = fig.gca(projection='3d') om, zt = meshgrid(om.ravel(),zt.ravel()) hub = cd.comoving_distance(1,z0=0,**cosmo) surf = ax.plot_surface(om,zt,hub,rstride=1,cstride=1,cmap=cm.jet,linewidth=0,antialiased=False) # ax.set_zlim() plt.show()
def deltaLYA(line): verbose = False ### Cosmology cosmo = {'omega_M_0':omegaM0__, 'omega_lambda_0':omegaLambda0__, 'omega_k_0':0., 'h':h__} z_pixel_1 = (4000./1215.67)-1. z_pixel_2 = (4000./line)-1. if (verbose): print if (verbose): print ' z_pixel_1 = ', z_pixel_1 if (verbose): print ' z_pixel_2 = ', z_pixel_2 d_pixel_1 = cosmology.comoving_distance(z_pixel_1, **cosmo)*h__ d_pixel_2 = cosmology.comoving_distance(z_pixel_2, **cosmo)*h__ if (verbose): print if (verbose): print ' d_pixel_1 = ', d_pixel_1 if (verbose): print ' d_pixel_2 = ', d_pixel_2 if (verbose): print if (verbose): print d_pixel_1-d_pixel_2 return d_pixel_1-d_pixel_2
def distance(var): return cd.comoving_distance(var, **cosmo)
distance = [] RA_AGN = [] DEC_AGN = [] name = [] flux = [] j = 0 for i in range(len(VCV)): if VCV.values[i][2] > 0 and VCV.values[i][2] < .03: RA, DEC = np.rad2deg( astroconvert.gal2eq(np.deg2rad(VCV.values[i][4]), np.deg2rad(VCV.values[i][5]))) RA2 = float("{0:.2f}".format(float(RA))) DEC2 = float("{0:.2f}".format(float(DEC))) RA_AGN.append(RA2) DEC_AGN.append(DEC2) D = cd.comoving_distance(VCV.values[i][2], **cosmo) D2 = float("{0:.2f}".format(float(D))) distance.append(D2) name.append(VCV.values[i][1]) flux.append(100.0) j += 1 sorted_index, sorted_d = zip( *sorted([(i, e) for i, e in enumerate(distance)], key=lambda x: x[1])) RA_AGN_sorted = [RA_AGN[i] for i in sorted_index] DEC_AGN_sorted = [DEC_AGN[i] for i in sorted_index] distance_sorted = [distance[i] for i in sorted_index] name_sorted = [name[i] for i in sorted_index] print "Total number of objects=", len(VCV) print "Total number of objects with measured redshift < 0.03=", j
#array definitions xs = np.zeros(11) fgrow = np.zeros(11) l = np.arange(0, 1001) constantfactor = np.zeros(11) result = np.arange(0, 1001) #reading the data file kn, dkn = np.loadtxt("../Data_files/CAMB_linear.txt", unpack=True) plt.subplots() for redshift in range(1, 11): constantfactor[redshift] = (9 / 4) * np.power(H0 / c, 4) * np.power( omegam0, 2) * (fgrowth(redshift, 0.308, unnormed=False) * (1 + redshift))**2 xs[redshift] = cd.comoving_distance(redshift, **cosmo) # upper limit of integration for i in range(10, 1000): result[i] = integration(i, redshift) plt.plot(l[10:1000], constantfactor[redshift] * result[10:1000], label='z = {}'.format(redshift)) plt.xlabel('l') plt.ylabel(r'$C_{l}$') plt.suptitle("Angular Power Spectrum") plt.legend() plt.xscale("log") plt.yscale("log") plt.savefig("compare_angpowspec_iteration2.pdf") plt.show()
# 'n' -> Linear # 'o' -> Non-Linear #array definitions xs = np.zeros(11) l = np.arange(0, 1001) resultn = np.arange(0, 1001) resulto = np.arange(0, 1001) #reading the data file kn, dkn = np.loadtxt("../Data_files/CAMB_linear.txt", unpack=True) ko, dko = np.loadtxt("../Data_files/CAMB_non_linear.txt", unpack=True) for i in range(10, 1000): xs[zcounter] = cd.comoving_distance(zcounter, **cosmo) # upper limit of integration resultn[i] = integrate.quad( lambda x: np.power((xs[zcounter] - x) / xs[zcounter], 2) * np.interp( l[i] / x, kn, dkn), 0, xs[zcounter])[0] resulto[i] = integrate.quad( lambda x: np.power((xs[zcounter] - x) / xs[zcounter], 2) * np.interp( l[i] / x, ko, dko), 0, xs[zcounter])[0] plt.subplots() plt.plot(l[10:1000], constantfactor * resultn[10:1000], label="Linear") plt.plot(l[10:1000], constantfactor * resulto[10:1000], label="Non-Linear") plt.xlabel('l') plt.ylabel(r'$C_{l}$') plt.suptitle("Angular Power Spectrum; z = {}".format(zcounter)) plt.legend() plt.xscale("log")
unpack=True) plt.subplots() plt.xlabel('L') plt.ylabel('N$_L$') plt.suptitle("Gaussian + Poisson noise") plt.xscale("log") plt.yscale("log") plt.xlim(l_plot_low_limit, l_plot_upp_limit) for eta in eta_array: print('Eta{}'.format(eta)) previous_l_max = 0 l_max_counter = 0 eta_D2_L = eta_D2_L_initial / 10**eta chi_s[redshift] = cd.comoving_distance(redshift, **cosmo) for current_l_max in l_max_array: for L in tqdm( range(int(previous_l_max * 2**0.5), int(current_l_max * 2**0.5))): angpowspec_without_j[L] = constantfactor( redshift) * angpowspec_integration_without_j(L, redshift) for j in range(j_low_limit, j_upp_limit): print('-------------j = {}----------------'.format(j)) fileout = open( "./J_files/gaussian_plus_poisson_integration_over_distance_j_upp_limit_{}_lmax_{}_eta_{}.txt" .format(j, current_l_max, eta), "w") for L in tqdm(
def distance(redshift): return cd.comoving_distance(redshift, **cosmo)
def __init__(self,filename,radians=True, cosmology = fidcosmo): ''' Imports the survey and creates a project directory Instantiating the class requires a filename or directory in which is kept (solely) the survey information. This step is designed to be as seamless as possible, though survey information is kept in a variety of formats. To this end, note the following: The default expected input is one ascii file with columns designated (in order) as: [redshift, RA, DEC, magnitude, comoving_distance, luminosity] NOTE: only these quantities are used in any calculations in the class as yet, and therefore no other columns will be read. In future versions this may change. If a folder is specified, a list of variables and the corresponding files must be submitted. If a single file is specified in a different order than that given, the order must be specified. If the survey information is in a completely different format, then the best thing to to do is reformat it yourself and try again. And email me the problem and I'll try to update the class to deal with it. Once the information is read in, a project directory is automatically created. This serves to speed up future calculations and simplify the layout of results from your survey. The project folder is by default named <survey_filename>_Project/ and included is a hidden file ".PyLSSproject" which serves to tell this class that the folder is in fact formatted in the default way. Within this folder the directory structure looks like: Project_Folder/ .PyLSSproject correctly_formatted_survey.dat Sub_Sample_1/ .PyLSSsample sample_description.txt Data/ correctly_formatted_sample.dat Mocks/ correctly_formatted_mock_1.dat ... Randoms/ correctly_formatted_random_1.dat ... Calculation_Type_1/ results.dat ... ... ... Each data file has a default header which lets the class know how the calculation was performed and some other information which is useful for archiving purposes. This serves to let the class know whether or not to perform a calculation again, or merely read in an existing calculation. A note on cosmologies: changing the fiducial cosmology will potentially change a good many of the calculations for a given survey (especially those relying on distances). This is reflected in the "Sub_Sample" directory level. That is, two identical subsamples of the main survey will be called different subsamples if their cosmology is specified differently. ''' self.is_project_file = False self.is_sample_file = False if "_PyLSSProject_" in os.listdir(os.path.split(filename)[0]): self.is_project_file = True if "_PyLSSSample_" in os.listdir(os.path.split(filename)[0]): self.is_sample_file = True self.cosmology = cosmology if not self.is_project_file and not self.is_sample_file: self.initial_file_import(filename, radians) self.create_project_dir(filename) elif self.is_project_file: self.survey_file_import(filename) self.project_dir = os.path.split(filename)[0] c_dist = cd.comoving_distance(self.survey_data["redshift"],**self.cosmology) if 'mag' in self.survey_data.dtype.names: lum = self.LuminosityFromAppMag(c_dist) self.survey_data = nlrf.append_fields(self.survey_data, names=("c_dist","lum"), data=(c_dist,lum), dtypes=(float,float),usemask=False,asrecarray=True) self.survey_data.dtype.names = ("redshift",'ra','dec','mag','c_dist','lum') else: self.survey_data = nlrf.append_fields(self.survey_data, names="c_dist", data=c_dist, dtypes=float,usemask=False,asrecarray=True) self.survey_data.dtype.names = ("redshift",'ra','dec','mag','c_dist') self.create_sample_dir() else: self.survey_file_import(filename) self.project_dir = os.path.split(os.path.split(filename)[0])[0] self.sample_dir = os.path.split(filename)[0] self.sample_name = os.path.split(filename)[1] # Define some overall parameters of the sample. self.N = self.survey_data['redshift'].shape[0] self.survey_name = os.path.split(self.project_dir)[1] # Make a Plots Directory self.plots_dir = self.sample_dir+'/SurveyPlots' try: os.makedirs(self.plots_dir) except OSError, e: if e.errno != errno.EEXIST: raise
def _correlation_in_s(quantity='c_dist', end_s=0.02, nr=15, n_randoms=1, n_cores=1): """ The convenience (callable) function to perform a correlation function estimation in redshift/c_dist space Note: At this time it will perform the correlation either in redshift or in comoving distance, but the final result will always be displayed in comoving distance. As many randoms as wanted can be used. There are NO error estimates as yet. Also, the 'angular selection function' used is merely the exact angles of the original particles. The algorithm can be sped up by using sorted redshift - will do this soon. PARAMETERS quantity ['c_dist'] - Should be 'c_dist' or 'redshift'. Specifies how to bin the data. end_s [0.02] - The largest separation to calculate. Default 0.02 for z, 120 for s. nr [15] - The number of bins to use. n_randoms [1] - The number of random catalogues to use. VALUES s_bins - an array of length nr with bin centres Corr - an array of length nr with correlation values. """ #Do some default cleaning if quantity != 'c_dist' and quantity != 'redshift': quantity = 'c_dist' if quantity == 'c_dist' and end_s == 0.02: end_s = 120 #Convert to cartesian real_pos = np.array(self.sph2car(self.survey_data[quantity], self.survey_data['ra'], self.survey_data['dec'])) print "shape of real_pos, ", real_pos.shape #Calculate data-data pairs DD = self.correlation_function_dd_wrapper(real_pos, end_s, nr) RR = np.zeros((n_randoms, nr)) DR = RR for i in range(n_randoms): print "Processing random number ", i #Make some randoms #Use the simple selection function production for now #Except I'll need an angle production as well. For now, use same angles as original. rand_r = self.create_radial_selection() random_pos = np.array(self.sph2car(rand_r, self.survey_data['ra'], self.survey_data['dec'])) #For all randoms, calculate DR and RR pairs RR[i, :] = self.correlation_function_dd_wrapper(random_pos, end_s, nr) DR[i, :] = self.correlation_function_dr_wrapper(pos1=real_pos, pos2=random_pos, end_s=end_s, nr=nr) #Take the means along the n_randoms axis RR = np.mean(RR, axis=0) DR = np.mean(DR, axis=0) #Use the Landy-Szalay Estimator Corr = 1 + DD / RR - 2 * DR / RR #Calculate the centre of bins s_bins = np.linspace(end_s / (2 * nr), end_s * (1 - 0.5 / nr), nr) if quantity == 'redshift': s_bins = cd.comoving_distance(s_bins, **self.cosmology) #Plot the function plt.clf() plt.plot(s_bins, Corr) plt.show() plt.savefig(self.__correlation_dir + '/correlation_in_' + quantity + '.eps') plt.clf() plt.plot(s_bins, s_bins ** 2 * Corr) plt.show() plt.savefig(self._correlation_dir + '/correlation_in_' + quantity + '_by_s_squared.eps') return s_bins, Corr
#print el.header z = el.header['ZQSO'] el = el.data #if (el['flux'][ el['flux']<0.05 ].size==0): continue plt.errorbar( el['lambda']/(1.+z), el['flux'],marker='o') #/(1.+z) lambdaTST = numpy.append(el['lambda']/(1.+z), lambdaTST) #/(1.+z) fluxTST = numpy.append(el['flux'], fluxTST) zTST = numpy.append(z,zTST) nbPixel = numpy.append(el['lambda'].size,nbPixel) print i, el['lambda'].size, z myTools.deal_with_plot(False,False,True) plt.ylim([ -0.1, 1.1]) distPixel = numpy.append(distPixel, [ el['lambda'][i+1]-el['lambda'][i] for i in range(0,el['lambda'].size-1) ]) distPixel2 = numpy.append(distPixel2, [ (el['lambda'][i+1]+el['lambda'][i])*0.5 for i in range(0,el['lambda'].size-1) ]) dist = cosmology.comoving_distance(el['lambda']/1215.67-1., **cosmo)*h__ deltaDist = numpy.append( deltaDist, [ dist[i+1]-dist[i] for i in range(0,el['lambda'].size-1) ] ) ''' print el['lambda'][0],dist[0] for i in range(0,el['lambda'].size-1): print el['lambda'][i+1], dist[i+1], distPixel[i], deltaDist[i] ''' plt.show() plt.hist(deltaDist,bins=100) plt.show() lambdaTST = numpy.asarray(lambdaTST)
def distance(z): return cd.comoving_distance(z, **cosmo)
from pylab import * import numpy as np import cosmolopy from scipy import integrate from scipy import interpolate from Cosmology import pyxi import cosmolopy.distance as cd from Cosmology import cosmology mycosmo = cosmolopy.fidcosmo.copy() mycosmo['baryonic_effects'] = True mycosmo['h'] = 0.7 mycosmo['omega_M_0'] = 0.3 mycosmo['omega_lambda_0'] = 0.7 mycosmo['omega_k_0'] = 0. print(cd.comoving_distance(0.001, **mycosmo)) print(cosmology.properdistance(np.array([0.001, 0.002])) * 3e5 / 70)
from pylab import * import numpy as np import cosmolopy from scipy import integrate from scipy import interpolate from Cosmology import pyxi import cosmolopy.distance as cd from Cosmology import cosmology mycosmo=cosmolopy.fidcosmo.copy() mycosmo['baryonic_effects']=True mycosmo['h']=0.7 mycosmo['omega_M_0']=0.3 mycosmo['omega_lambda_0']=0.7 mycosmo['omega_k_0']=0. print(cd.comoving_distance(0.001,**mycosmo)) print(cosmology.properdistance(np.array([0.001,0.002]))*3e5/70)
import numpy import cosmolopy.distance as cosmology from const_delta import * import matplotlib.pyplot as plt import cosmolopy.constants as cc from scipy import interpolate ### Cosmology cosmo = {'omega_M_0':omegaM0__, 'omega_lambda_0':omegaLambda0__, 'omega_k_0':0., 'h':h__} z = numpy.arange(0.,6.,0.001) d = cosmology.comoving_distance(z, **cosmo)*h__ convert_d_to_z = interpolate.interp1d(d,z,bounds_error=False,fill_value=0) def Get_speed(v,zTrue): return (1.+zTrue)*v+zTrue def Get_speed2(v,zTrue): vCosmo = ((1.+zTrue)**2.-1.)/((1.+zTrue)**2.+1.) tmpv = (vCosmo+v)/( 1.+ vCosmo*v ) return numpy.sqrt( (1.+tmpv)/(1.-tmpv) ) - 1. z = 2.5 v = numpy.arange(0.,1.,0.00001) zObs = numpy.array( [ Get_speed(i,z) for i in v ] )