New python samples. New python function to write grafic files

This commit is contained in:
Guilhem Lavaux 2014-06-01 15:32:15 +02:00
parent 5d3b56bfcb
commit 8258bd0fe9
4 changed files with 165 additions and 0 deletions

View file

@ -1,4 +1,5 @@
from _cosmotool import *
from grafic import writeGrafic
from borg import read_borg_vol

View file

@ -0,0 +1,24 @@
import struct
import numpy as np
def writeGrafic(filename, field, BoxSize, scalefac, **cosmo):
with file(filename, mode="wb") as f:
checkPoint = 4*11
Nx,Ny,Nz = field.shape
delta = BoxSize/Nx
bad = 0.0
f.write(struct.pack("IIIIffffffffI", checkPoint,
Nx, Ny, Nz,
delta,
bad, bad, bad,
scalefac,
cosmo['omega_M_0'], cosmo['omega_lambda_0'], 100*cosmo['h'], checkPoint))
checkPoint = 4*Ny*Nz
for i in xrange(Nx):
f.write(struct.pack("I", checkPoint))
f.write(field[i].astype(np.float32).tostring())
f.write(struct.pack("I", checkPoint))