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

some fixes

parent b70bdd7e
......@@ -6,10 +6,11 @@ import os,time
import sys
import argparse,textwrap
sys.path=['/home/jcl/works/GIT/uns_projects/py/modules/']+sys.path
#sys.path=['/home/jcl/works/GIT/uns_projects/py/modules/','/home/jcl/works/GIT/uns_projects/py/modules/simulations']+sys.path
import simulations.cinert as cinert
import simulations.csnapshot as csnap
#import simulations.csnapshot as csnap
from simulations.csnapshot import *
#from IPython import embed
......@@ -18,41 +19,41 @@ import simulations.csnapshot as csnap
def commandLine():
# help
parser = argparse.ArgumentParser(description="Display 2D image from UNS data",
parser = argparse.ArgumentParser(description="Compute Moment of Inertia on UNS simulation",
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('snapshot', help="uns input snapshot",default=None)
parser.add_argument('component', help="selected component",default=None)
parser.add_argument('outfile', help="output file name",default=None)
parser.add_argument('--ncut', help="#cuts ",default=10,type=int)
parser.add_argument('--outfile', help="output file name",default=None)
parser.add_argument('--ncut', help="#cuts ",default=20,type=int)
parser.add_argument('--fmin', help="fract min ",default=0.1,type=float)
parser.add_argument('--fmax', help="fract max ",default=0.9,type=float)
parser.add_argument('--out', help="if blank display on screen, else on given file ",default="",type=str)
parser.add_argument('--tree_threshold', help=">0 #particles, <0 percentage of particles ",default=-10.,type=float)
parser.add_argument('--notree_density',help='don''t use tree density',dest="notree", action="store_true", default=False)
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('--nocom', help='dont use com if no COD file requested',dest="nocom", action="store_true", default=False)
parser.add_argument('--nonemo', help='dont use Nemo algorithms (based on snapinert)',dest="nonemo", action="store_true", default=False)
parser.add_argument('--verbose',help='verbose mode',dest="verbose", action="store_true", default=False)
# parse
args = parser.parse_args()
# start main funciton
# start main function
process(args)
# -----------------------------------------------------
# process, is the core function
def process(args):
# select matplotlib backend
try:
uns=csnap.CSnapshot(args.snapshot,args.component,verbose_debug=args.verbose)
inert=cinert.CInert(verbose_debug=args.verbose)
f=inert.buildRes(args.outfile)
while(uns.nextFrame("")):
inert.fullProcess(uns=uns,ncut=args.ncut,component=args.component,center_file=args.cod,
fract_min=args.fmin,fract_max=args.fmax,com=not args.nocom)
# else:
# print ("[%s] is not a UNS snapshot ..."%(simname))
# instantiate CInert object
inert=cinert.CInert(snapshot=args.snapshot,outfile=args.outfile,ncut=args.ncut,
component=args.component,center_file=args.cod,
fract_min=args.fmin,fract_max=args.fmax,com=not args.nocom,
verbose_debug=args.verbose,
tree_density=not args.notree,tree_threshold=args.tree_threshold,nonemo=args.nonemo)
# start full process
inert.fullProcess(args.snapshot,args.component)
except Exception as x :
print (x.message,file=sys.stderr)
except KeyboardInterrupt:
......
......@@ -41,7 +41,7 @@ class CCod:
# ----
#
# constructor
def __init__(self,simname,analysis=None,dbname=None,verbose=False,verbose_debug=False):
def __init__(self,simname,analysis=None,cod_dir_name=None,dbname=None,verbose=False,verbose_debug=False):
"""
simname must be a UNS simulation belonging to a uns sqlite3 database.
infos regarding to simname simulation are loaded into privates variables
......@@ -49,6 +49,9 @@ class CCod:
self.__vdebug=verbose_debug
self.__verbose=verbose
if cod_dir_name is not None:
self.__COD_DIR_NAME=cod_dir_name
if analysis is None :
self.__dbname=dbname
if self.__vdebug:
......
......@@ -55,7 +55,7 @@ class CRectify:
data.rectify_select=data.rectify_select.replace(" ","") # remove blank
### build COM Dir
### build CRECT Dir
if hasattr(data,'rectify_dir'):
self.__rectify_dir=data.rectify_dir
#
......
......@@ -20,7 +20,9 @@ class CSnapshot:
__analysis=None
simname=None
select=None
#
# constructor
#
def __init__(self,simname,select="all",times="all",float32=True,verbose=False,verbose_debug=False):
select=select.encode('ascii')
times=times.encode('ascii')
......@@ -44,7 +46,9 @@ class CSnapshot:
raise RuntimeError("UNS not valid")
else:
None
def debugOn(self):
self.__vdebug=True
#
# nextFrame
#
......@@ -301,7 +305,7 @@ class CSnapshot:
#
#
#
def centerOnFile(self,pos,vel,mass,com,component,center_file):
def centerOnFile(self,pos,vel,mass,com,component,center_file,analysis=None):
"""
center positions and velocities according to paramaters
......@@ -317,9 +321,13 @@ class CSnapshot:
"""
if analysis is not None:
self.__analysis=analysis
if center_file is None and com: # no center file but COM reqested
print("Centering via COM", file=sys.stderr)
self.center(pos,vel,data_weight=mass,center=True)
cxv=self.center(pos,vel,data_weight=mass,center=True)
print("COM =",cxv,file=sys.stderr)
else :
if center_file is not None:
ok,tcxv=self._getCenterFromFile(center_file,component)
......
#!/usr/bin/python
from __future__ import print_function
import sys
import csnapshot as cs
try:
import py_unstools as ut # import py_unstools package
except ImportError:
print("WARNING !!!, failed to import module [py_unstools]",file=sys.stderr)
import numpy as np
from cfalcon import *
from py_unsio import *
from csnapshot import *
import cfalcon as cf
import py_unsio as unsio
# -----------------------------------------------------
#
class CTree:
"""methods imported from CTree C++ class"""
"""
methods imported from CTree C++ class
"""
__tree=None
# data given to constructor
__pos=None
__mass=None
__vel=None
__time=0.0
# -----------------------------------------------------
#
# data computed in tree
__tree_pos=None
__tree_vel=None
__tree_mass=None
__tree_rho=None
__tree_hsml=None
#
# constructor
#
def __init__(self,pos,vel=None,mass=None,fcells=0.9,rsize=0.4,time=0.0,seed=None):
self.__pos=pos
self.__mass=mass
......@@ -29,19 +41,24 @@ class CTree:
np.random.seed(seed)
if (type(pos[0])==np.float32):
self.__tree=ut.CTreeF(pos,mass,fcells,rsize)
else: # assume 64 bits (double)
self.__tree=ut.CTreeD(pos,mass,fcells,rsize)
# -----------------------------------------------------
#
#
# getLevels
#
def getLevels(self):
"""Return an numpy array with for each particles its level in the octree"""
ok,levels=self.__tree.get_levels(self.__tree.getNbody())
return ok,levels
# -----------------------------------------------------
#
#
# fastCod
#
def fastCod(self,threshold=10000):
"""
compute cod using octree
......@@ -74,7 +91,7 @@ class CTree:
p=np.reshape(p,(-1,))
#print(p.shape,p.size)
#print (p[:,])
c=CFalcon() # new falcon object
c=cf.CFalcon() # new falcon object
ok,rho,hsml=c.getDensity(p,m) # compute density
#print (ok)
......@@ -83,9 +100,9 @@ class CTree:
v=np.reshape(self.__vel,(-1,3))
v=v[idx[0:threshold],]
v=np.reshape(v,(-1,))
cxv=CSnapshot(None).center(p,v,m*rho)
cxv=cs.CSnapshot(None).center(p,v,m*rho)
unso=CunsOut("/home/jcl/x_x","gadget2")
unso=unsio.CunsOut("/home/jcl/x_x","gadget2")
unso.setArrayF("gas","pos",p)
unso.setArrayF("gas","mass",m)
......@@ -94,8 +111,9 @@ class CTree:
unso.save()
return cxv[0:3]
# -----------------------------------------------------
#
#
# fastCod2
#
def fastCod2(self,threshold=10000):
"""
compute cod using octree
......@@ -128,7 +146,7 @@ class CTree:
p=np.reshape(p,(-1,))
#print(p.shape,p.size)
#print (p[:,])
c=CFalcon() # new falcon object
c=cf.CFalcon() # new falcon object
ok,rho,hsml=c.getDensity(p,m) # compute density
#print (ok)
......@@ -137,10 +155,10 @@ class CTree:
v=np.reshape(self.__vel,(-1,3))
v=v[idx[0:threshold],]
v=np.reshape(v,(-1,))
cxv=CSnapshot(None).center(p,v,m*rho)
cxv=cs.CSnapshot(None).center(p,v,m*rho)
unso=CunsOut("/home/jcl/x_x","gadget2")
unso=unsio.CunsOut("/home/jcl/x_x","gadget2")
unso.setArrayF("gas","pos",p)
unso.setArrayF("gas","mass",m)
......@@ -149,8 +167,9 @@ class CTree:
unso.save()
return cxv[0:3]
# -----------------------------------------------------
#
#
# fastCod3
#
def fastCod3(self,threshold=10000,outfile=None):
"""
compute cod using octree
......@@ -159,8 +178,11 @@ class CTree:
threshold > 0 : use this values as number of particles selected for computing cod
threshold < 0 : use this |values| as a percentage of the total particles for computing cod
outfile : if not None save 'outfile' to NEMO format
Return:
cxv : COD, 1D numpy array of size 6
rpos : positions of particles used to compute cod 1D num array
"""
if threshold<0: # it's percentage of nbodies
......@@ -188,10 +210,15 @@ class CTree:
m=self.__mass[shuffle_idx_threshold] # get randomized thresholded indexes for mass
p=np.reshape(p,(-1,)) # flatten pos array
#print(p.shape,p.size)
#print (p[:,])
c=CFalcon() # new falcon object
c=cf.CFalcon() # new falcon object
ok,rho,hsml=c.getDensity(p,m) # compute density
self.__tree_pos = p
self.__tree_mass = m
self.__tree_rho = rho
self.__tree_hsml = hsml
#print (ok)
v=None
......@@ -199,14 +226,16 @@ class CTree:
v=np.reshape(self.__vel,(-1,3))
v=v[shuffle_idx_threshold, ]
v=np.reshape(v,(-1,))
cxv=CSnapshot(None).center(p,v,m*rho)
self.__tree_vel=v
cxv=cs.CSnapshot(None).center(p,v,m*rho)
if v is None: # no velocities
cxv[3]=0.0
cxv[4]=0.0
cxv[5]=0.0
if outfile is not None:
unso=CunsOut(outfile,"nemo")
unso=unsio.CunsOut(outfile,"nemo")
unso.setValueF("time",self.__time)
unso.setArrayF("all","pos",p)
if self.__vel is not None:
......@@ -216,3 +245,21 @@ class CTree:
unso.setArrayF("all","hsml",hsml)
unso.save()
return cxv
#
# getTreeDensity
#
def getTreeDensity(self):
"""
return rho and hsml computed in tree
"""
return self.__tree_rho,self.__tree_hsml
#
# getTreePart
#
def getTreePart(self):
"""
return pos,vel and mass used to computed the tree
"""
return self.__tree_pos,self.__tree_vel, self.__tree_mass
......@@ -29,6 +29,7 @@ class CUnsAnalysis:
store information used during analysis process
"""
uns_snap=None # pointer to UNS snpshot
snap_id=None
first=True
lock=[]
......@@ -122,9 +123,11 @@ class CUnsAnalysis:
# Feed QUEUE with list of snapshots
q = multiprocessing.Queue()
n=0
for snap in self.__slist: # loop on list os snsphots
#print "SNAP put :",snap
q.put(snap) # out a snapshot in the list
q.put("%s %d"%(snap,n)) # out a snapshot in the list + index
n=n+1
# start process jobs
processes=[] # list of processes
......@@ -176,9 +179,10 @@ class CUnsAnalysis:
while (not stop):
try:
print ("Core [",n,"] waiting...")
my_snap=queue_list.get(True,0.05) # we must use this line
# True means bloc during 0.05 sec,
# if nothing, then get raise Queue.Empty exception
my_snap,idx=queue_list.get(True,0.05).split() # we must use this line
# True means bloc during 0.05 sec,
# if nothing, then get raise Queue.Empty exception
data.snap_id=int(idx)
#my_snap=queue_list.get() # do not use this, could block if nothing to get
#time.sleep(0.01)
data.uns_snap=CSnapshot(my_snap,self.__select,verbose_debug=self.__vdebug)
......
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