diff --git a/python/cosmotool/__init__.py b/python/cosmotool/__init__.py index ebac8cb..162b5e0 100644 --- a/python/cosmotool/__init__.py +++ b/python/cosmotool/__init__.py @@ -1,5 +1,5 @@ from _cosmotool import * -from grafic import writeGrafic +from grafic import writeGrafic, writeWhitePhase from borg import read_borg_vol diff --git a/python/cosmotool/grafic.py b/python/cosmotool/grafic.py index f43023f..f863167 100644 --- a/python/cosmotool/grafic.py +++ b/python/cosmotool/grafic.py @@ -22,3 +22,18 @@ def writeGrafic(filename, field, BoxSize, scalefac, **cosmo): f.write(field[i].astype(np.float32).tostring()) f.write(struct.pack("I", checkPoint)) + +def writeWhitePhase(filename, field): + + with file(filename, mode="wb") as f: + Nx,Ny,Nz = field.shape + + checkPoint = 4*4 + f.write(struct.pack("IIIIII", checkPoint, Nx, Ny, Nz, 0, checkPoint)) + + checkPoint = struct.pack("I", 4*Ny*Nz) + for i in xrange(Nx): + f.write(checkPoint) + f.write(field[i].astype(np.float32).tostring()) + f.write(checkPoint) + diff --git a/python_sample/icgen/borgicgen.py b/python_sample/icgen/borgicgen.py index 2dd27d6..865eeb6 100644 --- a/python_sample/icgen/borgicgen.py +++ b/python_sample/icgen/borgicgen.py @@ -62,3 +62,4 @@ def write_icfiles(*generated_ic, **cosmo): ct.writeGrafic("ic_velc%s" % c, vel[i].reshape((N,N,N)), L, a_ic, **cosmo) ct.writeGrafic("ic_deltab", density, L, a_ic, **cosmo) + ct.writeWhitePhase("white.dat", density)