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