Page MenuHomec4science

gprofile
No OneTemporary

File Metadata

Created
Wed, May 22, 16:54

gprofile

#!/usr/bin/env python
from Nbody import *
import sys
import copy
import numarray.ieeespecial as ieee
try:
from optparse import OptionParser
except ImportError:
from optik import OptionParser
def parse_options():
usage = "usage: %prog [options] file"
parser = OptionParser(usage=usage)
parser.add_option("--minx",
action="store",
dest="mnx",
default=None,
help="min value in x")
parser.add_option("--maxx",
action="store",
dest="mxx",
default=None,
help="max value in x")
parser.add_option("--miny",
action="store",
dest="mny",
default=None,
help="min value in y")
parser.add_option("--maxy",
action="store",
dest="mxy",
default=None,
help="max value in y")
parser.add_option("--log",
action="store_true",
dest="logplot",
default = 0,
help="logarithm plot")
parser.add_option("--optimize",
action="store_true",
dest="optimize",
default = 0,
help="set rmax to the max radius")
parser.add_option("-p",
action="store",
dest="ps",
type="string",
default = None,
help="postscript filename",
metavar=" FILE")
parser.add_option("-t",
action="store",
dest="ftype",
type="string",
default = None,
help="type of the file",
metavar=" TYPE")
parser.add_option("--center",
action="store",
dest="center",
type="float",
default=None,
help="radius")
parser.add_option("--factor",
action="store",
dest="factor",
type="float",
default=1.,
help="multiply density by factor")
parser.add_option("--nb",
action="store",
dest="nb",
type="int",
default=25,
help="number of bins")
parser.add_option("--rm",
action="store",
dest="rm",
type="float",
default=50,
help="max radius")
parser.add_option("-c",
action="store",
dest="colors",
type="string",
default = None,
help="colors",
metavar=" 0,64,192")
(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
Error.setMode(dividebyzero="ignore", underflow="ignore", invalid="warn")
######################################################################
# M A I N
######################################################################
######################
# get options
files,options = parse_options()
ps = options.ps
mnx = options.mnx
mxx = options.mxx
mny = options.mny
mxy = options.mxy
logplot = options.logplot
col = options.colors
ftype = options.ftype
center = options.center
factor = options.factor
optimize = options.optimize
rm = options.rm
nb = options.nb
######################
# open sm
if ps==None:
g = SM.plot("x11 -bg white -fg black ")
else:
g = SM.plot("postencap %s"%ps)
# some init
g.palette('bgyrw')
g.expand(0.999)
# set colors
colors = {}
i = 0
for file in files:
if col!=None:
colors[file]=col[i]
else:
colors[file] = i*255/len(files)
i = i + 1
for file in files:
nbdy = Nbody(file,ftype=ftype)
if center!=None:
nbdy.histocenter(rbox=center)
if optimize:
rm1 = max(nbdy.minert())*2.
rm2 = max(nbdy.rxyz())
rm = min(rm1,rm2)
r,dens = nbdy.mdens(nb=nb,rm=rm)
dens = dens*factor
if logplot:
r = log10(r)
dens = log10(dens)
# replace bad values
c = 1-ieee.isinf(dens)
r = compress(c,r)
dens = compress(c,dens)
if file == files[0]:
# set limits
if mnx==None:
mnx = min(r)
if mxx==None:
mxx = max(r)
if mny==None:
mny = min(dens)
if mxy==None:
mxy = max(dens)
g.ctype(0)
g.limits(mnx,mxx,mny,mxy)
g.box()
# draw line
g.ctype(colors[file])
g.connect(r,dens)
# labels
g.ctype(0)
g.xlabel('R')
g.ylabel('density')
# -- end ---
if ps==None:
g.show()
else:
g.write()
g.clean()

Event Timeline