class setup(): dpath = '../../data/' dgenpath = '../../data/data-generated/' cosmo = cosmology.Cosmology(M=0.295, pfile=dpath + 'pklin_ds14.dat') dndz = np.loadtxt(dgenpath + 'cls_sampled/dndz_qso_pdb_lf.txt').T idndz = interpolate(dndz[0], dndz[1])
def __init__(self, z, dndz, cosmo=None, l=None, dz=0.5, nz=100, ggnorm=None): #Parameters which are not set if cosmo is None: cosmo = cosmology.Cosmology(M=CosmoPar().M, pfile=Files().pkfile) if l is None: l = numpy.linspace(100, 3000, 2901) if dndz is None: dndz = lambda x: 1 self.ggnorm = ggnorm self.z = z self.dndz = dndz self.cosmo = cosmo self.l = l self.dz = dz self.nz = nz self._clsetup()
def __init__(self, pm, Dmax_xgal, gridnr, obRun): """ pm: the parameter file Dmax_xgal: the maximum distance up to which transients are visible in kpc. gridnr: the frame number/identifying number of the grid obRun: the parent Observation instance """ self.gridnr = gridnr self.obRun = obRun self.SetUpFramecoords() self.Dmax_MK = MW.DMax_MW_kpc self.Dmax_xgal = Dmax_xgal self.N_RA = pm['n_RA'] self.N_DEC = pm['n_DEC'] self.N_cellsRADEC = self.N_RA * self.N_DEC self.FoV = obRun.aperture_DEC * obRun.aperture_RA self.N_DMW = pm['nCells_D'] self.N_xgal = pm['nCells_xgal'] self.h_DMW = self.Dmax_MK / float(self.N_DMW) self.h_xgal = (Dmax_xgal - self.Dmax_MK) / float(self.N_xgal) self.Gal_trans = obRun.Gal_trans #Whether there are Gal transients self.Xgal_trans = obRun.Xgal_trans #Whether there are Xgal transients self.bands = self.obRun.bands if self.Xgal_trans: self.Cosmo = cm.Cosmology(Dmax_xgal) self.cellGrid = self.makeCellGrid(self.h_DMW, self.h_xgal) self.choose_dust_grid()
def EvolvePmesh(pm, pmfinal, timesteps, Q, use_cosmo, smoothing = 0, lptbool = 0, snaps = None, \ laplacian = fourier_lap, derivative = fourier_der, zolamode = 0): boxsize = pm.BoxSize[0] ZA = evolve.ZA(pm, Q) if lptbool: LPT = evolve.LPT2(pm, Q) obj1 = Bunch() obj1.pos = numpy.zeros_like(Q) obj1.vel = numpy.zeros_like(Q) obj1.accel = numpy.zeros_like(Q) ## IC ## cosmo = cosmology.Cosmology(use_cosmo, 100.) a0 = numpy.exp(timesteps[0]) obj1.pos = Q + ZA * cosmo.Dgrow(a0) obj1.vel = ZA * cosmo.Dgrow(a0) * cosmo.Fomega1(a0) * cosmo.Ha(a0) * a0**2 if lptbool: obj1.pos += cosmo.Dgrow(a0)**2 * LPT obj1.vel += cosmo.Dgrow(a0)**2 *LPT \ *cosmo.Fomega2(a0)*cosmo.Ha(a0)* a0**2 obj1.pos[obj1.pos < 0.0] += pm.BoxSize[0] obj1.pos[obj1.pos > pm.BoxSize[0]] -= pm.BoxSize[0] ## Loop it ## for i in range(len(timesteps) - 1): loga1 = timesteps[i] loga2 = timesteps[i + 1] weight = 3 * cosmo.M * cosmo.H0**2 / (8 * math.pi * 43.007) * ( pm.BoxSize[0] / pm.Nmesh)**3 accelerate(obj1.pos, pmfinal, obj1.accel, smoothing, weight, laplacian, derivative) if i > 0: loga0 = timesteps[i - 1] kick(obj1.vel, obj1.accel, 0.5 * (loga1 + loga0), loga1, loga1, zolamode) kick(obj1.vel, obj1.accel, loga1, 0.5 * (loga1 + loga2), loga1, zolamode) drift(obj1.pos, obj1.vel, loga1, loga2, pmfinal, zolamode) pmfinal.clear() pmfinal.paint(obj1.pos) output.append(pmfinal.real.copy()) pmfinal.clear() ## Return evolved position ## pmfinal.paint(obj1.pos) return output
def set_new_redshift(self, redshift): ''' Setting redshift Parameters ---------- redshift : float Redshift of the source for fitting ''' self.redshift = redshift # Need luminosity distance to adjust spectrum to distance of the source self.Dl = cosmology.Cosmology().luminosity_distance(self.redshift) self.sfh_class.set_agelim(self.redshift)
def za_ic(pm, pmfinal, Q, timesteps, use_cosmo, smoothing=0): cosmo = cosmology.Cosmology(use_cosmo, 100.) ZA = evolve.ZA(pm, Q) a0 = numpy.exp(timesteps[0]) pos_ic = Q + ZA * cosmo.Dgrow(a0) pos_ic[pos_ic < 0.0] += pm.BoxSize[0] pos_ic[pos_ic > pm.BoxSize[0]] -= pm.BoxSize[0] pmfinal.clear() pmfinal.paint(pos_ic)
def est_comoving_dist(self, cosmology=None): if cosmology is None: cosmology = cosmo.Cosmology() if self._catalog is not None: dc = cosmology.comoving_distance(self._catalog['Z']) if 'DC' in self._catalog.dtype.fields.keys(): self._catalog['DC'] = dc if self._feedback > 1: print "Note: \'DC\' field overwrited !" else: self._catalog = append_fields(self._catalog, 'DC', dc)
def __init__(self, power_file, M, L, R=0., H0=100.): self.M = M self.L = L self.ktrue, self.ptrue = numpy.loadtxt(power_file, unpack=True) self.H0 = H0 self.R = R self.rhoc = 3 * H0**2 / (8 * math.pi * 43.007) self.rhom = self.rhoc * M self.cosmo = cosmo_lib.Cosmology(M=M, L=L) self.masses = 10**numpy.arange(9, 18, 0.01) self.sigma = numpy.zeros_like(self.masses) self.calc_sigma()
def find_GC(input_path, input_name, output_path=None, criterion=[1., 2., 4.]): prefix = '' if output_path is None: output_path = input_path comm = MPI.COMM_WORLD rank = comm.Get_rank() size = comm.Get_size() ga = read_data.GAMA_CAT(input_path) ga.catalog = input_name c = cosmo.Cosmology() c = c.init_physical(ombh2=0.02230, omch2=0.1188, H0=67.74, omkh2=0.00037) ga.est_comoving_dist(c) cg_index = np.zeros(len(ga.catalog)) #.astype('bool') cg_index_local = np.zeros(len(ga.catalog)) #.astype('bool') cos = np.cos sin = np.sin h = c.H0 / 100. cat_z = ga.catalog['Z'] criterion = np.sort(criterion)[::-1] for i in range(len(ga.catalog))[rank::size]: z_sel = [] hav = lambda x: (1. - np.cos(x)) / 2. ra = ga.catalog['RA'][i] * np.pi / 180. dec = ga.catalog['DEC'][i] * np.pi / 180. z = ga.catalog['Z'][i] z_sel.append(np.abs(cat_z - z) * u.c < criterion[0] * 1000. * 1.e3) z_sel[0][i] = False if not np.any(z_sel[0]): #print 'OK' cg_index[i] = criterion[0] continue for j in range(1, len(criterion)): z_sel.append( np.abs(cat_z[z_sel[0]] - z) * u.c < criterion[j] * 1000. * 1.e3) ra_sel = ga.catalog['RA'][z_sel[0]] * np.pi / 180. dec_sel = ga.catalog['DEC'][z_sel[0]] * np.pi / 180. cos_theta = hav(dec_sel - dec) + cos(dec_sel) * cos(dec) * hav(ra_sel - ra) cos_theta = 1. - 2. * cos_theta cos_theta[np.abs(cos_theta) < 1.e-9] = 0. cat_d = ga.catalog['DC'][z_sel[0]] / h * np.arccos(cos_theta) tr_sel = cat_d < 1. * criterion[0] if not np.any(tr_sel): #print 'OK' cg_index[i] = criterion[0] continue for j in range(1, len(criterion)): tr_sel = cat_d[z_sel[j]] < 1. * criterion[j] if not np.any(tr_sel): #print 'OK' cg_index[i] = criterion[j] #continue break #else: # print comm.Reduce(cg_index, cg_index_local, root=0) if rank == 0: #cg_index_local = cg_index_local.astype('bool') #catalog = ga.catalog[cg_index_local] for i in range(len(criterion)): print "Criterion %3.1f : %d" % ( criterion[i], len(cg_index_local[cg_index_local >= criterion[i]])) ga.add_fields('CGC', cg_index_local) ga.save(overwrite=True) comm.barrier()
def find_GC_old(input_path, input_name, output_path=None, criterion=1., bcut=100): prefix = '' if output_path is None: output_path = input_path comm = MPI.COMM_WORLD rank = comm.Get_rank() size = comm.Get_size() ga = read_data.GAMA_CAT(input_path) ga.catalog = input_name c = cosmo.Cosmology() c = c.init_physical(ombh2=0.02230, omch2=0.1188, H0=67.74, omkh2=0.00037) ga.est_comoving_dist(c) if bcut != 100: cat_n = len(ga.catalog) b = ga.catalog['MODELFLUX_r'] * 4. * np.pi * ga.catalog['DC']**2. b_bad = b < np.percentile(b, bcut) ga.mask_bad(b_bad) ga.rm_masked() print "%d of %d galaxies are removed due to the brightness cut" % (len( ga.catalog), cat_n) prefix += '_B%02d' % bcut cg_index = np.zeros(len(ga.catalog)) #.astype('bool') cg_index_local = np.zeros(len(ga.catalog)) #.astype('bool') cos = np.cos sin = np.sin h = c.H0 / 100. for i in range(len(ga.catalog))[rank::size]: hav = lambda x: (1. - np.cos(x)) / 2. ra = ga.catalog['RA'][i] * np.pi / 180. dec = ga.catalog['DEC'][i] * np.pi / 180. z = ga.catalog['Z'][i] z_sel = np.abs(ga.catalog['Z'] - z) * u.c < criterion * 1000. * 1.e3 z_sel[i] = False if not np.any(z_sel): #print 'OK' cg_index[i] = 1 continue ra_sel = ga.catalog['RA'][z_sel] * np.pi / 180. dec_sel = ga.catalog['DEC'][z_sel] * np.pi / 180. cos_theta = hav(dec_sel - dec) + cos(dec_sel) * cos(dec) * hav(ra_sel - ra) cos_theta = 1. - 2. * cos_theta cos_theta[np.abs(cos_theta) < 1.e-9] = 0. tr_sel = ga.catalog['DC'][z_sel] / h * np.arccos(cos_theta) tr_sel = tr_sel < 1. * criterion if not np.any(tr_sel): #print 'OK' cg_index[i] = 1 #else: # print comm.Reduce(cg_index, cg_index_local, root=0) if rank == 0: cg_index_local = cg_index_local.astype('bool') catalog = ga.catalog[cg_index_local] header = '%20s ' * len(catalog.dtype.names) header = header % catalog.dtype.names header = header[2:] print header #np.savetxt('/data/ycli/gama/galcat_GAMA_CG.dat', catalog, fmt='%20.12f', # header=header) #np.savetxt('/data/ycli/dr12/galaxy_DR12v5_LOWZ_North_RaDecZ_CGC.dat', # catalog, fmt='%20.12f', # header=header) #np.savetxt('/data/ycli/dr12/galaxy_DR12v5_LOWZ_South_RaDecZ_CGC.dat', # catalog, fmt='%20.12f', # header=header) #np.savetxt('/data/ycli/dr12/galaxy_DR12v5_CMASS_North_RaDecZ_CGC.dat', # catalog, fmt='%20.12f', # header=header) np.savetxt(output_path + input_name.split('.')[0] + '%s_CGC%d.dat' % (prefix, criterion), catalog, fmt='%20.12f', header=header)
def __init__(self, Spectrum, z=None, d=None, fluxnorm=None, miscline=None, misctol=10., ignore=None, derive=True, debug=False, restframe=False, ptol=2, sort=False): """ This can be called after a fit is run. It will inherit the specfit object and derive as much as it can from modelpars. Just do: spec.measure(z, xunits, fluxnorm) Notes: If z (redshift) or d (distance) are present, we can compute integrated line luminosities rather than just fluxes. Provide distance in cm. Only works with Gaussians. To generalize: 1. make sure we manipulate modelpars correctly, i.e. read in entries corresponding to wavelength/frequency/whatever correctly. Parameters ---------- z: float or None redshift d: float or None distance in cm (used for luminosities) fluxnorm: bool Normalize the fluxes? miscline: dictionary miscline = [{'name': H_alpha', 'wavelength': 6565}] misctol: tolerance (in Angstroms) for identifying an unmatched line to the line(s) we specify in miscline dictionary. sort: bool Sort the entries in order of observed wavelength (or velocity or frequency) """ self.debug = debug self.restframe = restframe # Inherit specfit object self.specfit = Spectrum.specfit self.speclines = Spectrum.speclines # Bit of a hack - help identifying unmatched lines self.miscline = miscline self.misctol = misctol # Flux units in case we are interested in line luminosities or just having real flux units if fluxnorm is not None: self.fluxnorm = fluxnorm else: self.fluxnorm = 1 # This is where we'll keep our results self.lines = OrderedDict() # Read in observed wavelengths tmp1 = np.reshape(self.specfit.modelpars, (len(self.specfit.modelpars) / 3, 3)) tmp2 = np.reshape(self.specfit.modelerrs, (len(self.specfit.modelerrs) / 3, 3)) if ignore is not None: tmp1 = np.delete(tmp1, ignore, 0) tmp2 = np.delete(tmp2, ignore, 0) # each tmp1 contains amplitude,wavelength,width # (Assumes gaussians) wavelengths = tmp1[:, 1] # sort by wavelength if sort: order = np.argsort(wavelengths) self.obspos = wavelengths[order] else: order = np.arange(wavelengths.size) self.obspos = wavelengths self.Nlines = wavelengths.size # Read in modelpars and modelerrs, re-organize so they are 2D arrays sorted by ascending wavelength self.modelpars = np.zeros_like(tmp1) self.modelerrs = np.zeros_like(tmp2) for i, element in enumerate(order): self.modelpars[i] = tmp1[element] self.modelerrs[i] = tmp2[element] # Read in appropriate list of reference wavelengths/frequencies/whatever self.reflines = self.speclines.optical.get_optical_lines() self.refpos = self.reflines['xarr'] self.refname = self.reflines['name'] # Redshift reference lines if restframe = True if self.restframe and z is not None: self.refpos *= (1.0 + z) # If distance or redshift has been provided, we can compute luminosities from fluxes if d is not None: self.d = d else: self.d = None if z is not None: self.cosmology = cosmology.Cosmology() self.d = self.cosmology.LuminosityDistance(z) * cm_per_mpc self.unmatched = self.identify_by_position(ptol=ptol) #if np.sum(unmatched) >= 2: # self.identify_by_spacing(unmatched) if derive: self.derive()
def parse_arguments(Files=None, CosmoPar=None): '''Parse the arguments from command line ''' if CosmoPar is None: CosmoPar = CosmoPar_local() parser = argparse.ArgumentParser() parser.add_argument('--beam', default=1, type=float) parser.add_argument('--temp', default=1, type=float) parser.add_argument('--zg', default=1, type=float, help="Redshift of source") parser.add_argument('--dz', default=0.5, type=float, help="Redshift bin around the source") parser.add_argument('--Nsource', default=50, type=float, help="Number of sources per arcmin") parser.add_argument('--b1', default=None, type=float, help="Bias of the sources") parser.add_argument('--M', default=CosmoPar.M, type=float, help="Matter density") parser.add_argument('--L', default=CosmoPar.L, type=float, help="Dark energy") parser.add_argument('--H0', default=CosmoPar.H0, type=float, help="Hubble") parser.add_argument('--pkfile', default=Files.pkfile, help="File with linear power spectrum") parser.add_argument('--outpath', default=Files.outpath, help="Where to save output") parser.add_argument('--classfile', default=Files.classfile, help="cl output from class") parser.add_argument('--errorfile', default=None, help="spectra file with errors and noises") parser.add_argument('--noisefile', default=None, help="File with instrumental and Fisher Noise") parser.add_argument('--survey', default='lsst', help="Which survey to use dndz from") args = parser.parse_args() args.cosmo = cosmology.Cosmology(M=args.M, L=args.L, pfile=args.pkfile) if args.b1 is None: args.b1 = 2 * args.cosmo.Dgrow(z=1.) / args.cosmo.Dgrow(z=args.zg) #Define file formats here if args.noisefile is None: try: args.noisefile = Files.noisefile % (args.beam * 10, args.temp * 10) except: args.noisefile = Files.noisefile if args.errorfile is None: try: args.errorfile = Files.errorfile % (args.zg * 100, args.b1 * 10, args.beam * 10, args.temp * 10) except: args.errorfile = Files.errorfile #Print them for runtime check print("beam = ", args.beam) print("dT = ", args.temp) print("zg = ", args.zg) print("b1 = ", args.b1) print("Noisefile = ", args.noisefile) print("Errorfile = ", args.errorfile) return args
action="store", dest="cols", type=float, nargs=6, default=[20, 6, 8, 9, 24, 21], help= "Columns containing the parameters: Omega_matter, Omega_k, w_DE, w_a, H_0, sigma_8. Mind the order of the parameters. [Default: %default]" ) return p.parse_args() if __name__ == "__main__": (opt, args) = options(op.OptionParser(version="%prog version 1.")) if (opt.a == None): opt.a = 1. / (1. + np.array(opt.z)) else: opt.a = np.array(opt.a) chain = np.loadtxt(args[0]) #read the input file for i, (om, ok, w0, wa, H0, s8) in enumerate(chain[:, opt.cols]): chain[i, opt.cols[-1]] = s8 * c.Cosmology( om=om, ok=ok, w0=w0, wa=wa, H0=H0).growth_rat(opt.a[0], opt.a[1]) np.savetxt(args[1], chain, fmt='%9.8e', delimiter='\t') exit()
def est_pksz_pipe(ini_params, feedback=1): comm = MPI.COMM_WORLD rank = comm.Get_rank() size = comm.Get_size() if rank != 0: feedback=0 _s = ini_params['cat_sele'] prefix = ini_params['prefix'] N = ini_params['rand_numb'] theta = ini_params['AP_theta'] f = ini_params['AP_f'] sigma_z = ini_params['sigma_z'] pksz_bins = ini_params['pksz_bins'] #pksz_bins -= 0.5 * (pksz_bins[1] - pksz_bins[0]) output_path = ini_params['output'] pl_map = ini_params['pl_map_code'] pl_data_path = ini_params['pl_map_path'] pl = read_data.PLANCK_MAP(pl_data_path, feedback=feedback) pl.mask = ini_params['pl_map_mask'] pl.kSZ_map = 'planck_%s.fits'%pl_map pl.unit = ini_params['pl_map_unit'] pl.unit = u.micro_K # convert to micro_K prefix += '_%s'%pl_map ga_cat = ini_params['ga_cat_code'] ga_data_path = ini_params['ga_cat_path'] ga = read_data.GAMA_CAT(ga_data_path, feedback=feedback) ga.catalog = 'galcat_%s.dat'%ga_cat prefix += '_%s'%ga_cat ga.mask_bad(ga.catalog['Z']<0.01) if ini_params['cgc_criterion'] is not None: ga.mask_bad(ga.catalog['CGC'] < ini_params['cgc_criterion']) prefix += '_CGC%d'%ini_params['cgc_criterion'] #if 'IO' in ga.catalog.dtype.names: # ga.mask_bad(ga.catalog['IO']==0) # prefix += '_I' #if ini_params['cmbrest'] == True: # print "convert from cmbrest to heliocentric" # prefix += '_HC' # ga.catalog['Z'] = ga.cmbrest_to_heliocentric() if 'dec_criterion' in ini_params.keys(): if ini_params['dec_criterion'] == 'N': ga.mask_bad(ga.catalog['DEC']<0) prefix += '_N' elif ini_params['dec_criterion'] == 'S': ga.mask_bad(ga.catalog['DEC']>0) prefix += '_S' #if 'n_member_criterion_max' in ini_params.keys(): # ga.mask_bad(ga.catalog['NMEM']>ini_params['n_member_criterion_max']) # prefix += '_NMEM_Max%d'%ini_params['n_member_criterion_max'] #if 'n_member_criterion_min' in ini_params.keys(): # ga.mask_bad(ga.catalog['NMEM']<ini_params['n_member_criterion_min']) # prefix += '_NMEM_Min%d'%ini_params['n_member_criterion_min'] if 'logHM_max' in ini_params.keys(): if 'LOGHALOMASS' in ga.catalog.dtype.names: halo_mass = ga.catalog['LOGHALOMASS'] elif 'LOGMASS' in ga.catalog.dtype.names: h = 0.67 halo_mass = models.stellarM2haloM(10.**ga.catalog['LOGMASS']/h)*h halo_mass = np.log10(halo_mass) else: print "LOGHALOMASS or LOGMASS needed" exit() ga.mask_bad(halo_mass>ini_params['logHM_max']) #ga.mask_bad(ga.catalog['IO']==1) prefix += '_logHM_Max%d'%ini_params['logHM_max'] if 'logHM_min' in ini_params.keys(): if 'LOGHALOMASS' in ga.catalog.dtype.names: halo_mass = ga.catalog['LOGHALOMASS'] elif 'LOGMASS' in ga.catalog.dtype.names: h = 0.67 halo_mass = models.stellarM2haloM(10.**ga.catalog['LOGMASS']/h)*h halo_mass = np.log10(halo_mass) else: print "LOGHALOMASS or LOGMASS needed" exit() ga.mask_bad(halo_mass<ini_params['logHM_min']) #ga.mask_bad(ga.catalog['IO']==1) prefix += '_logHM_Min%d'%ini_params['logHM_min'] jk_sample = False if 'jk' in ini_params.keys(): if ini_params['jk']: prefix += '_JK' jk_sample = True sim_sample = False if 'sim' in ini_params.keys(): if ini_params['sim']: prefix += '_SIM' sim_sample = True #if ga_cat == 'GAMA_CG': # ga.mask_bad(ga.catalog['MAG_AUTO_R'] == 99.) # ga.mask_bad(ga.catalog['MAG_AUTO_R'] >= 17.) #if ga_cat == 'DR12LOWZNCGC' and ini_params['zlim'] != []: # zmin = ini_params['zlim'][0] # zmax = ini_params['zlim'][1] # zbad = np.logical_or(ga.catalog['Z'] < zmin, ga.catalog['Z'] >= zmax) # ga.mask_bad(zbad) # prefix += '_zlim%3.2fto%3.2f'%(zmin, zmax) #if ga_cat in ['DR12CMASNCGC', 'DR12CMASSCGC', 'DR12LOWZNCGC', 'DR12LOWZSCGC', # 'DR12CMASNCGC2', 'DR12CMASSCGC2', 'DR12LOWZNCGC2', 'DR12LOWZSCGC2']: # mr = 22.5 - 2.5 * np.log10(ga.catalog['MODELFLUX_r']) # ga.mask_bad(mr > ini_params['r_cut']) # prefix += '_mlim%3.1f'%ini_params['r_cut'] max_len = ini_params['max_len'] ga_bad = np.ones(ga.catalog.shape[0]) ga_bad[_s] = False ga.mask_bad(ga_bad) ga.rm_masked() c = cosmo.Cosmology() c = c.init_physical(ombh2=0.02230, omch2=0.1188, H0=67.74, omkh2=0.00037) ga.est_comoving_dist(c) ga.get_ga_coord() output_name = '%s_%d_AP%darcm_f%3.2f_sigz%4.3f'%(prefix, N, theta, f, sigma_z) pkSZ_estimator(pl, ga, theta=theta/60., f=f, sigma_z = sigma_z, feedback=feedback, max_len=max_len, N=N, output_path=output_path, output_name=output_name, pksz_bins=pksz_bins, rank=rank, size=size, comm=comm, jk_sample=jk_sample, sim_sample=sim_sample)
def EvolvePmesh(pm, pmfinal, timesteps, Q, use_cosmo, smoothing = 0, lptbool = 0, snaps = None, \ laplacian = fourier_lap, derivative = fourier_der, zolamode = 0): output = [] boxsize = pm.BoxSize[0] ZA = evolve.ZA(pm, Q) if lptbool: LPT = evolve.LPT2(pm, Q) obj1 = Bunch() obj1.pos = numpy.zeros_like(Q) obj1.vel = numpy.zeros_like(Q) obj1.accel = numpy.zeros_like(Q) ## IC ## cosmo = cosmology.Cosmology(use_cosmo, 100.) a0 = numpy.exp(timesteps[0]) obj1.pos = Q + ZA * cosmo.Dgrow(a0) obj1.vel = ZA * cosmo.Dgrow(a0) * cosmo.Fomega1(a0) * cosmo.Ha(a0) * a0**2 if lptbool: obj1.pos += cosmo.Dgrow(a0)**2 * LPT obj1.vel += cosmo.Dgrow(a0)**2 *LPT \ *cosmo.Fomega2(a0)*cosmo.Ha(a0)* a0**2 obj1.pos[obj1.pos < 0.0] += pm.BoxSize[0] obj1.pos[obj1.pos > pm.BoxSize[0]] -= pm.BoxSize[0] ## Loop it ## for i in range(len(timesteps) - 1): loga1 = timesteps[i] loga2 = timesteps[i + 1] weight = 3 * cosmo.M * cosmo.H0**2 / (8 * math.pi * 43.007) * ( pm.BoxSize[0] / pm.Nmesh)**3 accelerate(obj1.pos, pmfinal, obj1.accel, smoothing, weight, laplacian, derivative) if i > 0: loga0 = timesteps[i - 1] kick(obj1.vel, obj1.accel, 0.5 * (loga1 + loga0), loga1, cosmo) kick(obj1.vel, obj1.accel, loga1, 0.5 * (loga1 + loga2), cosmo) drift(obj1.pos, obj1.vel, loga1, loga2, boxsize, cosmo) pmfinal.clear() # if snaps != None: # postemp = numpy.zeros_like(obj1.pos) # postemp[:] = obj1.pos # # left = snaps.searchsorted(loga1, side = "left") # right = snaps.searchsorted(loga2, side = "right") # # if left != right: # drift(postemp, obj1.vel, loga1, snaps[left], boxsize, cosmo) # pmfinal.clear() # pmfinal.paint(postemp) # output.append(pmfinal.real.copy()) # # for foo in range(left+1, right): # drift(postemp, obj1.vel, snaps[foo -1], snaps[foo], boxsize, cosmo) # pmfinal.clear() # pmfinal.paint(postemp) # output.append(pmfinal.real.copy()) # #drift(postemp, obj1.vel, snaps[right-1], loga2, pmfinal, cosmo) pmfinal.clear() ## Return evolved position ## pmfinal.paint(obj1.pos) return output