Fixed CIC errors. Added support for CosmoPower in _cosmotool.pyx
This commit is contained in:
parent
0a28eb3e04
commit
302ed9a912
8 changed files with 230 additions and 110 deletions
|
@ -1,5 +1,5 @@
|
|||
from _cosmotool import *
|
||||
from grafic import writeGrafic, writeWhitePhase
|
||||
from grafic import writeGrafic, writeWhitePhase, readGrafic
|
||||
from borg import read_borg_vol
|
||||
|
||||
|
||||
|
@ -13,9 +13,9 @@ class SimulationBare(PySimulationBase):
|
|||
raise TypeError("Simulation object to mirror must be a PySimulationBase")
|
||||
s = args[0]
|
||||
|
||||
self.positions = s.getPositions()
|
||||
self.velocities = s.getVelocities()
|
||||
self.identifiers = s.getIdentifiers()
|
||||
self.positions = [q.copy() for q in s.getPositions()] if s.getPositions() is not None else None
|
||||
self.velocities = [q.copy() for q in s.getVelocities()] if s.getVelocities() is not None else None
|
||||
self.identifiers = s.getIdentifiers().copy() if s.getIdentifiers() is not None else None
|
||||
self.boxsize = s.getBoxsize()
|
||||
self.time = s.getTime()
|
||||
self.Hubble = s.getHubble()
|
||||
|
@ -28,7 +28,7 @@ class SimulationBare(PySimulationBase):
|
|||
def _safe_merge(a, b):
|
||||
if b:
|
||||
if a:
|
||||
a = [np.append(q, r) for q,r in zip(a,other.positions)]
|
||||
a = [np.append(q, r) for q,r in zip(a,b)]
|
||||
else:
|
||||
a = b
|
||||
return a
|
||||
|
@ -42,15 +42,15 @@ class SimulationBare(PySimulationBase):
|
|||
return a
|
||||
|
||||
|
||||
assert self.time == other.time
|
||||
assert self.Hubble == other.Hubble
|
||||
assert self.boxsize == other.boxsize
|
||||
assert self.Omega_M == other.Omega_M
|
||||
assert self.Omega_Lambda == other.Omega_Lambda
|
||||
assert self.time == other.getTime()
|
||||
assert self.Hubble == other.getHubble()
|
||||
assert self.boxsize == other.getBoxsize()
|
||||
assert self.Omega_M == other.getOmega_M()
|
||||
assert self.Omega_Lambda == other.getOmega_Lambda()
|
||||
|
||||
self.positions = _safe_merge(self.positions, other.positions)
|
||||
self.velocities = _safe_merge(self.velocities, other.velocities)
|
||||
self.identifiers = _safe_merge0(self.idenfiers, other.identifiers)
|
||||
self.positions = _safe_merge(self.positions, other.getPositions())
|
||||
self.velocities = _safe_merge(self.velocities, other.getVelocities())
|
||||
self.identifiers = _safe_merge0(self.identifiers, other.getIdentifiers())
|
||||
|
||||
def getPositions(self):
|
||||
return self.positions
|
||||
|
@ -106,7 +106,7 @@ def loadRamsesAll(basepath, snapshot_id, **kwargs):
|
|||
cpu_id = 0
|
||||
output = None
|
||||
while True:
|
||||
s = loadRamses("%s/output_%05d" % (basepath,snapshot_id), cpu_id, **kwargs)
|
||||
s = loadRamses("%s/output_%05d" % (basepath,snapshot_id), snapshot_id, cpu_id, **kwargs)
|
||||
if s == None:
|
||||
break
|
||||
if output == None:
|
||||
|
@ -115,3 +115,5 @@ def loadRamsesAll(basepath, snapshot_id, **kwargs):
|
|||
output.merge(s)
|
||||
|
||||
cpu_id += 1
|
||||
|
||||
return output
|
||||
|
|
|
@ -1,6 +1,32 @@
|
|||
import struct
|
||||
import numpy as np
|
||||
|
||||
def readGrafic(filename):
|
||||
|
||||
with file(filename, mode="rb") as f:
|
||||
p = struct.unpack("IIIIffffffffI", f.read(4*11 + 2*4))
|
||||
checkPoint0, Nx, Ny, Nz, delta, _, _, _, scalefac, omega0, omegalambda0, h, checkPoint1 = p
|
||||
if checkPoint0 != checkPoint1 or checkPoint0 != 4*11:
|
||||
raise ValueError("Invalid unformatted access")
|
||||
|
||||
a = np.empty((Nx,Ny,Nz), dtype=np.float32)
|
||||
|
||||
BoxSize = delta * Nx * h
|
||||
|
||||
checkPoint = 4*Ny*Nz
|
||||
for i in xrange(Nx):
|
||||
checkPoint = struct.unpack("I", f.read(4))[0]
|
||||
if checkPoint != 4*Ny*Nz:
|
||||
raise ValueError("Invalid unformatted access")
|
||||
|
||||
a[i, :, :] = np.fromfile(f, dtype=np.float32, count=Ny*Nz).reshape((Ny, Nz))
|
||||
|
||||
checkPoint = struct.unpack("I", f.read(4))[0]
|
||||
if checkPoint != 4*Ny*Nz:
|
||||
raise ValueError("Invalid unformatted access")
|
||||
|
||||
return a, BoxSize, scalefac, omega0, omegalambda0, h
|
||||
|
||||
def writeGrafic(filename, field, BoxSize, scalefac, **cosmo):
|
||||
|
||||
with file(filename, mode="wb") as f:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue