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

refactoring...

parent 3944b8de
#!/usr/bin/env python #!/usr/bin/env python
from __future__ import print_function from __future__ import print_function
import sys import sys
sys.path=['/home/jcl/works/GIT/uns_projects/py/modules/','/home/jcl/works/GIT/uns_projects/py/modules/simulations']+sys.path #sys.path=['/home/jcl/works/GIT/uns_projects/py/modules/','/home/jcl/works/GIT/uns_projects/py/modules/simulations']+sys.path
from simulations.cmovie import * from unsiotools.simulations.cmovie import *
import argparse import argparse
import os,glob,subprocess import os,glob,subprocess
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# commandLine, parse the command line # commandLine, parse the command line
def commandLine(): def commandLine():
dbname=None dbname=None
...@@ -16,7 +16,7 @@ def commandLine(): ...@@ -16,7 +16,7 @@ def commandLine():
parser = argparse.ArgumentParser(description="Build directory for new metal simulation", parser = argparse.ArgumentParser(description="Build directory for new metal simulation",
formatter_class=argparse.ArgumentDefaultsHelpFormatter) formatter_class=argparse.ArgumentDefaultsHelpFormatter)
# options # options
parser.add_argument('srcdir', help='src directory ie : 30_idf401_init_gal3_-2_0.45') parser.add_argument('srcdir', help='src directory ie : 30_idf401_init_gal3_-2_0.45')
parser.add_argument('destdir',help="dest directory ei: /rydata/mdf/idf401_01") parser.add_argument('destdir',help="dest directory ei: /rydata/mdf/idf401_01")
...@@ -26,8 +26,8 @@ def commandLine(): ...@@ -26,8 +26,8 @@ def commandLine():
parser.add_argument('--verbose',help='verbose mode on', dest="verbose", action="store_true", default=False) parser.add_argument('--verbose',help='verbose mode on', dest="verbose", action="store_true", default=False)
# parse # parse
args = parser.parse_args() args = parser.parse_args()
# start main funciton # start main funciton
process(args) process(args)
......
...@@ -5,10 +5,10 @@ import sys ...@@ -5,10 +5,10 @@ import sys
import argparse,textwrap import argparse,textwrap
#sys.path=['/home/jcl/works/GIT/uns_projects/py/modules/','/home/jcl/works/GIT/uns_projects/py/modules/simulations']+sys.path #sys.path=['/home/jcl/works/GIT/uns_projects/py/modules/','/home/jcl/works/GIT/uns_projects/py/modules/simulations']+sys.path
from simulations.crectify import * from unsiotools.simulations.crectify import *
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# commandLine, parse the command line # commandLine, parse the command line
def commandLine(): def commandLine():
# help # help
...@@ -39,11 +39,9 @@ def process(args): ...@@ -39,11 +39,9 @@ def process(args):
c.buildRectFile(simname=args.simname,ev_in=args.ev,rect_out=args.rect) c.buildRectFile(simname=args.simname,ev_in=args.ev,rect_out=args.rect)
except Exception as x : except Exception as x :
print (x.message) print (x.message)
# ----------------------------------------------------- # -----------------------------------------------------
# main program # main program
if __name__ == '__main__': if __name__ == '__main__':
commandLine() commandLine()
...@@ -5,7 +5,7 @@ import matplotlib.pyplot as plt ...@@ -5,7 +5,7 @@ import matplotlib.pyplot as plt
# cnd line # cnd line
import sys, getopt,os.path import sys, getopt,os.path
#sys.path.append('/home/jcl/works/SVN/uns_projects/trunk/py/modules/') #sys.path.append('/home/jcl/works/SVN/uns_projects/trunk/py/modules/')
from uns_simu import * from unsiotools.uns_simu import *
import argparse import argparse
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
...@@ -53,11 +53,11 @@ def main(argv): ...@@ -53,11 +53,11 @@ def main(argv):
#if len(gparam)>1: #if len(gparam)>1:
# dt = float(gparam['MaxSizeTimestep']) # dt = float(gparam['MaxSizeTimestep'])
# print "Overwrite dt from gadget.patam = ",dt # print "Overwrite dt from gadget.patam = ",dt
for f in file.split(","): for f in file.split(","):
try: try:
cpu_file,mylegend=f.split(":") # parse filename:legend cpu_file,mylegend=f.split(":") # parse filename:legend
except ValueError: except ValueError:
f_label=f f_label=f
cpu_file=f cpu_file=f
...@@ -76,7 +76,7 @@ def main(argv): ...@@ -76,7 +76,7 @@ def main(argv):
else: else:
print "Simulation [",cpu_file,"] does not exist in unsio database..." print "Simulation [",cpu_file,"] does not exist in unsio database..."
sys.exit() sys.exit()
time,cpu,ncores=parseCPU(cpu_file,dt,tf,tl) time,cpu,ncores=parseCPU(cpu_file,dt,tf,tl)
f_label=f_label+" cpus=%d"%ncores f_label=f_label+" cpus=%d"%ncores
if tmax>0 and (tmax-time[-1])>0.01: if tmax>0 and (tmax-time[-1])>0.01:
...@@ -100,13 +100,13 @@ def main(argv): ...@@ -100,13 +100,13 @@ def main(argv):
else: else:
plt.plot(time,cpu,label=f_label) plt.plot(time,cpu,label=f_label)
plt.xlabel('Simulation time') plt.xlabel('Simulation time')
plt.ylabel('Cpu time (seconds)') plt.ylabel('Cpu time (seconds)')
plt.title('Cpu time every dt='+'%f'%dt) plt.title('Cpu time every dt='+'%f'%dt)
leg=plt.legend(loc='best', fancybox=True) leg=plt.legend(loc='best', fancybox=True)
leg.get_frame().set_alpha(0.5) leg.get_frame().set_alpha(0.5)
if (out==''): if (out==''):
plt.show() plt.show()
else: else:
...@@ -114,7 +114,7 @@ def main(argv): ...@@ -114,7 +114,7 @@ def main(argv):
plt.savefig(out)#, bbox_inches=0) plt.savefig(out)#, bbox_inches=0)
plt.close(fig) plt.close(fig)
sys.exit() sys.exit()
# Parse gadget.param file and return a dictionary key pair value # Parse gadget.param file and return a dictionary key pair value
...@@ -144,7 +144,7 @@ def getHMS(sec,tag): ...@@ -144,7 +144,7 @@ def getHMS(sec,tag):
mins = sec / 60 mins = sec / 60
sec -= 60*mins sec -= 60*mins
dhms="%s :%dd %dh %dmn %ds"%(tag,days,hrs,mins,sec) dhms="%s :%dd %dh %dmn %ds"%(tag,days,hrs,mins,sec)
print dhms print dhms
return dhms return dhms
...@@ -163,7 +163,7 @@ def parseCPU(file,dt,tf,tl): ...@@ -163,7 +163,7 @@ def parseCPU(file,dt,tf,tl):
cputotlast=0.0 cputotlast=0.0
cputot=0.0 cputot=0.0
ncores=0 ncores=0
for line in a: for line in a:
if line.startswith("Step"): # Step line if line.startswith("Step"): # Step line
if (tl != -1 and t>tl): # exit if time last reach if (tl != -1 and t>tl): # exit if time last reach
...@@ -172,8 +172,8 @@ def parseCPU(file,dt,tf,tl): ...@@ -172,8 +172,8 @@ def parseCPU(file,dt,tf,tl):
if first: if first:
ncores=int(line.split()[5]) ncores=int(line.split()[5])
cputot=float(a.next().split()[1]) # get from next line cpu time cputot=float(a.next().split()[1]) # get from next line cpu time
if (t>=tf and first): # time >= time first and first if (t>=tf and first): # time >= time first and first
tlast= t # save time tlast= t # save time
cputotlast=cputot # save cpu time cputotlast=cputot # save cpu time
first=False first=False
...@@ -220,7 +220,7 @@ def printHelp(prog,file,dt,tf,tl,out,smooth): ...@@ -220,7 +220,7 @@ def printHelp(prog,file,dt,tf,tl,out,smooth):
smooth : curve fit smoothing.... [%d] smooth : curve fit smoothing.... [%d]
""" """
print help % (prog,file,dt,tf,tl,out,smooth) print help % (prog,file,dt,tf,tl,out,smooth)
if __name__=='__main__': if __name__=='__main__':
main(sys.argv[0:]) main(sys.argv[0:])
#!/usr/bin/env python #!/usr/bin/env python
from __future__ import print_function from __future__ import print_function
import sys import sys
sys.path=['/home/jcl/works/GIT/uns_projects/py/modules/','/home/jcl/works/GIT/uns_projects/py/modules/simulations']+sys.path #sys.path=['/home/jcl/works/GIT/uns_projects/py/modules/','/home/jcl/works/GIT/uns_projects/py/modules/simulations']+sys.path
import argparse import argparse
import os,glob import os,glob
import errno import errno
......
#!/usr/bin/env python #!/usr/bin/env python
from __future__ import print_function from __future__ import print_function
import sys import sys
sys.path=['/home/jcl/works/GIT/uns_projects/py/modules/','/home/jcl/works/GIT/uns_projects/py/modules/simulations']+sys.path #sys.path=['/home/jcl/works/GIT/uns_projects/py/modules/','/home/jcl/works/GIT/uns_projects/py/modules/simulations']+sys.path
from simulations.cmovie import * #from simulations.cmovie import *
import argparse import argparse
import os,glob import os,glob
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# commandLine, parse the command line # commandLine, parse the command line
def commandLine(): def commandLine():
dbname=None dbname=None
...@@ -16,15 +16,15 @@ def commandLine(): ...@@ -16,15 +16,15 @@ def commandLine():
parser = argparse.ArgumentParser(description="Link snapshot with one unit incremental", parser = argparse.ArgumentParser(description="Link snapshot with one unit incremental",
formatter_class=argparse.ArgumentDefaultsHelpFormatter) formatter_class=argparse.ArgumentDefaultsHelpFormatter)
# options # options
parser.add_argument('snapshot', help='snapshot path, ie : runs/snapshot') parser.add_argument('snapshot', help='snapshot path, ie : runs/snapshot')
parser.add_argument('--verbose',help='verbose mode on', dest="verbose", action="store_true", default=False) parser.add_argument('--verbose',help='verbose mode on', dest="verbose", action="store_true", default=False)
# parse # parse
args = parser.parse_args() args = parser.parse_args()
# start main funciton # start main funciton
process(args) process(args)
...@@ -37,7 +37,7 @@ def process(args): ...@@ -37,7 +37,7 @@ def process(args):
snap_list = snap_list+sorted(glob.glob(args.snapshot+'_???')) snap_list = snap_list+sorted(glob.glob(args.snapshot+'_???'))
snap_list = snap_list+sorted(glob.glob(args.snapshot+'_????')) snap_list = snap_list+sorted(glob.glob(args.snapshot+'_????'))
snap_list = snap_list+sorted(glob.glob(args.snapshot+'_?????')) snap_list = snap_list+sorted(glob.glob(args.snapshot+'_?????'))
cpt=0 cpt=0
for mysnap in snap_list: for mysnap in snap_list:
mylink="snapshot_"+str(cpt) mylink="snapshot_"+str(cpt)
......
#!/usr/bin/env python #!/usr/bin/env python
import sys import sys
from uns_simu import * #from unsiotools.uns_simu import *
from simulations.ccod import * #from simulations.ccod import *
import argparse import argparse
sys.path=['/home/jcl/works/GIT/uns_projects/py/modules/','/home/jcl/works/GIT/uns_projects/py/modules/simulations']+sys.path #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
...@@ -32,9 +32,9 @@ def commandLine(): ...@@ -32,9 +32,9 @@ def commandLine():
# ----------------------------------------------------- # -----------------------------------------------------
# process, is the core function # process, is the core function
def process(args): def process(args):
pass pass
# ----------------------------------------------------- # -----------------------------------------------------
# main program # main program
......
...@@ -2,13 +2,13 @@ ...@@ -2,13 +2,13 @@
from __future__ import print_function from __future__ import print_function
import sys import sys
#sys.path=['/home/jcl/works/GIT/uns_projects/py/modules/','/home/jcl/works/GIT/uns_projects/py/modules/simulations']+sys.path #sys.path=['/home/jcl/works/GIT/uns_projects/py/modules/','/home/jcl/works/GIT/uns_projects/py/modules/simulations']+sys.path
from uns_simu import * #from unsiotools.uns_simu import *
from simulations.ccod import * from unsiotools.simulations.ccod import *
import argparse import argparse
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# commandLine, parse the command line # commandLine, parse the command line
def commandLine(): def commandLine():
dbname=None dbname=None
ncores=None ncores=None
...@@ -22,7 +22,7 @@ def commandLine(): ...@@ -22,7 +22,7 @@ def commandLine():
parser = argparse.ArgumentParser(description="Display merging time", parser = argparse.ArgumentParser(description="Display merging time",
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('--dmax', help='max distance of separation (kpc)',default=dmax,type=float) parser.add_argument('--dmax', help='max distance of separation (kpc)',default=dmax,type=float)
parser.add_argument('--cod1', help='first cod file',default=cod1) parser.add_argument('--cod1', help='first cod file',default=cod1)
...@@ -39,8 +39,8 @@ def commandLine(): ...@@ -39,8 +39,8 @@ def commandLine():
#parser.add_argument('--no-verbose',help='verbose mode off', dest="verbose", action="store_false", default=True) #parser.add_argument('--no-verbose',help='verbose mode off', dest="verbose", action="store_false", default=True)
# parse # parse
args = parser.parse_args() args = parser.parse_args()
if args.pngfile=="None": if args.pngfile=="None":
args.pngfile=None args.pngfile=None
# start main funciton # start main funciton
...@@ -59,7 +59,7 @@ def process(args): ...@@ -59,7 +59,7 @@ def process(args):
except KeyboardInterrupt: except KeyboardInterrupt:
sys.exit() sys.exit()
# ----------------------------------------------------- # -----------------------------------------------------
# main program # main program
......
...@@ -2,17 +2,16 @@ ...@@ -2,17 +2,16 @@
from __future__ import print_function from __future__ import print_function
import sys import sys
sys.path=['/home/jcl/works/GIT/uns_projects/py/modules/','/home/jcl/works/GIT/uns_projects/py/modules/simulations']+sys.path #sys.path=['/home/jcl/works/GIT/uns_projects/py/modules/','/home/jcl/works/GIT/uns_projects/py/modules/simulations']+sys.path
#from py_unstools import * # import py_unstools package #from py_unstools import * # import py_unstools package
from unsio import * #from unsio import *
from uns_simu import * #from general.ctools import *
from general.ctools import *
import argparse import argparse
import os,subprocess import os,subprocess
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# commandLine, parse the command line # commandLine, parse the command line
def commandLine(): def commandLine():
dbname=None dbname=None
......
...@@ -2,12 +2,12 @@ ...@@ -2,12 +2,12 @@
from __future__ import print_function from __future__ import print_function
import sys import sys
#sys.path=['/home/jcl/works/GIT/uns_projects/py/modules/','/home/jcl/works/GIT/uns_projects/py/modules/simulations']+sys.path #sys.path=['/home/jcl/works/GIT/uns_projects/py/modules/','/home/jcl/works/GIT/uns_projects/py/modules/simulations']+sys.path
from simulations.cmovie import * from unsiotools.simulations.cmovie import *
import argparse import argparse
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# commandLine, parse the command line # commandLine, parse the command line
def commandLine(): def commandLine():
dbname=None dbname=None
...@@ -15,7 +15,7 @@ def commandLine(): ...@@ -15,7 +15,7 @@ def commandLine():
parser = argparse.ArgumentParser(description="Build simulation movie after smart analysis", parser = argparse.ArgumentParser(description="Build simulation movie after smart analysis",
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('--dbname',help='UNS database file name', default=dbname) parser.add_argument('--dbname',help='UNS database file name', default=dbname)
...@@ -25,7 +25,7 @@ def commandLine(): ...@@ -25,7 +25,7 @@ def commandLine():
#parser.add_argument('--no-verbose',help='verbose mode off', dest="verbose", action="store_false", default=True) #parser.add_argument('--no-verbose',help='verbose mode off', dest="verbose", action="store_false", default=True)
# parse # parse
args = parser.parse_args() args = parser.parse_args()
# start main funciton # start main funciton
process(args) process(args)
...@@ -42,7 +42,7 @@ def process(args): ...@@ -42,7 +42,7 @@ def process(args):
print(x.message) print(x.message)
sys.exit() sys.exit()
# ----------------------------------------------------- # -----------------------------------------------------
# main program # main program
......
...@@ -4,10 +4,10 @@ from __future__ import print_function ...@@ -4,10 +4,10 @@ from __future__ import print_function
import sys import sys
import numpy as np import numpy as np
import argparse import argparse
from uns_simu import * from unsiotools.uns_simu import *
import os.path import os.path
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# commandLine, parse the command line # commandLine, parse the command line
def commandLine(): def commandLine():
# help # help
...@@ -23,11 +23,11 @@ def commandLine(): ...@@ -23,11 +23,11 @@ def commandLine():
process(args) process(args)
# ----------------------------------------------------- # -----------------------------------------------------
# #
def checkSimu(simname): def checkSimu(simname):
sql3 = UnsSimu() sql3 = UnsSimu()
#sql3.printInfo(simname) #sql3.printInfo(simname)
r = sql3.getInfo(simname) r = sql3.getInfo(simname)
if (r) : if (r) :
tbd_dir=r['dir']+'/ANALYSIS/Tbd' tbd_dir=r['dir']+'/ANALYSIS/Tbd'
...@@ -41,7 +41,7 @@ def checkSimu(simname): ...@@ -41,7 +41,7 @@ def checkSimu(simname):
# ----------------------------------------------------- # -----------------------------------------------------
# process, is the core function # process, is the core function
def process(args): def process(args):
fnpy=args.npy fnpy=args.npy
if (not os.path.exists(fnpy)): if (not os.path.exists(fnpy)):
dnpy,fnpy_yes,fnpy_no=checkSimu(args.npy) dnpy,fnpy_yes,fnpy_no=checkSimu(args.npy)
...@@ -58,7 +58,7 @@ def process(args): ...@@ -58,7 +58,7 @@ def process(args):
for i in range(data.size/3): for i in range(data.size/3):
print (' '.join(map(str,data[:,i]))) print (' '.join(map(str,data[:,i])))
# ----------------------------------------------------- # -----------------------------------------------------
# main program # main program
......
...@@ -9,14 +9,14 @@ import numpy as np ...@@ -9,14 +9,14 @@ import numpy as np
import argparse import argparse
import matplotlib import matplotlib
matplotlib.use('Agg') matplotlib.use('Agg')
sys.path=['/home/jcl/works/GIT/uns_projects/py/modules/','/home/jcl/works/GIT/uns_projects/py/modules/simulations']+sys.path #sys.path=['/home/jcl/works/GIT/uns_projects/py/modules/','/home/jcl/works/GIT/uns_projects/py/modules/simulations']+sys.path
from simulations.cuns_analysis import * from unsiotools.simulations.cuns_analysis import *
# #
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# commandLine, parse the command line # commandLine, parse the command line
def commandLine(): def commandLine():
dbname=None dbname=None
ncores=None ncores=None
...@@ -32,7 +32,7 @@ def commandLine(): ...@@ -32,7 +32,7 @@ def commandLine():
parser.add_argument('--verbose',help='verbose mode', default=False) parser.add_argument('--verbose',help='verbose mode', default=False)
print ("Matplotlib backend Using:",matplotlib.get_backend(),file=sys.stderr) print ("Matplotlib backend Using:",matplotlib.get_backend(),file=sys.stderr)