...
 
Commits (2)
#!/usr/bin/env python
#!/usr/bin/env python3
from __future__ import print_function
#from uns_simu import *
......@@ -27,7 +27,7 @@ class CTestunsio:
__comp = {'halo':[__1D,__3D],'gas':[__1D,__3D,__1Dgas],'stars':[__1D,__3D,__1Dstars],'disk':[__1D,__3D],'bndry':[__1D,__3D],'bulge':[__1D,__3D]}
__compNemo = { 'all':[__1D,__3D,__1Dgas] }
# -----------------------------------------------------
#
#
def __init__(self,nbody=None,seed=666,single=True,verbose=None, uns2uns=False):
self.__nbody = nbody
self.__verbose = verbose
......@@ -38,7 +38,7 @@ class CTestunsio:
self.__initSeed(self.__seed)
# -----------------------------------------------------
#
#
def __initSeed(self,seed=None):
if seed is None:
seed=self.__seed
......@@ -46,7 +46,7 @@ class CTestunsio:
np.random.seed(seed)
# -----------------------------------------------------
#
#
def __dataF(self,n):
if (self.__single):
x=np.float32(np.random.sample(n))
......@@ -54,7 +54,7 @@ class CTestunsio:
x=np.float64(np.random.sample(n))
return x
# -----------------------------------------------------
#
#
def __saveArray(self,comp,attr,dim,real=True):
if real:
......@@ -64,7 +64,7 @@ class CTestunsio:
ok=self.__unso.setArrayI(comp,attr,np.arange(self.__nbody*dim,dtype=np.int32)) # save real arrays
# -----------------------------------------------------
#
#
def saveModel(self,filename=None,unstype="gadget3",single=True):
"""
save model in requested format
......@@ -95,7 +95,7 @@ class CTestunsio:
select_comp = self.__comp # comp for gadget2 gadget3
if unstype=="nemo":
select_comp = self.__compNemo # comp for nemo
#for comp,all_array in select_comp.iteritems():
for comp,all_array in select_comp.items():
print ("[%-6s] : "%(comp),file=sys.stderr,end="")
......@@ -104,7 +104,7 @@ class CTestunsio:
dim=block_array[0]
for array in block_array[1:]:
print(" %s"%(array),file=sys.stderr, end="")
self.__saveArray(comp,array,dim,real=True) # save real
self.__saveArray(comp,array,dim,real=True) # save real
# save integer arrays
dim=self.__1Dint[0]
......@@ -121,7 +121,7 @@ class CTestunsio:
ff = tempfile.NamedTemporaryFile()
myfile = ff.name
ff.close()
if single:
outfloat="float=t"
else:
......@@ -134,11 +134,11 @@ class CTestunsio:
#sys.exit()
os.remove(self.__model_file)
self.__model_file=myfile
print("Outfile = [%s]"%(self.__model_file))
# -----------------------------------------------------
#
#
def __compareArray(self,comp,attr,dim,real=True):
if real:# float
......@@ -159,13 +159,13 @@ class CTestunsio:
sys.exit()
# -----------------------------------------------------
#
#
def __compareModel(self,unstype="gadget3",single=True):
"""
load model from disk and compare with generated values
"""
self.__initSeed() # reset random generator
if not os.path.isfile(self.__model_file):
print("File [%s] does not exist, aborting..\n"%(self.__model_file),file=sys.stderr)
sys.exit()
......@@ -198,7 +198,7 @@ class CTestunsio:
self.__unsi.close()
# -----------------------------------------------------
#
#
def testIO(self):
"""
test models snasphot that unsio knows howto dump on a file
......@@ -242,4 +242,3 @@ def process(args):
# main program
if __name__ == '__main__':
commandLine()