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

updates

parent 0d38bddd
Pipeline #325 skipped
#cmake
*build/
#qmake
*.user
# tilda
*~
# Compiled Object files
*.slo
*.lo
*.o
*.obj
# Compiled Dynamic libraries
*.so
*.so.*
*.dylib
*.dll
# Fortran module files
*.mod
# Compiled Static libraries
*.lai
*.la
*.a
*.lib
*.lo
# Executables
*.exe
*.out
*.app
# Debug files
*.dSYM/
*.su
# automake
Makefile.in
/autom4te.cache
/autoscan.log
/autoscan-*.log
/aclocal.m4
/compile
/config.h.in
/configure
/configure.scan
/depcomp
/install-sh
/missing
/stamp-h1
# cuda
*.i
*.ii
*.gpu
*.ptx
*.cubin
*.fatbin
......@@ -13,7 +13,7 @@ import numpy as np # arrays are treated as numpy arrays
# In[2]:
simname="mdf001%50"
simname="mdf001%1500"
components="gas,stars"
times="all"
verbose=False
......
#!/usr/bin/python
#
from __future__ import print_function
#
# save stars particles to density field for displaying with glnemo2
# MANDATORY
from py_unsio import * # import py_unsio package (UNSIO)
import numpy as np # arrays are treated as numpy arrays
import math
import argparse
import sys
#from IPython import embed
class snap:
time = None
nbody = None
mass = None
pos = None
vel = None
ids = None
array = None
hsml = None
rho = None
metal = None
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# commandLine, parse the command line
def commandLine():
f_hsml=0.1
parser = argparse.ArgumentParser(description="Save selected array into gas density field",
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('input', help='UNS input file with array particle')
parser.add_argument('output', help="gadget2 output file ")
parser.add_argument('comp', help="component to select")
parser.add_argument('array', help="array to select")
parser.add_argument('--hsml', help='hsml value',type=float,default=f_hsml)
#parser.add_argument('time', help="time of reference to keep stars particles")
args = parser.parse_args()
process(args.input,args.output,args.comp,args.array,args.hsml)
# -----------------------------------------------------
# selectarray
def selectarray(snap,f_hsml):
#select=(snap.array>=(snap.time-snap.time*dt/100.)) # select particles in the ramge of array
select=(snap.array>-1000000) # select particles in the ramge of array
snap.pos=np.reshape(snap.pos,(-1,3)) # pos reshaped in a 2D array [nbody,3]
# rescale pos
snap.pos = snap.pos[select]
snap.pos = np.reshape(snap.pos,snap.pos.size) # flatten the array (mandatory for unsio)
# rescale vel
if snap.vel.size > 0:
print ("yo")
snap.vel=np.reshape(snap.vel,(-1,3)) # pos reshaped in a 2D array [nbody,3]
snap.vel = snap.vel[select]
snap.vel = np.reshape(snap.vel,snap.vel.size) # flatten the array (mandatory for unsio)
#rescale mass
snap.mass = snap.mass[select]
# rescale array
snap.array = snap.array[select]
# hsml
snap.hsml=np.zeros(snap.array.size,dtype='float32')
snap.hsml += f_hsml
# -----------------------------------------------------
# Compute, is the core function
def process(simname,out,components,array_tag,f_hsml):
verbose=False
#timef=float(times)
# Create a UNSIO object
uns = CunsIn(simname,components,"all",verbose)
# bits="I" # select properties, particles Identities only here
# get file name
# sim_name=uns.getFileName()
print ("simname=",simname, " out=",out,file=sys.stderr)
print ("components=",components,file=sys.stderr)
print ("hsml=",f_hsml,file=sys.stderr)
# load frame
ok=uns.nextFrame("")
#print ok
if (ok) :
ok,snap.array = uns.getArrayF(components,array_tag)
if ( ok ) :
#print "ok ",ok, snap.array
print ("min=", snap.array.min()," max=",snap.array.max(),file=sys.stderr)
#embed()
ok,snap.time = uns.getValueF("time")
ok,snap.pos = uns.getArrayF(components,"pos")
ok,snap.vel = uns.getArrayF(components,"vel")
ok,snap.mass = uns.getArrayF(components,"mass")
# select array
#selectarray(snap,f_hsml)
# hsml
snap.hsml=np.zeros(snap.array.size,dtype='float32')
snap.hsml += f_hsml
# instantiate output object
unso=CunsOut(out,"gadget2",verbose); # output file
# save data
unso.setValueF("time",snap.time) # save time
unso.setArrayF("gas","pos",snap.pos) # save pos
#unso.setArrayF("all","vel",snap.vel) # save vel
unso.setArrayF("gas","mass",snap.mass) # save mass
unso.setArrayF("gas","rho",snap.array) # save array to rho
unso.setArrayF("gas","hsml",snap.hsml) # save hsml
unso.save()
else:
print ("there are no array %s in this snapshot !!!"%(array_tag),file=sys.stderr)
else :
print ("Didn't load anything....",file=sys.stderr)
# -----------------------------------------------------
# main program
commandLine() # parse command line
......@@ -3,7 +3,7 @@
# For more information about how to use UNSIO, visit:
# http://projets.lam.fr/projects/unsio/
# -----------------------------------------------------------------------
# Copyright Jean-Charles LAMBERT (CeSAM)- 2008-2014
# Copyright Jean-Charles LAMBERT (CeSAM)- 2008-2016
#
# e-mail: Jean-Charles.Lambert@lam.fr
# address: Centre de donneeS Astrophysique de Marseille (CeSAM)
......@@ -28,7 +28,6 @@ import sys, getopt
# compute
def compute(file,out,comp,take,bits,mmult):
compchk="gas,halo,disk,bulge,stars,bndry"
uns=CunsIn(file,comp,"all")
if uns.nextFrame(bits):
......@@ -94,7 +93,14 @@ def printAndSaveProp(uns,unso,comp,take,mmult):
vel=keepEveryTake(vel,3,take)
unso.setArrayF(comp,"vel",vel) # save vel
# return a 1D numpy data array with rho
# return a 1D numpy data array with acc
ok,acc=uns.getArrayF(comp,"acc")
if ok:
print "acc =",acc
vel=keepEveryTake(acc,3,take)
unso.setArrayF(comp,"acc",acc) # save vel
# return a 1D numpy data array with rho
ok,rho=uns.getArrayF(comp,"rho")
if ok:
print "rho =",rho
......@@ -137,6 +143,14 @@ def printAndSaveProp(uns,unso,comp,take,mmult):
metal=keepEveryTake(metal,1,take)
unso.setArrayF(comp,"metal",metal) # save mettalicity
# return a 1D numpy data array with potential
ok,pot=uns.getArrayF(comp,"pot")
if ok:
print "pot =",pot
metal=keepEveryTake(pot,1,take)
unso.setArrayF(comp,"pot",pot) # save mettalicity
# return a 1D numy data array with id
ok,indexes=uns.getArrayI(comp,"id")
......
#!/usr/bin/python
#
from __future__ import print_function
#
# save stars particles to density field for displaying with glnemo2
# MANDATORY
from py_unsio import * # import py_unsio package (UNSIO)
import numpy as np # arrays are treated as numpy arrays
import math
import argparse
import sys
#from IPython import embed
class snap:
time = None
nbody = None
mass = None
pos = None
vel = None
ids = None
pot = None
hsml = None
rho = None
metal = None
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# commandLine, parse the command line
def commandLine():
dt=3
f_hsml=0.1
parser = argparse.ArgumentParser(description="Save pot into density field of a NEMO snapshot ",
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('input', help='UNS input file with pot particle')
parser.add_argument('output', help="NEMO output file ")
parser.add_argument('comp', help="component to select")
parser.add_argument('--dt', help="save particles:[age > time-time*dt%%],(time=current time)",default=dt,type=float)
parser.add_argument('--hsml', help='hsml value',type=float,default=f_hsml)
#parser.add_argument('time', help="time of reference to keep stars particles")
args = parser.parse_args()
process(args.input,args.output,args.comp,args.dt,args.hsml)
# -----------------------------------------------------
# selectpot
def selectpot(snap,dt,f_hsml):
#select=(snap.pot>=(snap.time-snap.time*dt/100.)) # select particles in the ramge of pot
select=(snap.pot>-1000000) # select particles in the ramge of pot
snap.pos=np.reshape(snap.pos,(-1,3)) # pos reshaped in a 2D array [nbody,3]
# rescale pos
snap.pos = snap.pos[select]
snap.pos = np.reshape(snap.pos,snap.pos.size) # flatten the array (mandatory for unsio)
# rescale vel
if snap.vel.size > 0:
print ("yo")
snap.vel=np.reshape(snap.vel,(-1,3)) # pos reshaped in a 2D array [nbody,3]
snap.vel = snap.vel[select]
snap.vel = np.reshape(snap.vel,snap.vel.size) # flatten the array (mandatory for unsio)
#rescale mass
snap.mass = snap.mass[select]
# rescale pot
snap.pot = snap.pot[select]
# hsml
snap.hsml=np.zeros(snap.pot.size,dtype='float32')
snap.hsml += f_hsml
# -----------------------------------------------------
# compute, is the core function
def process(simname,out,components,dt,f_hsml):
verbose=False
#timef=float(times)
# Create a UNSIO object
uns = CunsIn(simname,components,"all",verbose)
# bits="I" # select properties, particles Identities only here
# get file name
# sim_name=uns.getFileName()
print ("simname=",simname, " out=",out,file=sys.stderr)
print ("components=",components,file=sys.stderr)
print ("hsml=",f_hsml,file=sys.stderr)
# load frame
ok=uns.nextFrame("")
#print ok
if (ok) :
ok,snap.pot = uns.getArrayF(components,"pot")
if ( ok ) :
#print "ok ",ok, snap.pot
print ("min=", snap.pot.min()," max=",snap.pot.max(),file=sys.stderr)
#embed()
ok,snap.time = uns.getValueF("time")
ok,snap.pos = uns.getArrayF(components,"pos")
ok,snap.vel = uns.getArrayF(components,"vel")
ok,snap.mass = uns.getArrayF(components,"mass")
# select pot according to dt
selectpot(snap,dt,f_hsml)
# instantiate output object
unso=CunsOut(out,"gadget2",True); # output file
# save data
unso.setValueF("time",snap.time) # save time
unso.setArrayF("gas","pos",snap.pos) # save pos
#unso.setArrayF("all","vel",snap.vel) # save vel
unso.setArrayF("gas","mass",snap.mass) # save mass
unso.setArrayF("gas","rho",snap.pot) # save pot to rho
unso.setArrayF("gas","hsml",snap.hsml) # save hsml
unso.save()
else:
print ("there are no age for stars in this snapshot !!!",file=sys.stderr)
else :
print ("Didn't load anything....",file=sys.stderr)
# -----------------------------------------------------
# main program
commandLine() # parse command line
......@@ -160,6 +160,8 @@ void addComponent(CSnapshot<T> &mysnap,std::string comp, uns::CunsIn2<T> * uns1,
addArray(mysnap,comp,"pos" ,3,uns1,uns2,unsout,verbose);
addArray(mysnap,comp,"vel" ,3,uns1,uns2,unsout,verbose);
addArray(mysnap,comp,"mass",1,uns1,uns2,unsout,verbose);
addArray(mysnap,comp,"pot",1,uns1,uns2,unsout,verbose);
addArray(mysnap,comp,"acc",3,uns1,uns2,unsout,verbose);
if (comp == "gas") {
addArray(mysnap,comp,"u" ,1,uns1,uns2,unsout,verbose);
addArray(mysnap,comp,"hsml" ,1,uns1,uns2,unsout,verbose);
......
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