Moved to Python3 compatible python
This commit is contained in:
parent
29f991f0d4
commit
483ff1333d
@ -1,7 +1,7 @@
|
|||||||
###
|
###
|
||||||
### BORG code is from J. Jasche
|
### BORG code is from J. Jasche
|
||||||
###
|
###
|
||||||
import StringIO
|
import io
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from numpy import *
|
from numpy import *
|
||||||
import os.path
|
import os.path
|
||||||
@ -154,9 +154,9 @@ def get_grid_values(xx,data, ranges):
|
|||||||
def get_mean_density(fdir, smin, step):
|
def get_mean_density(fdir, smin, step):
|
||||||
""" estimate ensemble mean
|
""" estimate ensemble mean
|
||||||
"""
|
"""
|
||||||
print '-'*60
|
print('-'*60)
|
||||||
print 'Get 3D ensemble mean density field'
|
print('Get 3D ensemble mean density field')
|
||||||
print '-'*60
|
print('-'*60)
|
||||||
|
|
||||||
fname0 = fdir + 'initial_density_'+str(0)+'.dat'
|
fname0 = fdir + 'initial_density_'+str(0)+'.dat'
|
||||||
fname1 = fdir + 'final_density_'+str(0)+'.dat'
|
fname1 = fdir + 'final_density_'+str(0)+'.dat'
|
||||||
@ -208,9 +208,9 @@ def get_mean_density(fdir, smin, step):
|
|||||||
def get_mean_density_fdir(fdir,init,steps):
|
def get_mean_density_fdir(fdir,init,steps):
|
||||||
""" estimate ensemble mean
|
""" estimate ensemble mean
|
||||||
"""
|
"""
|
||||||
print '-'*60
|
print('-'*60)
|
||||||
print 'Get 3D ensemble mean density field'
|
print('Get 3D ensemble mean density field')
|
||||||
print '-'*60
|
print('-'*60)
|
||||||
|
|
||||||
fname0,fname1=build_filelist(fdir)
|
fname0,fname1=build_filelist(fdir)
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ import numpy as np
|
|||||||
|
|
||||||
def cicParticles(particles, L, N):
|
def cicParticles(particles, L, N):
|
||||||
|
|
||||||
if type(N) not in [int,long]:
|
if type(N) not in [int,int]:
|
||||||
raise TypeError("N must be a numeric type")
|
raise TypeError("N must be a numeric type")
|
||||||
|
|
||||||
def shifted(i, t):
|
def shifted(i, t):
|
||||||
@ -14,7 +14,7 @@ def cicParticles(particles, L, N):
|
|||||||
|
|
||||||
i =[]
|
i =[]
|
||||||
r = []
|
r = []
|
||||||
for d in xrange(3):
|
for d in range(3):
|
||||||
q = ne.evaluate('(p%L)*N/L', local_dict={'p':particles[d], 'L':L, 'N':N })
|
q = ne.evaluate('(p%L)*N/L', local_dict={'p':particles[d], 'L':L, 'N':N })
|
||||||
o = np.empty(q.size, dtype=np.int64)
|
o = np.empty(q.size, dtype=np.int64)
|
||||||
o[:] = np.floor(q)
|
o[:] = np.floor(q)
|
||||||
|
@ -163,8 +163,8 @@ class CIC_CL(object):
|
|||||||
# 2 dimensions
|
# 2 dimensions
|
||||||
translator['ndim'] = ndim
|
translator['ndim'] = ndim
|
||||||
translator['centered'] = '1' if centered else '0'
|
translator['centered'] = '1' if centered else '0'
|
||||||
looperVariables = ','.join(['id%d' % d for d in xrange(ndim)])
|
looperVariables = ','.join(['id%d' % d for d in range(ndim)])
|
||||||
looperFor = '\n'.join(['for (int id{dim}=0; id{dim} < 2; id{dim}++) {{'.format(dim=d) for d in xrange(ndim)])
|
looperFor = '\n'.join(['for (int id{dim}=0; id{dim} < 2; id{dim}++) {{'.format(dim=d) for d in range(ndim)])
|
||||||
looperForEnd = '}' * ndim
|
looperForEnd = '}' * ndim
|
||||||
|
|
||||||
kern = pragmas + CIC_PREKERNEL.format(**translator) + (CIC_KERNEL % {'looperVariables': looperVariables, 'looperFor': looperFor, 'looperForEnd':looperForEnd})
|
kern = pragmas + CIC_PREKERNEL.format(**translator) + (CIC_KERNEL % {'looperVariables': looperVariables, 'looperFor': looperFor, 'looperForEnd':looperForEnd})
|
||||||
|
@ -27,7 +27,7 @@ def readGrafic(filename):
|
|||||||
BoxSize = delta * Nx * h
|
BoxSize = delta * Nx * h
|
||||||
|
|
||||||
checkPoint = 4*Ny*Nz
|
checkPoint = 4*Ny*Nz
|
||||||
for i in xrange(Nx):
|
for i in range(Nx):
|
||||||
checkPoint = struct.unpack("I", f.read(4))[0]
|
checkPoint = struct.unpack("I", f.read(4))[0]
|
||||||
if checkPoint != 4*Ny*Nz:
|
if checkPoint != 4*Ny*Nz:
|
||||||
raise ValueError("Invalid unformatted access")
|
raise ValueError("Invalid unformatted access")
|
||||||
@ -57,7 +57,7 @@ def writeGrafic(filename, field, BoxSize, scalefac, **cosmo):
|
|||||||
cosmo['omega_M_0'], cosmo['omega_lambda_0'], 100*cosmo['h'], checkPoint))
|
cosmo['omega_M_0'], cosmo['omega_lambda_0'], 100*cosmo['h'], checkPoint))
|
||||||
checkPoint = 4*Ny*Nz
|
checkPoint = 4*Ny*Nz
|
||||||
field = field.reshape(field.shape, order='F')
|
field = field.reshape(field.shape, order='F')
|
||||||
for i in xrange(Nx):
|
for i in range(Nx):
|
||||||
f.write(struct.pack("I", checkPoint))
|
f.write(struct.pack("I", checkPoint))
|
||||||
f.write(field[i].astype(np.float32).tostring())
|
f.write(field[i].astype(np.float32).tostring())
|
||||||
f.write(struct.pack("I", checkPoint))
|
f.write(struct.pack("I", checkPoint))
|
||||||
@ -73,7 +73,7 @@ def writeWhitePhase(filename, field):
|
|||||||
|
|
||||||
field = field.reshape(field.shape, order='F')
|
field = field.reshape(field.shape, order='F')
|
||||||
checkPoint = struct.pack("I", 4*Nx*Ny)
|
checkPoint = struct.pack("I", 4*Nx*Ny)
|
||||||
for i in xrange(Nx):
|
for i in range(Nx):
|
||||||
f.write(checkPoint)
|
f.write(checkPoint)
|
||||||
f.write(field[i].astype(np.float32).tostring())
|
f.write(field[i].astype(np.float32).tostring())
|
||||||
f.write(checkPoint)
|
f.write(checkPoint)
|
||||||
@ -87,7 +87,7 @@ def readWhitePhase(filename):
|
|||||||
|
|
||||||
checkPoint_ref = 4*Ny*Nz
|
checkPoint_ref = 4*Ny*Nz
|
||||||
|
|
||||||
for i in xrange(Nx):
|
for i in range(Nx):
|
||||||
if struct.unpack("I", f.read(4))[0] != checkPoint_ref:
|
if struct.unpack("I", f.read(4))[0] != checkPoint_ref:
|
||||||
raise ValueError("Invalid unformatted access")
|
raise ValueError("Invalid unformatted access")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user