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

add rectify option to uns_2dplot

parent f8fc94d3
......@@ -27,6 +27,10 @@ def commandLine():
default="gas:jet,stars:Paired,halo:Accent")
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('--rect_sim', help="you must give a simname to activate rectify",default=None)
parser.add_argument('--rect_comp', help="used component based file, eg 'stars-stars' or 'gas-stars'",default="stars-stars")
parser.add_argument('--rect_dir', help="rectify directory name",default="rectify2")
parser.add_argument('--rect_suffix',help="rectify suffix file name",default="ev")
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)
......@@ -60,7 +64,6 @@ def process(args):
# matplotlib.use() must be done before importing matplotlib.pyplot
import simulations.c2dplot as c2d
import simulations.csnapshot as csnap
try:
cpt = args.cpt
uns=csnap.CSnapshot(args.snapshot,args.component,verbose_debug=args.verbose)
......@@ -68,8 +71,9 @@ 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,center_cod=args.cod,
nopart=args.nopart)
mergers=args.mergers,cmap=args.cmap,cpt=cpt,noxz=args.noxz, contour=args.contour,
nc=args.nc,center_cod=args.cod,nopart=args.nopart,
rect_sim=args.rect_sim,rect_comp=args.rect_comp,rect_dir=args.rect_dir,rect_suffix=args.rect_suffix)
cpt =cpt+1
# else:
# print ("[%s] is not a UNS snapshot ..."%(simname))
......
......@@ -3,6 +3,7 @@ from __future__ import print_function
from csnapshot import *
from uns_simu import *
from ccod import *
import simulations.crectify as crect
from multiprocessing import Lock
import time
import os,sys
......@@ -406,11 +407,17 @@ 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,center_cod=None,nopart=False):
cpt=0,noxz=False,contour=False,nc=20,center_cod=None,nopart=False,
rect_sim=None, rect_comp="stars-stars",rect_dir="rectify2",rect_suffix="ev"):
t0=time.clock()
sigma_ori=sigma
xrange_ori=xrange
# rectify variables
self.__rect_sim = rect_sim
self.__rect_comp = rect_comp
self.__rect_dir = rect_dir
self.__rect_suffix = rect_suffix
self.__x={}
# set color map
comp_cmap=self.__setCmapComponents(cmap)
......@@ -419,8 +426,16 @@ class C2dplot:
ok,timex=uns.getData("time")
if self.__vdebug:
print ("Loading time : " , time.clock()-t0)
# read data_rectify
if self.__rect_sim is not None:
ok,self.__data_rect=crect.CRectify.infoTimeSimu(self.__rect_sim,timex,self.__rect_comp,
self.__rect_dir,self.__rect_suffix)
else:
print("Rectify, sim is None !!\n")
self.__uns=uns
#
ok_center,center_xy,center_xz,cx1,cx2=self.__getCenterMerger(mergers)
......@@ -533,6 +548,18 @@ class C2dplot:
# reshape array in x,y,z arrays
pos=np.reshape(pos,(-1,3)) # pos reshaped in a 2D array [nbody,3]
# if self.__rect_sim is not None:
# print("rectifying....")
# x0 = pos * self.__data_rect[6:9]
# x1 = pos * self.__data_rect[9:12]
# x2 = pos * self.__data_rect[12:15]
#
# #pos[:,0] = np.sum(x0,axis=1)
# #pos[:,1] = np.sum(x1,axis=1)
# #pos[:,2] = np.sum(x2,axis=1)
# else:
# pass
x = pos[:,0] # x coordinates
if row==0:
y = pos[:,1] # y coordinates
......@@ -540,6 +567,7 @@ class C2dplot:
y = pos[:,2] # z coordinates
nbody = x.size
print("before center pos[100,:] =",pos[100,:])
if self.__vdebug:
print("Ok_center [%d] center_cod <%s>"%(ok_center,center_cod))
if ok_center:# it's a merger requested which exist
......@@ -555,6 +583,7 @@ class C2dplot:
print("Failed to __getCenterCod, aborting...\n")
sys.exit()
else:
print("tcxv=",tcxv[1:4])
x -= tcxv[1]
if row==0: # y = y
y -= tcxv[2]
......@@ -567,7 +596,25 @@ class C2dplot:
print ("COM = ",xcom,ycom)
x -= xcom
y -= ycom
# proceed on rectify
print("after center pos[100,:] =",pos[100,:])
if self.__rect_sim is not None:
x0 = pos * self.__data_rect[6:9]
x1 = pos * self.__data_rect[9:12]
x2 = pos * self.__data_rect[12:15]
if row==0:
x = np.sum(x0,axis=1)
self.__x[component]=np.copy(x)
y = np.sum(x1,axis=1)
else:
x = self.__x[component] # np.sum(x0,axis=1)
y = np.sum(x2,axis=1)
print("after rectify x[100] y[100] =",x[100],y[100])
else:
pass
else : # there are no particles
x=np.empty(0)
y=np.empty(0)
......
......@@ -282,6 +282,44 @@ class CRectify:
else :
self.__convertEv2Rect(ev_in,rect_out)
#
# infoTimeSimu
#
@staticmethod
def infoTimeSimu(simname,time,component="gas-stars",rectify_dir_name='rectify2',verbose=False):
"""
return info array at the corresponding time and simu rect file
"""
sql3 = UnsSimu(simname,verbose=verbose)
r = sql3.getInfo()
if (r is None) :
print("Simulation %s does not belong to UNS database...\n"%(simname))
sys.exit()
rectify_dir=r['dir']+"/ANALYSIS/"+rectify_dir_name
rect_file=rectify_dir+"/"+r['name']+"."+component+".ev"
print("Trying reading file [%s]\n"%(rect_file))
ok=False
data=[]
if os.path.isfile(rect_file):
f=open(rect_file,"r")
try:
while True:
data=map(np.float64,(f.readline().split()))
#print ("DATA =",n,data,len(data))
if (len(data)>0):
atime=data[0]
if (atime-0.001)<time and (atime+0.001)>time:
return True,data[1:]
else:
return False,[]
except EOFError:
pass
return ok,[]
#
# __convertEv2Rect
......
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