Commit b2542a24 authored by LAMBERT Jean-charles's avatar LAMBERT Jean-charles
Browse files

still fighting py2 vs py3

parent 7cb1bf79
...@@ -15,7 +15,7 @@ for i in np.arange(30): ...@@ -15,7 +15,7 @@ for i in np.arange(30):
q.put(i) q.put(i)
def f(x): def f(x):
global zz global zz
try: try:
a=q.get() # get one more element a=q.get() # get one more element
zz = zz+1 zz = zz+1
...@@ -26,8 +26,7 @@ def f(x): ...@@ -26,8 +26,7 @@ def f(x):
if __name__ == '__main__': if __name__ == '__main__':
p = Pool(5) p = Pool(5)
a=p.map(f,np.arange(30) ) a=list(p.map(f,np.arange(30) ))
print ">>>",a print ">>>",a
print "zz=",zz print "zz=",zz
...@@ -57,7 +57,7 @@ def process(args): ...@@ -57,7 +57,7 @@ def process(args):
sys.exit() sys.exit()
for i in range(data.size/3): for i in range(data.size/3):
print (' '.join(map(str,data[:,i]))) print (' '.join(list(map(str,data[:,i]))))
# ----------------------------------------------------- # -----------------------------------------------------
......
#!/usr/bin/env python #!/usr/bin/env python
import sys import sys
from uns_simu import * import unsio
from simulations.ccod import * from unsiotools.uns_simu import *
from unsiotools.simulations import csnapshot
from unsiotools.simulations import ccod
import argparse import argparse
import numpy as np
sys.path=['/home/jcl/works/GIT/uns_projects/py/modules/','/home/jcl/works/GIT/uns_projects/py/modules/simulations']+sys.path
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# commandLine, parse the command line # commandLine, parse the command line
def commandLine(): def commandLine():
dbname=None dbname=None
ncores=None ncores=None
...@@ -19,7 +20,9 @@ def commandLine(): ...@@ -19,7 +20,9 @@ def commandLine():
formatter_class=argparse.ArgumentDefaultsHelpFormatter) formatter_class=argparse.ArgumentDefaultsHelpFormatter)
# options # options
parser.add_argument('simname', help='Simulation name') parser.add_argument('simname', help='Simulation name')
parser.add_argument('haloN', help='Selected component') parser.add_argument('input', help='UNS input file')
parser.add_argument('output', help='Nemo output file')
parser.add_argument('haloN', help='Select halo number (1 or 2)',type=int)
parser.add_argument('--dbname',help='UNS database file name', default=dbname) parser.add_argument('--dbname',help='UNS database file name', default=dbname)
parser.add_argument('--verbose',help='verbose mode', default=False) parser.add_argument('--verbose',help='verbose mode', default=False)
...@@ -33,9 +36,57 @@ def commandLine(): ...@@ -33,9 +36,57 @@ def commandLine():
# ----------------------------------------------------- # -----------------------------------------------------
# process, is the core function # process, is the core function
def process(args): def process(args):
pass cod=ccod.CCod(args.simname,verbose_debug=args.verbose)
if cod.isMultipleHalo():
print("Muliple halo = ",cod.isMultipleHalo())
uns_snap=csnapshot.CSnapshot(args.input,"halo")
ok = uns_snap.nextFrame()
if ok:
select="halo"
ok,timex=uns_snap.getData("time")
print("timex=",timex,type(timex))
ok,pos=uns_snap.getData(select,"pos")
ok,mass=uns_snap.getData(select,"mass")
ok,vel =uns_snap.getData(select,"vel")
ok,id=uns_snap.getData(select,"id")
ok,mass,pos,vel = cod.getExtractHalo(id,mass,pos,vel,args.haloN)
print(mass,pos,vel)
unso=unsio.CunsOut(args.output,"nemo")
unso.setValueF("time",timex)
unso.setArrayF("all","pos",pos)
unso.setArrayF("all","mass",mass)
unso.setArrayF("all","vel",vel)
unso.save()
else:
print("Unable to load data from [%s]"%(agrs.snapshot))
else :
print("No multiple halo detected for simulation [%s]"%(args.simname))
#
# ----
#
def extractHalo(self,id,mass,pos,vel):
id_sort=np.argsort(id) # sort according to ID order
offset=0
myidsort=np.zeros(1)
if self.__halo_N==1: # first halo
mylast=self.__halo_part[0]
myidsort = id_sort[0:mylast]
else : # second halo
mylast=self.__halo_part[1]
offset = self.__halo_part[0]+mylast
myidsort = id_sort[self.__halo_part[0]:offset]
#print("myidsort : ",myidsort,mylast,self.__halo_part)
pos = np.reshape(pos,(-1,3)) # reshape pos to nbody,3
pos = np.reshape(pos[myidsort],-1) # select ids
vel = np.reshape(vel,(-1,3)) # reshape vel to nbody,3
vel = np.reshape(vel[myidsort],-1) # select ids
return True,mass[myidsort],pos,vel
# ----------------------------------------------------- # -----------------------------------------------------
# main program # main program
......
...@@ -193,7 +193,7 @@ class C2dplot: ...@@ -193,7 +193,7 @@ class C2dplot:
try: try:
f=open(t_file,"r") f=open(t_file,"r")
while True: while True:
atime=map(np.float,(f.readline().split())) atime=list(map(np.float,(f.readline().split())))
if (len(atime)>0): if (len(atime)>0):
if (atime[0]-0.001)<time and (atime[0]+0.001)>time: if (atime[0]-0.001)<time and (atime[0]+0.001)>time:
f.close() f.close()
...@@ -540,13 +540,14 @@ class C2dplot: ...@@ -540,13 +540,14 @@ class C2dplot:
if ok: if ok:
# get data # get data
ok,rho=uns.getData(comp,"rho") # rho ok,rho=uns.getData(comp,"rho") # rho
if not ok: if not ok:
rho=np.ones(pos.size/3) rho=np.ones(int(pos.size/3))
# get data # get data
ok,mass=uns.getData(comp ,"mass") # gas density ok,mass=uns.getData(comp ,"mass") # gas density
if not ok: if not ok:
mass=np.ones(pos.size/3) mass=np.ones(int(pos.size/3))
# reshape array in x,y,z arrays # reshape array in x,y,z arrays
pos=np.reshape(pos,(-1,3)) # pos reshaped in a 2D array [nbody,3] pos=np.reshape(pos,(-1,3)) # pos reshaped in a 2D array [nbody,3]
...@@ -777,7 +778,6 @@ class C2dplot: ...@@ -777,7 +778,6 @@ class C2dplot:
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# commandLine, parse the command line # commandLine, parse the command line
def commandLine(): def commandLine():
import argparse import argparse
# help # help
parser = argparse.ArgumentParser(description="Display 2D image from UNS data", parser = argparse.ArgumentParser(description="Display 2D image from UNS data",
...@@ -812,7 +812,7 @@ def commandLine(): ...@@ -812,7 +812,7 @@ def commandLine():
args = parser.parse_args() args = parser.parse_args()
if args.cmap=="show": # show colormap if args.cmap=="show": # show colormap
import general.ctools as ct import unsiotools.general.ctools as ct
ct.displayColormap() ct.displayColormap()
sys.exit() sys.exit()
...@@ -845,7 +845,9 @@ def process(args): ...@@ -845,7 +845,9 @@ def process(args):
# else: # else:
# print ("[%s] is not a UNS snapshot ..."%(simname)) # print ("[%s] is not a UNS snapshot ..."%(simname))
except Exception as x : except Exception as x :
import traceback
print (x,file=sys.stderr) print (x,file=sys.stderr)
traceback.print_exc(file=sys.stdout)
except KeyboardInterrupt: except KeyboardInterrupt:
sys.exit() sys.exit()
...@@ -853,4 +855,4 @@ def process(args): ...@@ -853,4 +855,4 @@ def process(args):
# ----------------------------------------------------- # -----------------------------------------------------
# main program # main program
if __name__ == '__main__': if __name__ == '__main__':
commandLine() commandLine()
...@@ -20,7 +20,6 @@ import signal ...@@ -20,7 +20,6 @@ import signal
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
# #
# ---- # ----
# #
...@@ -35,7 +34,7 @@ class CCod: ...@@ -35,7 +34,7 @@ class CCod:
__cod_file_base=None __cod_file_base=None
__ctree_threshold=10000 __ctree_threshold=10000
__fastcod=True __fastcod=True
__halo_part=np.zeros(10) __halo_part=np.zeros(10,dtype=int)
__is_multiple_halo=False __is_multiple_halo=False
__ok_halo_N=False __ok_halo_N=False
__halo_comp=None __halo_comp=None
...@@ -357,6 +356,12 @@ class CCod: ...@@ -357,6 +356,12 @@ class CCod:
# #
# ---- # ----
# #
def getExtractHalo(self,id,mass,pos,vel, halo_id):
self.__halo_N=halo_id
return self.__extractHalo(id,mass,pos,vel)
#
# ----
#
def __extractHalo(self,id,mass,pos,vel): def __extractHalo(self,id,mass,pos,vel):
id_sort=np.argsort(id) # sort according to ID order id_sort=np.argsort(id) # sort according to ID order
offset=0 offset=0
...@@ -368,7 +373,6 @@ class CCod: ...@@ -368,7 +373,6 @@ class CCod:
mylast=self.__halo_part[1] mylast=self.__halo_part[1]
offset = self.__halo_part[0]+mylast offset = self.__halo_part[0]+mylast
myidsort = id_sort[self.__halo_part[0]:offset] myidsort = id_sort[self.__halo_part[0]:offset]
#print("myidsort : ",myidsort,mylast,self.__halo_part)
pos = np.reshape(pos,(-1,3)) # reshape pos to nbody,3 pos = np.reshape(pos,(-1,3)) # reshape pos to nbody,3
pos = np.reshape(pos[myidsort],-1) # select ids pos = np.reshape(pos[myidsort],-1) # select ids
vel = np.reshape(vel,(-1,3)) # reshape vel to nbody,3 vel = np.reshape(vel,(-1,3)) # reshape vel to nbody,3
...@@ -417,11 +421,8 @@ class CCod: ...@@ -417,11 +421,8 @@ class CCod:
print("\n\n!!! File [%s] does not exist !!!!\n\n"%(model_param),file=sys.stderr) print("\n\n!!! File [%s] does not exist !!!!\n\n"%(model_param),file=sys.stderr)
self.__halo_part=self.__halo_part[np.where(self.__halo_part>0)] self.__halo_part=self.__halo_part[np.where(self.__halo_part>0)]
if self.__vdebug: if self.__vdebug:
print (self.__halo_part,self.__halo_part.size,file=sys.stderr) print (">>> ",self.__halo_part,self.__halo_part.size,file=sys.stderr)
return ok return ok
# #
# ---- # ----
# Compute mering time between two halos galaxy # Compute mering time between two halos galaxy
...@@ -581,9 +582,9 @@ class CCod: ...@@ -581,9 +582,9 @@ class CCod:
f=open(cod_file,"r") f=open(cod_file,"r")
try: try:
while True: while True:
tcxv=map(np.float64,(f.readline().split())) tcxv=list(map(np.float64,(f.readline().split())))
#print ("TCXV =",n,tcxv,len(tcxv)) #print ("TCXV =",n,tcxv,len(tcxv))
if (len(tcxv)>0): if (len(tcxv)>0):
atime=tcxv[0] atime=tcxv[0]
if (atime-0.001)<time and (atime+0.001)>time: if (atime-0.001)<time and (atime+0.001)>time:
return True,tcxv return True,tcxv
......
...@@ -3,7 +3,7 @@ from __future__ import print_function ...@@ -3,7 +3,7 @@ from __future__ import print_function
from ..uns_simu import * from ..uns_simu import *
from .csnapshot import * from .csnapshot import *
from .cfalcon import * from .cfalcon import *
from .ctree import * from .ctree import *
from multiprocessing import Process, Lock,Pool from multiprocessing import Process, Lock,Pool
import multiprocessing import multiprocessing
...@@ -209,7 +209,7 @@ class CCom: ...@@ -209,7 +209,7 @@ class CCom:
xx=f.readline() xx=f.readline()
if (len(xx)>0): if (len(xx)>0):
tcxv.append( np.float64(xx)) tcxv.append( np.float64(xx))
tcxv.append(map(np.float64,(f.readline().split()))) tcxv.append(list(map(np.float64,(f.readline().split()))))
if (len(tcxv)>0): if (len(tcxv)>0):
atime=tcxv[0] atime=tcxv[0]
read_index=tcxv[1][0] read_index=tcxv[1][0]
......
...@@ -517,7 +517,7 @@ class CInert: ...@@ -517,7 +517,7 @@ class CInert:
try: try:
f=open(t_file,"r") f=open(t_file,"r")
while True: while True:
atime=map(np.float,(f.readline().split())) atime=list(map(np.float,(f.readline().split())))
if (len(atime)>0): if (len(atime)>0):
if (atime[0]-0.001)<time and (atime[0]+0.001)>time: if (atime[0]-0.001)<time and (atime[0]+0.001)>time:
f.close() f.close()
......
...@@ -151,7 +151,7 @@ class CMovie: ...@@ -151,7 +151,7 @@ class CMovie:
try: try:
f=open(t_file,"r") f=open(t_file,"r")
while True: while True:
atime=map(np.float,(f.readline().split())) atime=list(map(np.float,(f.readline().split())))
if (len(atime)>0): if (len(atime)>0):
if (atime[0]-0.001)<time and (atime[0]+0.001)>time: if (atime[0]-0.001)<time and (atime[0]+0.001)>time:
f.close() f.close()
...@@ -309,7 +309,7 @@ class CMovie: ...@@ -309,7 +309,7 @@ class CMovie:
try: try:
f=open(t_file,"r") f=open(t_file,"r")
while True: while True:
atime=map(np.float,(f.readline().split())) atime=list(map(np.float,(f.readline().split())))
if (len(atime)>0): if (len(atime)>0):
if (atime[0]-0.001)<time and (atime[0]+0.001)>time: if (atime[0]-0.001)<time and (atime[0]+0.001)>time:
f.close() f.close()
......
#!/usr/bin/python #!/usr/bin/env python
from __future__ import print_function from __future__ import print_function
from ..uns_simu import * from ..uns_simu import *
...@@ -76,7 +76,7 @@ class CPlotInert: ...@@ -76,7 +76,7 @@ class CPlotInert:
f.readline() #skip time f.readline() #skip time
icut=0 icut=0
#try: #try:
myline=map(np.float,(f.readline().split())) myline=list(map(np.float,(f.readline().split())))
#print(myline) #print(myline)
lambda1=myline[10] lambda1=myline[10]
lambda2=myline[11] lambda2=myline[11]
...@@ -117,13 +117,20 @@ class CPlotInert: ...@@ -117,13 +117,20 @@ class CPlotInert:
#!!gs = gridspec.GridSpec(1, 2,wspace=0,hspace=0,width_ratios=[2,2],height_ratios=[1,1])#height_ratios=h,width_ratios=w) #!!gs = gridspec.GridSpec(1, 2,wspace=0,hspace=0,width_ratios=[2,2],height_ratios=[1,1])#height_ratios=h,width_ratios=w)
#print(gs.get_width_ratios(),gs.get_height_ratios(),gs.get_grid_positions(fig)) #print(gs.get_width_ratios(),gs.get_height_ratios(),gs.get_grid_positions(fig))
#!!fig.suptitle("%s %s"%(self.__simname,self.__component)) #!!fig.suptitle("%s %s"%(self.__simname,self.__component))
import os
allres=sorted(glob.glob(self.__dir_moi+"/inertia_*")) allres=sorted(glob.glob(self.__dir_moi+"/inertia_*"))
# keep only directories
allresdir=[]
for d in allres:
if os.path.isdir(d):
allresdir.append(d)
fig,axes = plt.subplots(ncols=len(allres),sharey=False,figsize=(12, 6))#gridspec_kw={'width_ratios': [2, 2]})
fig,axes = plt.subplots(ncols=len(allresdir),sharey=False,figsize=(12, 6))#gridspec_kw={'width_ratios': [2, 2]})
fig.suptitle("%s %s"%(self.__simname,self.__component)) fig.suptitle("%s %s"%(self.__simname,self.__component))
n=0 n=0
for res in allres: for res in allresdir:
#ax = plt.subplot(gs[0,n]) #ax = plt.subplot(gs[0,n])
ax= axes[n] ax= axes[n]
ax.set_xlabel("Gyears") ax.set_xlabel("Gyears")
......
...@@ -219,7 +219,7 @@ class CRectify: ...@@ -219,7 +219,7 @@ class CRectify:
try: try:
f=open(eigen_file,"r") f=open(eigen_file,"r")
while True: while True:
tce=map(np.float64,(f.readline().split())) tce=list(map(np.float64,(f.readline().split())))
if (len(tce)>0): if (len(tce)>0):
atime=tce[0] atime=tce[0]
if (atime-0.001)<time and (atime+0.001)>time: if (atime-0.001)<time and (atime+0.001)>time:
...@@ -355,7 +355,7 @@ class CRectify: ...@@ -355,7 +355,7 @@ class CRectify:
f=open(rect_file,"r") f=open(rect_file,"r")
try: try:
while True: while True:
data=map(np.float64,(f.readline().split())) data=list(map(np.float64,(f.readline().split())))
#print ("DATA =",n,data,len(data)) #print ("DATA =",n,data,len(data))
if (len(data)>0): if (len(data)>0):
atime=data[0] atime=data[0]
......
...@@ -152,10 +152,10 @@ class CSnapshot: ...@@ -152,10 +152,10 @@ class CSnapshot:
if type==2: # array if type==2: # array
ret_data = np.append(ret_data,data) ret_data = np.append(ret_data,data)
else: else:
ret_data = data[0] ret_data = data
else: else:
status=0 # one component missing status=0 # one component missing
if self.__vdebug: if self.__vdebug and type==2:
print ("ok=",ok," data=",data.size," ret_data=",ret_data.size) print ("ok=",ok," data=",data.size," ret_data=",ret_data.size)
return status,ret_data return status,ret_data
# #
...@@ -173,13 +173,15 @@ class CSnapshot: ...@@ -173,13 +173,15 @@ class CSnapshot:
# proceed __uns.getValue() # proceed __uns.getValue()
if tab_value_F.count(comp_value) > 0: if tab_value_F.count(comp_value) > 0:
ok,ret_data[0]=self.__uns.getValueF(comp_value) ok,ret_data[0]=self.__uns.getValueF(comp_value)
data=float(ret_data[0])
else: else:
if tab_value_I.count(comp_value) > 0: if tab_value_I.count(comp_value) > 0:
ok,ret_data[0]=self.__uns.getValueI(comp_value) ok,ret_data[0]=self.__uns.getValueI(comp_value)
data=int(ret_data[0])
#ret_data[0]=data #ret_data[0]=data
if self.__vdebug: if self.__vdebug:
print ("ok,data",ok,data) print ("ok,data",ok,data)
return ok,1,ret_data return ok,1,data
else: else:
if tag != "id": if tag != "id":
ok,data=self.__uns.getArrayF(comp_value,tag) ok,data=self.__uns.getArrayF(comp_value,tag)
...@@ -216,7 +218,7 @@ class CSnapshot: ...@@ -216,7 +218,7 @@ class CSnapshot:
if com: # resquest com if com: # resquest com
ok,mass=self.getData(select,"mass") # get mass ok,mass=self.getData(select,"mass") # get mass
if not ok: # no mass if not ok: # no mass
mass=np.ones(pos.size/3) # fake mass mass=np.ones(int(pos.size/3)) # fake mass
cxv=self.center(pos,None,mass,True) # centering cxv=self.center(pos,None,mass,True) # centering
# reshape pos 1d array to 2d array [nbody,3] # reshape pos 1d array to 2d array [nbody,3]
pos2d=np.reshape(pos,(-1,3)) pos2d=np.reshape(pos,(-1,3))
......
...@@ -138,7 +138,7 @@ def setup_package(): ...@@ -138,7 +138,7 @@ def setup_package():
platforms=["Linux", "Mac OS-X", "Unix"], platforms=["Linux", "Mac OS-X", "Unix"],
python_requires='>=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*', python_requires='>=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*',
package_dir={'':'py'}, # all packages are under 'py' directory package_dir={'':'py'}, # all packages are under 'py' directory
packages=['unsiotools', 'unsiotools/simulations'], packages=['unsiotools', 'unsiotools/simulations','unsiotools/general'],
cmdclass={'build_py': build_py}, cmdclass={'build_py': build_py},
py_modules=['unsiotools/py_unstools'], py_modules=['unsiotools/py_unstools'],
ext_modules = [ ext_modules = [
...@@ -175,6 +175,9 @@ def setup_package(): ...@@ -175,6 +175,9 @@ def setup_package():
os.environ['NEMO']+'/usr/dehnen/falcON/lib' ] os.environ['NEMO']+'/usr/dehnen/falcON/lib' ]
) )
], ],
scripts=[
'py/mains/uns_extract_halo.py',
],
entry_points={ entry_points={
"console_scripts": [ "console_scripts": [
"uns_2dplot.py = unsiotools.simulations.c2dplot:commandLine", "uns_2dplot.py = unsiotools.simulations.c2dplot:commandLine",
...@@ -187,8 +190,8 @@ def setup_package(): ...@@ -187,8 +190,8 @@ def setup_package():
"processing_analysis.py = unsiotools.simulations.cuns_analysis:commandLine", "processing_analysis.py = unsiotools.simulations.cuns_analysis:commandLine",
], ],
}, },
#install_requires=['numpy'], install_requires=['python-unsio','matplotlib','scipy','numpy'],
#setup_requires=['numpy'] setup_requires=['numpy']
) )
setup(**metadata) setup(**metadata)
# #
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment