Page MenuHomec4science

gplot_r-val
No OneTemporary

File Metadata

Created
Fri, Sep 27, 00:48

gplot_r-val

#!/usr/bin/env python
'''
Plot value computed in a spherical grid, as a function of the radius
Yves Revaz
Thu Jan 10 10:50:06 CET 2008
'''
from pNbody import *
from pNbody import myNumeric
from pNbody import libdisk
from pNbody import libgrid
import SM
import string
import sys
import os
from optparse import OptionParser
from Gtools import *
def parse_options():
usage = "usage: %prog [options] file"
parser = OptionParser(usage=usage)
parser = add_postscript_options(parser)
parser = add_color_options(parser)
parser = add_limits_options(parser)
parser = add_units_options(parser)
parser = add_log_options(parser)
parser = add_reduc_options(parser)
parser = add_center_options(parser)
parser = add_select_options(parser)
parser = add_cmd_options(parser)
parser = add_display_options(parser)
parser.add_option("-t",
action="store",
dest="ftype",
type="string",
default = None,
help="type of the file",
metavar=" TYPE")
parser.add_option("--val",
action="store",
dest="val",
type="string",
default = None,
help="value to plot, ex: --val='nb.u' ",
metavar=" STR")
(options, args) = parser.parse_args()
if options.colors!=None:
exec("options.colors = array([%s])"%(options.colors))
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()
ps = options.ps
col = options.colors
xmin = options.xmin
xmax = options.xmax
ymin = options.ymin
ymax = options.ymax
logxy = options.log
reduc = options.reduc
ftype = options.ftype
center = options.center
select = options.select
cmd = options.cmd
display = options.display
val = options.val
#localsystem = Set_SystemUnits_From_Options(options)
#######################################
# define output system of unit
#######################################
#outputunits = units.UnitSystem('mks',[units.Unit_km, units.Unit_Ms, units.Unit_s , units.Unit_K, units.Unit_mol, units.Unit_C])
#######################################
# open sm
#######################################
g = Graph_Init(ps)
Graph_SetDefaultsGraphSettings(g)
colors = Graph_SetColorsForFiles(files,col)
#######################################
# LOOP
#######################################
# read files
for file in files:
nb = Nbody(file,ftype=ftype)
# set model units
#nb.localsystem_of_units = localsystem
# center the model
if center=='hdcenter':
print "centering %s"%(center)
nb.hdcenter()
elif center=='histocenter':
print "centering %s"%(center)
nb.histocenter()
# select
if select!=None and select!="None":
print "select %s"%(select)
nb = nb.select(select)
# reduc
if reduc!= None:
print "reducing %s"%(reduc)
nb = nb.reduc(reduc)
# cmd
if (cmd!= None) and (cmd!= 'None'):
print nb.nbody
print "exec : %s"%cmd
exec(cmd)
# display
if (display!= None) and (display!= 'None'):
nb.display(obs=None,view=display,marker='cross')
################
# get values
################
r = nb.rxyz()
cmd = "y = %s"%(val)
print cmd
exec(cmd)
x = r
y = y
# use log
if logxy != None:
x,y = Graph_UseLog(x,y,logxy)
g.ticksize(-1,0,-1,-1)
if (file == files[0]):
xmin,xmax,ymin,ymax = Graph_SetLimits(g,xmin,xmax,ymin,ymax,x,y)
Graph_DrawBox(g,xmin,xmax,ymin,ymax,logxy)
g.ctype(colors[file])
# plot points
g.points(x,y)
g.ctype(0)
g.xlabel('Radius')
g.ylabel('Val')
# -- end ---
Graph_End(g,ps)

Event Timeline