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

add movie2

parent 5a6adb65
......@@ -25,9 +25,11 @@ def commandLine():
example: stars:Paired,halo:Purples\n \
(to display all colormap available use \"show\" as keyword)",
default="gas:jet,stars:Paired,halo:Accent")
parser.add_argument('--mergers', help="file to re-center, or @sim (ex; @mdf648) to get file automatically from simulation ",default="",type=str)
parser.add_argument('--mergers', help="use results from mergers analysis to re-center (ex; @mdf648) to get file automatically from simulation ",default="",type=str)
parser.add_argument('--cod', help="use COD file to re-center, or @sim (ex; @mdf648) to get file automatically from simulation ",default=None)
parser.add_argument('--sigma', help="gaussian sigma ",default=6.,type=float)
parser.add_argument('--noxz',help='no XZ projection',dest="noxz", action="store_true", default=False)
parser.add_argument('--nopart',help='not display particles number',dest="nopart", action="store_true", default=False)
parser.add_argument('--contour',help='toggle iso contour display',dest="contour", action="store_true", default=False)
parser.add_argument('--nc',help='#levels contour',default=20,type=int)
parser.add_argument('--cpt', help="index of the image (out.cpt.jpg)",default=0,type=int)
......@@ -66,7 +68,8 @@ def process(args):
while(uns.nextFrame("")):
c=c2d.C2dplot(verbose_debug=args.verbose)
c.fullProcess(uns=uns,out=args.out,component=args.component,xrange=float(args.range),sigma=args.sigma,
mergers=args.mergers,cmap=args.cmap,cpt=cpt,noxz=args.noxz, contour=args.contour, nc=args.nc)
mergers=args.mergers,cmap=args.cmap,cpt=cpt,noxz=args.noxz, contour=args.contour, nc=args.nc,center_cod=args.cod,
nopart=args.nopart)
cpt =cpt+1
# else:
# print ("[%s] is not a UNS snapshot ..."%(simname))
......
......@@ -14,6 +14,7 @@ import matplotlib.gridspec as gridspec
import math
import time
import scipy.ndimage as ndi
import subprocess
#from IPython import embed
#
......@@ -47,8 +48,7 @@ class C2dplot:
if analysis is not None:
self.__analysis=analysis
self.__smartAnalysisInit()
else:
pass
#
# __smartAnalysisInit
......@@ -84,10 +84,37 @@ class C2dplot:
#self.__parseSelect(data)
self.__createDir(data)
#
#
#
def buildMovie(self,simname,dirmovie=None,overwrite=False,ncores=None):
"""
buildMovie, build movie created using process_analysis.py program
*IN*
simname : simulation name, must belong to unsio database
"""
sql3 = UnsSimu(simname)
r = sql3.getInfo()
if (r) : # simulation exist
if dirmovie is not None:
dir_movie=dirmovie
else:
dir_movie=r['dir']+'/ANALYSIS/movie2' # movie directory
for d in ["contour","std"]:
for s in glob.glob(dir_movie+"/"+d+"/*"):
dir_frame=os.path.basename(s)
movie_name=dir_movie+"/"+d+"_"+dir_frame+".avi"
if not os.path.isfile(movie_name) or overwrite:
print("make_divx.pl",s,"frame",movie_name,"25",str(ncores),file=sys.stderr)
subprocess.call(["make_divx.pl",s,"frame",movie_name,"25",str(ncores)])
#
# smartAnalysis
#
def smartAnalysis(self,analysis=None,component=None,xrange="20",mergers=None,cmap="gas:jet,stars:Paired,halo:Accent",contour=False,noxz=False,sigma=6.0):
def smartAnalysis(self,analysis=None,component=None,xrange="20",mergers=None,center_cod=None,cmap="gas:jet,stars:Paired,halo:Accent",contour=False,noxz=False,sigma=6.0):
"""
Main core function to compute MOVIE on current snapshot store in data_analysis
"""
......@@ -110,7 +137,7 @@ class C2dplot:
no=int(basefile.split("_")[1]) # compute no
out=my_dir+"/frame"
self.fullProcess(data.uns_snap,out=out,component=component,xrange=xrange,sigma=sigma,
cmap=cmap,mergers=mergers,cpt=no,noxz=noxz,contour=contour)
cmap=cmap,mergers=mergers,center_cod=center_cod,cpt=no,noxz=noxz,contour=contour)
self.__saveNewTime(time,t_file) # save new time in ".time_completed" file
else:
if self.__vdebug:
......@@ -267,9 +294,45 @@ class C2dplot:
return ndi.gaussian_filter(img, sigma=(r,r),order=0) ## gaussian convolution
#ndi.gaussian_filter(img, (r,r)) ## gaussian convolution
#
# __getCenterCod
#
def __getCenterCod(self,center_cod,comp=None):
"""
According to argument 'center_cod'
- if it's cod file, will return cod
- if it's '@sim' it will return sim's cod at component comp
"""
#embed()
# check if simu
if self.__vdebug:
print("IN __getCenterCod [%s]"%(center_cod),file=sys.stderr)
if os.path.isfile(center_cod) : # it's a file
ok,time=self.__uns.getData("time")
return CCod(None).getCodFromFile(center_cod,time)
else:
tmp=center_cod.split('@')
if (len(tmp)>1): # it's simulation name
simname=tmp[1]
if self.__vdebug:
print("Simulation name from COD [%s] comp <%s>\n"%(simname,comp))
print("SELF.__ANALYSIS = <%s>"%(self.__analysis))
cod=CCod(simname,verbose_debug=self.__vdebug)
ok,time=self.__uns.getData("time")
cod_base=None
if self.__analysis is not None:
if hasattr(self.__analysis,"cod_dir"):
cod_base=self.__analysis.cod_dir
if self.__vdebug:
print(" def __getCenterCod -> cod_base=[%s]"%(cod_base))
return cod.getCodFromComp(comp,time,cod_file_base=cod_base)
return False,None,None,None,None
#
# __getCenterMerger
#
def __getCenterMerger(self,mergers):
"""
......@@ -284,12 +347,19 @@ class C2dplot:
simname=tmp[1]
if self.__vdebug:
print("Simulation name from merger [%s]\n"%(simname))
print("SELF.__ANALYSIS = <%s>"%(self.__analysis))
cod=CCod(simname,verbose_debug=self.__vdebug)
ok,time=self.__uns.getData("time")
ok1,tcxv1=cod.getCodFromComp("halo_1",time)
cod_base=None
if self.__analysis is not None:
if hasattr(self.__analysis,"cod_dir"):
cod_base=self.__analysis.cod_dir
if self.__vdebug:
print(" def __getCenterMerger -> cod_base=[%s]"%(cod_base))
ok1,tcxv1=cod.getCodFromComp("halo_1",time,cod_file_base=cod_base)
if self.__vdebug:
print ("halo_1:",ok,tcxv1,file=sys.stderr)
ok2,tcxv2=cod.getCodFromComp("halo_2",time)
ok2,tcxv2=cod.getCodFromComp("halo_2",time,cod_file_base=cod_base)
if self.__vdebug:
print ("halo_2:",ok,tcxv2,file=sys.stderr)
if ok1 and ok2:
......@@ -331,7 +401,7 @@ class C2dplot:
#
#
def fullProcess(self,uns,out="",component=None,xrange=20.,sigma=6.0,mergers="",cmap="jet",
cpt=0,noxz=False,contour=False,nc=20):
cpt=0,noxz=False,contour=False,nc=20,center_cod=None,nopart=False):
t0=time.clock()
sigma_ori=sigma
xrange_ori=xrange
......@@ -408,7 +478,8 @@ class C2dplot:
ax.set_yticks([])
#embed()
self.__display(uns,out,comp[c],xrange,sigma_ori,mergers,comp_cmap[comp[c]],
ok_center, center_xy,center_xz,ax,fig,r,contour=contour,nc=nc)
ok_center, center_xy,center_xz,ax,fig,r,contour=contour,nc=nc,
center_cod=center_cod,nopart=nopart)
fig.subplots_adjust(hspace=0.,wspace=0.)
print("Overall time [%.3f] sec"%(time.clock()-t0),file=sys.stderr)
if (out==''):
......@@ -425,7 +496,7 @@ class C2dplot:
#
#
def __display(self,uns,out,component,xrange,sigma_ori,mergers,cmap,ok_center,
center_xy,center_xz,ax,fig,row,contour=False,nc=20):
center_xy,center_xz,ax,fig,row,contour=False,nc=20,center_cod=None,nopart=False):
t0=time.clock()
comp=component
......@@ -457,20 +528,32 @@ class C2dplot:
nbody = x.size
if ok_center:
print("Ok_center [%d] center_cod <%s>"%(ok_center,center_cod))
if ok_center:# it's a merger requested which exist
x -= center_xy[0]
if row==0:
y -= center_xy[1]
else:
y -= center_xz[1]
else:
# center according COM or COD if RHO exist
xcom=np.average(x.astype(np.float64),weights=mass*rho)
ycom=np.average(y.astype(np.float64),weights=mass*rho)
if self.__vdebug:
print ("COM = ",xcom,ycom)
x -= xcom
y -= ycom
if center_cod is not None: # center on COD requested
ok,tcxv=self.__getCenterCod(center_cod,comp)
if not ok :
print("Failed to __getCenterCod, aborting...\n")
sys.exit()
else:
x -= tcxv[1]
if row==0: # y = y
y -= tcxv[2]
else: # y = z
y -= tcxv[3]
else: # COM center according COM or COD if RHO exist
xcom=np.average(x.astype(np.float64),weights=mass*rho)
ycom=np.average(y.astype(np.float64),weights=mass*rho)
if self.__vdebug:
print ("COM = ",xcom,ycom)
x -= xcom
y -= ycom
else : # there are no particles
x=np.empty(0)
......@@ -538,8 +621,11 @@ class C2dplot:
xtext=0.05
ytext=0.95
if row==0:
ax.text(xtext,ytext,component+":%d"%x.size,style='italic',color='black',bbox={'facecolor':'white', 'alpha':0.2, 'pad':10},
verticalalignment='top', horizontalalignment='left',transform=ax.transAxes)
disp_comp=component
if not nopart: # display particles number
disp_comp=disp_comp+":%d"%x.size
ax.text(xtext,ytext,disp_comp,style='italic',color='black',bbox={'facecolor':'white',
'alpha':0.2, 'pad':10},verticalalignment='top', horizontalalignment='left',transform=ax.transAxes)
#ax.imshow(zd , origin='lower',cmap=cmap,interpolation='nearest', norm = matplotlib.colors.LogNorm(),
# extent=[view_xmin, view_xmax, view_ymin, view_ymax])
......
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