Commit 2a1ca79a authored by jclamber's avatar jclamber
Browse files

more pythons programs

git-svn-id: http://svn.oamp.fr/repos/uns_projects/trunk@105 f264a43e-d52d-4b82-913b-c2bd5215a18a
parent f1091a5c
#!/usr/bin/python
#
#
# 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
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# 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 stars particle')
parser.add_argument('output', help="NEMO output file ")
parser.add_argument('time', help="time of reference to keep stars particles")
args = parser.parse_args()
compute(args.input,args.output,args.time)
# -----------------------------------------------------
# compute, is the core function
def compute(simname,out,times):
components="stars"
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," times=",times
# load frame
ok=uns.nextFrame("")
print ok
if (ok) :
ok,ages = uns.getArrayF("stars","age")
if ( ok ) :
print "ok ",ok, ages
print "min=", ages.min()," max=",ages.max()
ok,timec= uns.getValueF("time")
ok,pos = uns.getArrayF("stars","pos")
ok,vel = uns.getArrayF("stars","vel")
ok,mass = uns.getArrayF("stars","mass")
hsml=np.zeros(ages.size,dtype='float32')
hsml += 1.0
print "HSML :", hsml.size , hsml, hsml.dtype
# instantiate output object
unso=CunsOut(out,"nemo"); # output file
# 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",ages) # save ages to rho
unso.setArrayF("all","hsml",hsml) # save hsml
unso.save()
else:
print "there are no age for stars in this snapshot !!!"
else :
print "Didn't load anything...."
# -----------------------------------------------------
# main program
commandLine() # parse command line
#!/usr/bin/python
#
#
# 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
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# 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 stars particle')
parser.add_argument('output', help="NEMO output file ")
#parser.add_argument('time', help="time of reference to keep stars particles")
args = parser.parse_args()
compute(args.input,args.output)
# -----------------------------------------------------
# compute, is the core function
def compute(simname,out):
components="stars"
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
# load frame
ok=uns.nextFrame("")
print ok
if (ok) :
ok,metal = uns.getArrayF("stars","metal")
if ( ok ) :
print "ok ",ok, metal
print "min=", metal.min()," max=",metal.max()
ok,timec= uns.getValueF("time")
ok,pos = uns.getArrayF("stars","pos")
ok,vel = uns.getArrayF("stars","vel")
ok,mass = uns.getArrayF("stars","mass")
hsml=np.zeros(metal.size,dtype='float32')
hsml += 1.0
print "HSML :", hsml.size , hsml, hsml.dtype
# instantiate output object
unso=CunsOut(out,"nemo"); # output file
# 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",metal) # save metal to rho
unso.setArrayF("all","hsml",hsml) # save hsml
unso.save()
else:
print "there are no age for stars in this snapshot !!!"
else :
print "Didn't load anything...."
# -----------------------------------------------------
# main program
commandLine() # parse command line
......@@ -2,8 +2,8 @@
#
# Find out gas life of particles
#
# save stars particles born before/after a specific time
# MANDATORY
from py_unsio import * # import py_unsio package (UNSIO)
......@@ -15,7 +15,7 @@ import argparse
# commandLine, parse the command line
def commandLine():
parser = argparse.ArgumentParser(description="Save stars particles before/after a specific time")
parser = argparse.ArgumentParser(description="Save stars particles born before/after a specific time")
parser.add_argument('input', help='UNS input file with stars particle')
parser.add_argument('output', help="NEMO output file ")
parser.add_argument('time', help="time of reference to keep stars particles")
......
#!/usr/bin/python
from uns_simu import *
import argparse
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# commandLine, parse the command line
def commandLine():
dbname=""
# help
parser = argparse.ArgumentParser(description="UNS test python",
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
# options
parser.add_argument('simname', help='Simulation name')
parser.add_argument('--dbname',help='UNS database file name', default=dbname)
# parse
args = parser.parse_args()
# start main funciton
process(args.simname,args.dbname)
# -----------------------------------------------------
# process, is the core function
def process(simname,dbname):
test = UnsSimu(simname,dbname)
# -----------------------------------------------------
# main program
commandLine() # parse command line
#/usr/bin/python
import sqlite3
import os,sys
class UnsSimu:
'sqlite3 management for UNS sqlite3 database'
__conn=0 # connection database handler
name="" # simulation name
dbname="/pil/programs/DB/simulation.dbl" # database simulation name
__status=1
__dbunsio=".unsio"
# constructor
def __init__(self,name,dbname="") :
self.name = name
if (dbname != "" ) :
self.dbname = dbname
if (not os.path.isfile(dbname)) :
print 'sqlite3 db file ['+dbname+'] does not exist...\n'
self.__status = 0;
else :
self.__conn = sqlite3.connect(dbname)
self.__status = 1
else : # we must parse .unsio file
status,self.dbname=self.parseDotUnsio("")
self.__conn = sqlite3.connect(dbname)
self.__status = 1
# parse $HOME/.unsio file to detect db file name
def parseDotUnsio(self,file):
inputfile =file
if (file == "" ):
inputfile=os.environ['HOME']+"/"+self.__dbunsio
print "Input file:",inputfile
gparam={}
try:
gp=open(inputfile,"r")
except IOError:
print "no file ["+inputfile+"], will use default :"+self.dbname
return False,self.dbname
for line in gp:
data=line.split()
if (len(data)>1 and data[0]!='%' and data[0]!='#'):
gparam[data[0]] = data[1]
#print data
if (gparam['dbname']!="") :
return True,gparam['dbname']
else:
False,self.dbname
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