Page MenuHomec4science

gselectvals
No OneTemporary

File Metadata

Created
Sun, Aug 18, 03:40

gselectvals

#!/home/revaz/local/bin/python
'''
Plot histogram of a certain value of the model
Yves Revaz
ven oct 6 10:58:38 CEST 2006
'''
from numarray import *
from Nbody import *
import string
import sys
import os
from libjeans import *
from Nbody.libutil import histogram
from optparse import OptionParser
from Gtools import *
from Gtools import vanderwaals as vw
def parse_options():
usage = "usage: %prog [options] file"
parser = OptionParser(usage=usage)
parser = add_limits_options(parser)
parser = add_reduc_options(parser)
parser = add_select_options(parser)
parser.add_option("-t",
action="store",
dest="ftype",
type="string",
default = None,
help="type of the file",
metavar=" TYPE")
parser.add_option("--cmd",
action="store",
dest="cmd",
type="string",
default = 'v = nb.T()',
help="command to extract value ex. 'v = nb.T()' ",
metavar=" STRING")
parser.add_option("-w",
action="store",
dest="w",
type="string",
default = None,
help="write output (particles in the graph)",
metavar=" STRING")
parser.add_option("--min",
action="store",
dest="xmin",
type="float",
default = None,
help="min value to select)",
metavar=" FLOAT")
parser.add_option("--max",
action="store",
dest="xmax",
type="float",
default = None,
help="max value to select)",
metavar=" FLOAT")
(options, args) = parser.parse_args()
if len(args) == 0:
print "you must specify a filename"
sys.exit(0)
files = args
return files,options
#############################
# graph
#############################
# get options
files,options = parse_options()
xmin = options.xmin
xmax = options.xmax
reduc = options.reduc
ftype = options.ftype
select = options.select
cmd = options.cmd
w = options.w
#######################################
# LOOP
#######################################
# read files
for file in files:
nb = Nbody(file,ftype=ftype)
# select
if select!=None:
print "select %s"%(select)
nb = nb.select(select)
if reduc!= None:
print "reducing %s"%(reduc)
nb = nb.reduc(reduc)
exec(cmd)
if xmin==None:
xmin = min(v)
if xmax==None:
xmax = max(v)
# write submodel
if w!= None:
c = (v>xmin)*(v<xmax)
nb = nb.selectc(c)
nb.rename(w)
nb.write()

Event Timeline