示例#1
0
def modifynoise(M):
    noise_model = truth_noise_model
    noisemlim = 10**M
    #if noisep['noisefile'] is not None:
    if noisep['offset'] or noisep['noised'] == 3:
        try:
            noisefile = mpath + noisep['noisefile'] % (10 * M)
        except TypeError:
            noisefile = mpath + noisep['noisefile']
        except:
            if not rank:
                print('\nERROR: Need a noise file for the offset & 3D noise\n')
            sys.exit()
        if not rank: print('Noise file is \n%s' % noisefile)

        truth_noise_model.create_off3d(data_m.mapp,
                                       noisefile,
                                       smooth=noisep['smooth'])
        save_map(truth_noise_model.offset,
                 optfolder + 'noise_M%02d' % (10 * M), 'offset')
        truth_noise_model.create_ivar3d(data_m.mapp,
                                        noisefile,
                                        noisep['noisevar'],
                                        smooth=noisep['smooth'])

    if noisep['mlim']:
        truth_noise_model.suppress_noise(data_m.mapp,
                                         mlim=noisemlim,
                                         ninf=float(noisep['ninf']),
                                         smooth=noisep['smooth'])
    if noisep['noised'] == 3:
        save_map(truth_noise_model.ivar3d,
                 optfolder + 'noise_M%02d' % (10 * M), 'ivar3d')
    return noise_model
示例#2
0
def make_data(bs, nc, seed, nsteps, path='', z=0):
    #initiate
    pm = ParticleMesh(BoxSize=bs, Nmesh=(nc, nc, nc), dtype='f8')

    ofolder = path + 'z%02d/L%04d_N%04d_S%04d_%02dstep/'%(z*10, bs, nc, seed, nsteps)
#        
    
    if pm.comm.rank == 0:
        print('Make data for seed = %d'%seed)
        print('Data to be saved at path - %s'%ofolder)

    klin, plin = numpy.loadtxt('ics_matterpow_0.dat', unpack = True)
    pk = interpolate(klin, plin)
    cosmo = Planck15.clone(Omega_cdm = 0.2685, h = 0.6711, Omega_b = 0.049)
    #pk = EHPower(Planck15, redshift=0)
    #cosmo = Planck15

    s_truth = pm.generate_whitenoise(seed, type='complex')\
            .apply(lambda k, v: v * (pk(sum(ki **2 for ki in k) **0.5) / v.BoxSize.prod()) ** 0.5)\
            .c2r()

    #dynamics
    aa = 1.0/(1+z)
    if pm.comm.rank == 0:
        print('Evolve to redshift = %0.1f, scale factor = %0.2f'%(z, aa))
    stages = numpy.linspace(0.1, aa, nsteps, endpoint=True)

    start = time()
    dynamic_model = NBodyModel(cosmo, pm, B=2, steps=stages)
    #dynamic_model = LPTModel(cosmo, pm, B=2, steps=stages)

    #Save data

    X, V, final = dynamic_model.get_code().compute(['X', 'V', 'final'], init={'parameters':s_truth})
    end = time()
    print('Time taken = ', end-start)

    save_map(s_truth, ofolder + 'mesh', 's')
    save_map(final, ofolder + 'mesh', 'd')

    if pm.comm.rank == 0:
        print('X, V computed')
    cat = ArrayCatalog({'Position': X, 'Velocity' : V}, BoxSize=pm.BoxSize, Nmesh=pm.Nmesh)
    kdd = KDDensity(cat).density
    cat['KDDensity'] = kdd
    cat['InitPosition'] = dynamic_model.get_code().engine.q
    cat.save(ofolder + 'dynamic/1', ('InitPosition', 'Position', 'Velocity', 'KDDensity'))
    if pm.comm.rank == 0:
        print('dynamic model created')

    #FOF
    fof = FOF(cat, linking_length=0.2, nmin=12)
    fofcat = fof.find_features(peakcolumn='KDDensity')
    fofcat['Mass'] = fofcat['Length'] * cosmo.Om0 * 27.7455 * pm.BoxSize.prod() / pm.Nmesh.prod()
    fofcat.save(ofolder+'FOF', ('CMPosition', 'CMVelocity', 'PeakPosition', 'PeakVelocity', 'Length', 'Mass'))
示例#3
0
                          abund=abund,
                          ofolder=optfolder,
                          seed=scatterp['rseed'],
                          zz=zz,
                          mexp=None,
                          cc=0,
                          stellar=False,
                          rsd=rsd,
                          truemass=False)
data_m = fof_model.make_observable(s_truth)
data_m.save(optfolder + 'datam/')

fofdata = BigFileCatalog(optfolder + 'FOFd', header='Header')
layout = pm.decompose(fofdata['PeakPosition'])
hpmesh = pm.paint(fofdata['PeakPosition'], layout=layout)
save_map(data_m.s, optfolder + 'datap', 's')
save_map(data_m.d, optfolder + 'datap', 'd')
save_map(hpmesh, optfolder + 'datap', 'mapp')

#setup MODEL
pfile = 'ics_matterpow_0.dat'
klin, plin = numpy.loadtxt(pfile, unpack=True)
pk = interpolate(klin, plin)
cosmo = Planck15.clone(Omega_cdm=0.2685, h=0.6711, Omega_b=0.049)
aa = 1 / (1 + basep['zz'])
if not rank:
    print('Redshift and Scale factor at final point are = %0.2f, %0.2f' %
          (basep['zz'], aa))

recon, hpshift, rshift = model.standard(pm=pm,
                                        fofcat=fofdata,
示例#4
0
 def save(self, path):
     save_map(self.mapp, path, 'mapp')
     save_map(self.s, path, 's')
     save_map(self.d, path, 'd')