hmesh['pnn'] = tools.paintnn(hposd, bs, ncp) hmesh['target'] = hmesh['pnn'].copy() print('All the mesh have been generated for seed = %d'%seed) #Create training voxels ftlist = [mesh[i].copy() for i in ftname] ftlistpad = [np.pad(i, pad, 'wrap') for i in ftlist] targetmesh = hmesh['target'] targetmesh[targetmesh > 1] = 1 ncube = int(ncp/cube_size) inp = dtools.splitvoxels(ftlistpad, cube_size=cube_sizeft, shift=cube_size, ncube=ncube) yinp = dtools.splitvoxels(targetmesh, cube_size=cube_size, shift=cube_size, ncube=ncube) recp = sess.run(output, feed_dict={xx:inp, yy:yinp}) mesh['predict'] = dtools.uncubify(recp[:,:,:,:,0], shape) meshes[seed] = [mesh, hmesh] print('All the predictions have been generated for seed = %d'%seed) ############################## ##Power spectrum kk = tools.fftk(shape, bs) kmesh = sum(i**2 for i in kk)**0.5 fig, ax = plt.subplots(1, 2, figsize = (10, 4)) for seed in seeds: predict, hpmeshd = meshes[seed][0]['predict'], meshes[seed][1]['target'], k, pkpred = tools.power(predict/predict.mean(), boxsize=bs, k=kmesh)
hmesh['pnnsat'] = tools.paintnn(hposd[galtype], bs, ncp) hmesh['pnncen'] = tools.paintnn(hposd[~galtype], bs, ncp) print('All the mesh have been generated for seed = %d'%seed) #Create training voxels ftlist = [mesh[i].copy() for i in ftname] ftlistpad = [np.pad(i, pad, 'wrap') for i in ftlist] targetmesh = [hmesh['pnncen'], hmesh['pnnsat']] ntarget = len(targetmesh) ncube = int(ncp/cube_size) inp = dtools.splitvoxels(ftlistpad, cube_size=cube_sizeft, shift=cube_size, ncube=ncube) satmesh,cenmesh, rates = sess.run([samplesat, prediction, rate], feed_dict={input:inp, keepprob:1}) mesh['predictsat'] = dtools.uncubify(satmesh[:,:,:,:,0], [nc,nc,nc]) mesh['predictcen'] = dtools.uncubify(cenmesh[:,:,:,:,0], [nc,nc,nc]) mesh['predict'] = mesh['predictcen'] + mesh['predictsat'] mesh['rates'] = dtools.uncubify(rates[:,:,:,:,0], [nc,nc,nc]) meshes[seed] = [mesh, hmesh] print('Number of predicted & true satellites = ', satmesh.sum(), hmesh['pnnsat'].sum()) ############################## ##Power spectrum kk = tools.fftk(shape, bs) kmesh = sum(i**2 for i in kk)**0.5 fig, ax = plt.subplots(2, 3, figsize = (12, 8)) for seed in tseeds:
meshs, meshf, meshd = session.run([linmesh, final, samples]) title = session.run([loss, chisq, prior, grad]) np.save(optfolder + '/init.f4', meshs) dg.makefig(literals['truemeshes'], [meshs, meshf, meshd], optfolder+'%s.png'%('init'), boxsize=bs, title='%s'%title) optimizer.minimize(session, loss_callback=lcallback, fetches=[[[loss, chisq, prior, grad], [linmesh, final, samples]]]) meshs, meshf, meshd = session.run([linmesh, final, samples]) title = session.run([loss, chisq, prior, grad]) reconsplit[ii] = meshs np.save(optfolder + '/recon.f4', meshs) dg.makefig(literals['truemeshes'], [meshs, meshf, meshd], optfolder+'%s.png'%('recon'), boxsize=bs, title='%s'%title) initval = dtools.uncubify(np.stack(reconsplit, axis=0), [nc,nc,nc]) recong = rmods.graphhposft1(config, modpath, data, pad, maxiter=maxiter, gtol=gtol, anneal=anneal, resnorm=resnorm) losses = [] literals = {'losses':losses, 'truemeshes':truemeshes, 'bs':bs, 'nc':nc} tstart = time() lcallback = lambda x: loss_callback(x, literals=literals, nprint=nprint, nsave=nsave, maxiter=maxiter, t0=tstart) # with tf.Session(graph=recong) as session: g = session.graph session.run(tf.global_variables_initializer()) linmesh = g.get_tensor_by_name("linmesh:0") samples = tf.squeeze(g.get_tensor_by_name("samples:0")) final = g.get_tensor_by_name("final:0") optimizer = g.get_collection_ref('opt')[0] loss = g.get_tensor_by_name('loss:0')
plt.close() losses.append(l) shape = (nc, nc, nc) recon = sess.run(xopt) print(recon) plt.figure() im = plt.imshow(recon[0, :, :, :, 0].sum(axis=0)) plt.colorbar(im) plt.savefig('./figs/n%02d/recon2single%s.png' % (numd * 1e4, suff)) print(recon.mean(), recon.std()) outtruth = sess.run(output, feed_dict={xx: cube_features, yy: cube_target}) outrecon = sess.run(output, feed_dict={xx: recon, yy: cube_target}) recon = dtools.uncubify(recon[:, 2:34, 2:34, 2:34, 0], shape) outtruth = dtools.uncubify(outtruth[:, :, :, :, 0], shape) outrecon = dtools.uncubify(outrecon[:, :, :, :, 0], shape) reconmapp = dtools.uncubify(cube_target[:, :, :, :, 0], shape) recontruth = dtools.uncubify(cube_features[:, 2:34, 2:34, 2:34, 0], shape) def getim(ar, axis=0): #return ar[0, :, :, :, 0].sum(axis=axis) return ar[:, :, :].sum(axis=axis) fig, axar = plt.subplots(3, 3, figsize=(18, 18)) fsize = 16
#Create training voxels ftlist = [mesh[i].copy() for i in ftname] ftlistpad = [np.pad(i, pad, 'wrap') for i in ftlist] targetmesh = hmesh['target'] targetmesh[targetmesh > 1] = 1 for size in test_sizes: ncube = int(ncp / size) print(size, ncube) inp = dtools.splitvoxels(ftlistpad, cube_size=size + 2 * pad, shift=size, ncube=ncube) recp = sess.run(prediction, feed_dict={input: inp, keepprob: 1}) mesh['predict%03d' % size] = dtools.uncubify(recp[:, :, :, :, 0], shape) meshes[seed] = [mesh, hmesh] print('Prediction done for seed = %d' % seed) ############################## ##Power spectrum kk = tools.fftk(shape, bs) kmesh = sum(i**2 for i in kk)**0.5 lss = ['-', '--', ':', '-.'] fig, ax = plt.subplots(1, 2, figsize=(10, 4)) for ss, seed in enumerate(seeds): hpmeshd = meshes[seed][1]['target'] k, pkhd = tools.power(hpmeshd / hpmeshd.mean(), boxsize=bs, k=kmesh)