Exemplo n.º 1
0
    sigma = 1**0.5
    nprint, nsave = 20, 40
    R0s = [4, 2, 1, 0]

    #output folder
    ofolder = './saved/L%04d_N%04d_S%04d_n%02d/' % (bs, nc, seed, numd * 1e4)
    if anneal: ofolder += 'anneal%d/' % len(R0s)
    else: ofolder += '/noanneal/'
    ofolder = ofolder + suffix
    try:
        os.makedirs(ofolder)
    except:
        pass
    print('Output in ofolder = \n%s' % ofolder)
    pkfile = '../flowpm/Planck15_a1p00.txt'
    config = Config(bs=bs, nc=nc, seed=seed, pkfile=pkfile)
    #hgraph = dg.graphlintomod(config, modpath, pad=pad, ny=1)
    print('Diagnostic graph constructed')
    fname = open(ofolder + '/README', 'w', 1)
    fname.write('Using module from path - %s n' % modpath)
    fname.close()

    #Generate Data
    truth = tools.readbigfile(dpath + ftype % (bs, nc, seed, step) + 'mesh/s/')
    print(truth.shape)
    final = tools.readbigfile(dpath + ftype % (bs, nc, seed, step) + 'mesh/d/')
    print(final.shape)
    hposall = tools.readbigfile(dpath + ftype % (bs, ncf, seed, stepf) +
                                'FOF/PeakPosition/')[1:]
    hposd = hposall[:num].copy()
    data = tools.paintnn(hposd, bs, nc)
Exemplo n.º 2
0
import numpy as np
import numpy
import os, sys
os.environ["CUDA_VISIBLE_DEVICES"] = "0"
from time import time
import matplotlib.pyplot as plt

import tensorflow as tf

from background import *
import tfpm
import tfpmfuncs as tfpf
from tfpmconfig import Config

pkfile = './Planck15_a1p00.txt'
config = Config(bs=400, nc=128, seed=100, pkfile=pkfile)
bs, nc = config['boxsize'], config['nc']
grid = bs / nc * np.indices((nc, nc, nc)).reshape(3, -1).T.astype(np.float32)
config['grid'] = grid

tf.reset_default_graph()

tf.reset_default_graph()


def pm(config, verbose=True):
    g = tf.Graph()
    with g.as_default():
        linear = tfpm.linfield(config, name='linear')
        icstate = tfpm.lptinit(linear, config, name='icstate')
        fnstate = tfpm.nbody(icstate, config, verbose=verbose, name='fnstate')
Exemplo n.º 3
0
    ax[0, 0].legend()
    for axis in ax.flatten():
        axis.grid(which='both', lw=0.5, color='gray')
    fig.suptitle(title)
    fig.tight_layout(rect=[0, 0, 1, 0.95])
    fig.savefig(fname)


#######################################################
if __name__ == "__main__":

    bs, nc = 400, 128
    seed = 100
    step = 5

    config = Config(bs=bs, nc=nc, seed=seed)
    modpath = '/home/chmodi/Projects/galmodel/code/models/n10/pad2-logistic/module/1546529135/likelihood'

    truelin = tools.readbigfile(dpath + ftype % (bs, nc, seed, step) +
                                'mesh/s/').astype(np.float32)
    truefin = tools.readbigfile(dpath + ftype % (bs, nc, seed, step) +
                                'mesh/d/').astype(np.float32)
    truedata = dtools.gethalomesh(bs, nc, seed).astype(np.float32)

    g = graphlintomod(config, modpath, pad=2, ny=1)

    reconpath = './saved/L0400_N0128_S0100_n10/noanneal/nc3norm_std/'
    for i in range(0, 100, 25):
        print(i)
        mesh = np.load(reconpath + 'iter%d.f4.npy' % i).reshape(nc, nc, nc)
        savehalofig([truelin, truefin, truedata],
Exemplo n.º 4
0
    anneal = False
    voxels = True
    cube_size = int(64)
    R0s = [4, 2, 1, 0]

    #output folder
    ofolder = './saved/L%04d_N%04d_S%04d_n%02d/'%(bs, nc, seed, numd*1e4)
    if anneal : ofolder += 'anneal%d/'%len(R0s)
    elif voxels: ofolder += 'voxel%d/'%int(cube_size)
    else: ofolder += '/vanilla/'
    ofolder = ofolder + suffix
    try: os.makedirs(ofolder)
    except: pass
    print('Output in ofolder = \n%s'%ofolder)
    pkfile = '../flowpm/Planck15_a1p00.txt'
    config = Config(bs=bs, nc=nc, seed=seed, pkfile=pkfile)


    #Generate Data
    truth = tools.readbigfile(dpath + ftype%(bs, nc, seed, step) + 'mesh/s/')
    print(truth.shape)
    final = tools.readbigfile(dpath + ftype%(bs, nc, seed, step) + 'mesh/d/')
    print(final.shape)
    hposall = tools.readbigfile(dpath + ftype%(bs, ncf, seed, stepf) + 'FOF/PeakPosition/')[1:]    
    hposd = hposall[:num].copy()
    data = tools.paintnn(hposd, bs, nc)

    truemeshes = [truth, final, data]
    np.save(ofolder + '/truth.f4', truth)
    np.save(ofolder + '/final.f4', final)
    np.save(ofolder + '/data.f4', data)
Exemplo n.º 5
0
tf.reset_default_graph()


def linfieldlocal(white, config, name='linfield'):
    '''generate a linear field with a given linear power spectrum'''

    bs, nc = config['boxsize'], config['nc']
    whitec = tfpf.r2c3d(white, norm=nc**3)
    lineark = tf.multiply(whitec, (pkmesh / bs**3)**0.5)
    linear = tfpf.c2r3d(lineark, norm=nc**3, name=name)
    return linear


#

config = Config(bs=100, nc=32, seed=200, pkfile=pkfile)
bs, nc = config['boxsize'], config['nc']
kmesh = sum(kk**2 for kk in config['kvec'])**0.5
pkmesh = config['ipklin'](kmesh)
print(bs, nc)

xx = tf.placeholder(tf.float32, (nc, nc, nc), name='white')
whitec = tfpf.r2c3d(xx, norm=nc**3)
lineark = tf.multiply(whitec, (pkmesh / bs**3)**0.5)
linear = tfpf.c2r3d(lineark, norm=nc**3, name='linear')
icstate = tfpm.lptinit(linear, config, name='icstate')
fnstate = tfpm.nbody(icstate, config, verbose=False, name='fnstate')
final = tf.zeros_like(linear)
final = tfpf.cic_paint(final,
                       fnstate[0],
                       boxsize=config['boxsize'],