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

updates

parent 3b7ce1e2
......@@ -31,8 +31,25 @@ extern "C" { // declare as extern to be called from fortran and C
// wrapper which can be called from a fortran program
int get_param_simu_(const char * filename, const char * select, float * data, int l1, int l2);
int get_param_model_(const char * filename, const char * select, float * data, int l1, int l2);
int get_last_info_(const char * filename, const char * select, float * data, int l1, int l2);
}
//------------------------------------------------------------------------------
// get_last_info_
int get_last_info_(const char * _name, const char * _field, float * data, int l1, int l2)
{
int ret=0;
std::string simname = tools::Ctools::fixFortran(_name,l1,false);
std::string field = tools::Ctools::fixFortran(_field,l2,false);
std::string value=getParam(simname,"final_time.txt", field, false);
if (value.length()>0) {
ret=1;
std::istringstream istr(value);
istr >> *data;
//std::cerr << "Data = " << *data << "\n";
}
return ret;
}
//------------------------------------------------------------------------------
// get_param_model_
int get_param_model_(const char * _name, const char * _field, float * data, int l1, int l2)
......@@ -118,7 +135,7 @@ std::string getParam(std::string simname,std::string filename, std::string sele
if (unsin->isValid()) { // input file is known by UNS lib
std::string param=unsin->snapshot->getSimDir()+"/"+filename;
std::cerr << "gadget.param :"<<param<<"\n";
std::cerr << "File :"<<param<<"\n";
ret = processParam(param, select);
if (ret.length()>0) {
//std::cerr << "found:"<<select << " : "<< ret << "\n";
......
......@@ -147,7 +147,7 @@ def printAndSaveProp(uns,unso,comp,take,mmult):
ok,pot=uns.getArrayF(comp,"pot")
if ok:
print "pot =",pot
metal=keepEveryTake(pot,1,take)
pot=keepEveryTake(pot,1,take)
unso.setArrayF(comp,"pot",pot) # save mettalicity
......
......@@ -6,7 +6,7 @@ from c2dplot import *
import py_unstools # rectify swig
import subprocess
from multiprocessing import Lock
from multiprocessing import Lock,cpu_count
import time
import os
......@@ -92,7 +92,7 @@ class CMovie:
c.draw(uns_snap=uns_snap,select=comp,outdev=fdir+"/frame",title=basefile,no=no,prop=prop,cb=0,rrange=radius,times=time.item())
else :
c.draw(uns_snap=uns_snap,select=comp,outdev=fdir+"/frame",title=basefile,no=no,prop=prop,cb=1,rrange=radius,times=time.item(),psort=1,itf=0)
if not os.path.isfile(myframe): # no frame created
if not os.path.isfile(myframe): # no frame created
subprocess.call(["convert","-size","850x680","xc:black",myframe]) # create a black frame
self.__saveNewTime(time,t_file) # save new time in ".time_completed" file
......@@ -257,3 +257,262 @@ class CMovie:
data.lock[data.lock_id].release()
sys.exit()
data.lock[data.lock_id].release() # release process
#
#
#
def buildMovie(self,simname,overwrite):
"""
buildMovie, build movie created using process_analysis.py program
*IN*
simname : simulation name, must belong to unsio database
"""
sql3 = UnsSimu()
r = sql3.getInfo(simname)
if (r) : # simulation exist
dir_movie=r['dir']+'/ANALYSIS/movie' # movie directory
for d in glob.glob(dir_movie+"/w/*"): # loop on work "w" directory
base=os.path.basename(d) # get basename like r_1_p_99_pp_none
if (base[0:2]=='r_') :
q,radius,q,percen,q,property=base.split("_")
print("Radius [%f] Percen [%f] Property [%s]\n"%(float(radius),float(percen),property))
dir2_movie=dir_movie+"/center"
if float(percen)>0:
dir2_movie=dir_movie+"/whole"
if property!="none":
dir2_movie=dir_movie+"/"+property
if not os.path.isdir(dir2_movie) :
try:
os.makedirs(dir2_movie)
except OSError:
print("Unable to create directory [%s]\n"%(dir2_movie))
print ("Dir [%s]\n"%(d))
for c in glob.glob(d+"/*"): # loop on components
comp=os.path.basename(c)
movie_name=simname+"_"+comp+"_"+property+"_post.avi"
print ("comp <%s> filename [%s/%s]\n"%(comp,dir2_movie,movie_name))
if not os.path.isfile(myframe): # no frame created
subprocess.call(["convert","-size","850x680","xc:black",myframe]) # create a black frame
self.__saveNewTime(time,t_file) # save new time in ".time_completed" file
else:
if self.__vdebug:
print("MOVIE: skip time[%.3f] from <%s>\n"%(time,t_file))
#
# __checkTimeExist
#
def __saveNewTime(self,time,t_file):
"""
write in t_file a new time completed
*IN*
time : current time
t_file : filename
"""
# lock process
self.__analysis.lock[self.__analysis.lock_id].acquire()
if self.__vdebug:
print("Saving a new movie time[%.3f] in <%s>\n"%(time,t_file))
try:
f=open(t_file,"a")
f.write("%e\n"%(time))
f.close()
except:
print("\n\nUnable to save time[%.3f] in <%s>, aborting....\n"%(time,t_file))
sys.exit()
# release process
self.__analysis.lock[self.__analysis.lock_id].release()
#
# __checkTimeExist
#
def __checkTimeExist(self,time,t_file):
"""
check in t_file, if time has been already computed
*IN*
time : current time
t_file : file with time value
*OUT*
boolean : True if time exist, False otherwise
"""
if os.path.isfile(t_file):
try:
f=open(t_file,"r")
while True:
atime=map(np.float,(f.readline().split()))
if (len(atime)>0):
if (atime[0]-0.001)<time and (atime[0]+0.001)>time:
f.close()
return True
else:
f.close()
return False
except EOFError:
pass
else:
if self.__vdebug:
print("FILE <%s> does not exist...\n"%(t_file))
return False
#
# __smartAnalysisInit
#
def __smartAnalysisInit(self):
"""
start some initialisations
"""
data=self.__analysis
if not hasattr(data,'movie_select'):
print("\n\nYou must set a fied [movie_select] in your <data> object, aborting...\n\n")
sys.exit()
data.movie_select=data.movie_select.replace(" ","") # remove blank
### build COM Dir
if hasattr(data,'movie_dir'):
self.__movie_dir=data.movie_dir
#
else: # default simdir simulation
self.__movie_dir=data.sim_info['dir']+"/ANALYSIS/movie"
if self.__vdebug:
print("MOVIE DIR = ", type(self.__movie_dir), data.sim_info['name'])
self.simname=data.sim_info['name']
self.__comp_data =[] # list to store compononent to proceed
self.__newradius_0=[] # list to store newradius 0
self.__parseSelect(data)
self.__createDir(data)
#
# __parseSelect
#
def __parseSelect(self,data):
"""
parse selected string
"""
### re build select component variable according to components existing at mid
### simulation time (pre-computed by cuns_analysis.py and set to data.list_components
self.__new_select=""
for colon_s in data.movie_select.split(":"): # colon separate analysis
print ("COLON_S =",colon_s)
comp,prop,percen,newradius,extdir=colon_s.split("#")
xx=data.list_components.find(comp) # find if component exist
if xx==-1: # comp not exist
print("CMovie#Warning : component <%s> from select <%s> does not exist...\n"\
%(comp,colon_s))
else: # comp exist
fdir=self.__movie_dir+"/w/r_"+newradius+"_p_"+\
percen+"_pp_"+prop+"/"+comp
self.__comp_data.append([comp,prop,float(percen),int(newradius),extdir,fdir])
#
# __createDir
#
def __createDir(self,data):
"""
create directories for each existing components
"""
for comp,prop,percen,newradius,extdir,fdir in self.__comp_data:
# check newradius
radius=-1
if newradius==0: #we must compute radius of the last snapshot
s=CSnapshot(data.slist[-1],comp)
ok=s.nextFrame("xv")
if ok:
# compute radius for at percen particles for the last snapshot
status,radius=s.getMaxRadius(select=comp,percen=percen)
else:
print ("Cannot compute newradius_0 for [%s] on file "%(comp,data.slist[-1]))
s.close() # close test snapshot
print("Comp [%s] newradius_0 = <%f>"%(comp,radius))
self.__newradius_0.append(radius) # store newradius_0
data.lock[data.lock_id].acquire() # lock process
# build directory
if (not os.path.isdir(fdir)) :
try:
print("Core ID ",data.core_id," create directory [%s]\n"%(fdir))
os.makedirs(fdir)
except OSError:
print("Unable to create directory [%s]\n"%(fdir))
data.lock[data.lock_id].release()
sys.exit()
data.lock[data.lock_id].release() # release process
#
#
#
def buildMovie(self,simname,overwrite,ncores):
"""
buildMovie, build movie created using process_analysis.py program
*IN*
simname (str) : simulation name, must belong to unsio database
overwrite (bool): overwrite movie file if True
ncores (str) : number of cores. if "None" all cores used, otherwise
use int(ncores)
"""
# compute cores
if ncores==0:
ncores=cpu_count()
if self.__vdebug:
print ("#cores used :",ncores)
sql3 = UnsSimu()
r = sql3.getInfo(simname)
if (r) : # simulation exist
dir_movie=r['dir']+'/ANALYSIS/movie' # movie directory
for d in glob.glob(dir_movie+"/w/*"): # loop on work "w" directory
base=os.path.basename(d) # get basename like r_1_p_99_pp_none
if (base[0:2]=='r_') :
q,radius,q,percen,q,property=base.split("_")
print("Radius [%f] Percen [%f] Property [%s]\n"%(float(radius),float(percen),property))
dir2_movie=dir_movie+"/center"
if float(percen)>0:
dir2_movie=dir_movie+"/whole"
if property!="none":
dir2_movie=dir_movie+"/"+property
if not os.path.isdir(dir2_movie) :
try:
os.makedirs(dir2_movie)
except OSError:
print("Unable to create directory [%s]\n"%(dir2_movie))
print ("Dir [%s]\n"%(d))
for c in glob.glob(d+"/*"): # loop on components
comp=os.path.basename(c)
movie_name=simname+"_"+comp+"_"+property+"_post.avi"
print ("comp <%s> filename [%s/%s]\n"%(comp,dir2_movie,movie_name))
if not os.path.isfile(dir2_movie+"/"+movie_name) or overwrite:
subprocess.call(["make_divx.pl",d+"/"+comp,"frame",dir2_movie+"/"+movie_name,"25",str(ncores)]) # create a black frame
else:
message="In CLASS <"+self.__class__.__name__+"> : Unknown simulation ["+simname+"] in UNS database..."
raise Exception(message)
pass
{
"metadata": {
"name": "",
"signature": "sha256:84844d086ec204569eb12c0cfe3fb329d3233e41a7bdbc33f08caf937e2a2dde"
"signature": "sha256:4e225eae94be85e2cec84ece307b91246e2c9c04d8b912515cc06d31c0158614"
},
"nbformat": 3,
"nbformat_minor": 0,
......@@ -176,7 +176,48 @@
"collapsed": false,
"input": [
"ok,pos=s.getData(\"halo\",\"pos\")\n",
"pos = np.reshape(pos,(-1,3))\n",
"pos = np.reshape(pos,(-1,3))"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 5
},
{
"cell_type": "code",
"collapsed": true,
"input": [
"x=np.sqrt(pos[:,0]**2+pos[:,2]**2+pos[:,2]**2)\n",
"print x\n",
"pos[:,0]"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"[ 111.24293518 112.47983551 129.29412842 ..., 184.55291748 183.32403564\n",
" 183.24845886]\n"
]
},
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 14,
"text": [
"array([ 87.16773224, 89.67019653, 97.93200684, ..., 112.50759888,\n",
" 112.50405121, 112.50299835], dtype=float32)"
]
}
],
"prompt_number": 14
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"pos=np.reshape(pos[n],pos[n].size)"
],
"language": "python",
......
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