Commit 5bd8ffc9 authored by jclamber's avatar jclamber
Browse files

more pythons programs

git-svn-id: http://svn.oamp.fr/repos/uns_projects/trunk@106 f264a43e-d52d-4b82-913b-c2bd5215a18a
parent 2a1ca79a
#!/usr/bin/python
#
#
# save gas particles temperature 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
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# commandLine, parse the command line
def commandLine():
parser = argparse.ArgumentParser(description="Save stars particles born before/after a specific time")
parser.add_argument('input', help='UNS input file with gas particle')
parser.add_argument('output', help="NEMO output file ")
parser.add_argument('z', help="cut in z",type=float)
args = parser.parse_args()
compute(args.input,args.output,args.z)
# -----------------------------------------------------
# compute, is the core function
def compute(simname,out,z):
components="gas"
verbose=False
# 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," z=",z
# load frame
ok=uns.nextFrame("")
print ok
if (ok) :
ok,temp = uns.getArrayF("gas","temp")
if ( ok ) :
print "ok ",ok, temp
print "min=", temp.min()," max=",temp.max()
ok,timec= uns.getValueF("time")
ok,pos = uns.getArrayF("gas","pos")
print "in:",pos.size, pos.shape
pos=np.reshape(pos,(-1,3)) # pos reshaped in a 2D array [nbody,3]
ok,vel = uns.getArrayF("gas","vel")
vel=np.reshape(vel,(-1,3)) # vel reshaped in a 2D array [nbody,3]
ok,mass = uns.getArrayF("gas","mass")
ok,rho=uns.getArrayF("gas","rho")
idmax=np.argmax(rho)
x=pos[idmax,0]
y=pos[idmax,1]
z=pos[idmax,2]
pos[:,0] -= x
pos[:,1] -= y
pos[:,2] -= z
mask_z = ((pos[:,2] > -z) & (pos[:,2]<z))
print "mask_z:", mask_z,mask_z.size, mass.size
# instantiate output object
unso=CunsOut(out,"nemo"); # output file
# reshape in 1D array
pos = np.reshape(pos[mask_z],pos[mask_z].size)
print "out:",pos.size, pos.shape
vel = np.reshape(vel[mask_z],vel[mask_z].size)
mass = mass[mask_z]
temp = temp[mask_z]
hsml = np.zeros(temp.size,dtype='float32')
hsml += 1.0
#ok,hsml=uns.getArrayF("gas","hsml")
#hsml = hsml[mask_z]
print "HSML :", hsml.size , hsml, hsml.dtype
# save data
unso.setValueF("time",timec) # save time
unso.setArrayF("all","pos",pos) # save pos
unso.setArrayF("all","vel",vel) # save vel
unso.setArrayF("all","mass",mass) # save mass
unso.setArrayF("all","rho",temp) # save temp to rho
unso.setArrayF("all","hsml",hsml) # save hsml
unso.save()
else:
print "there are no temperature for gas in this snapshot !!!"
else :
print "Didn't load anything...."
# -----------------------------------------------------
# main program
commandLine() # parse command line
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