Page MenuHomec4science

gplotfmass
No OneTemporary

File Metadata

Created
Tue, Jun 18, 18:28

gplotfmass

#!/usr/bin/env python
'''
Extract and plot energy and mass values contained in the
output Gadget file called by default "energy.txt".
Yves Revaz
Tue May 31 10:18:56 CEST 2005
'''
import sys
from numarray import *
import SM
from Nbody import *
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("-l", "--label",
# action="store_true",
# dest="label",
# default=0,
# help="display the movie")
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("-p",
action="store",
dest="ps",
type="string",
default = None,
help="postscript filename",
metavar=" FILE")
parser.add_option("-o",
action="store",
dest="obs",
type="string",
default = 'etot',
help="observable name",
metavar=" NAME")
parser.add_option("-m","--mode",
action="store",
dest="mode",
type="string",
default = 'normal',
help="mode",
metavar=" NAME")
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
#############################
# graph
#############################
# get options
files,options = parse_options()
ps = options.ps
mnx = options.mnx
mxx = options.mxx
mny = options.mny
mxy = options.mxy
obs = options.obs
col = options.colors
mode= options.mode
# 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
# read files
for file in files:
t,m1,m2,m3,m4,m5,m6=g.read(file,[0,29,30,31,32,33,34])
mt = m1+m2+m3+m4+m5+m6
# mass fraction
m1 = m1/mt
m2 = m2/mt
m3 = m3/mt
m4 = m4/mt
m5 = m5/mt
m6 = m6/mt
x = mt/mt
if mode == 'normal':
if file == files[0]:
# set limits
if mnx==None:
mnx = min(t)
if mxx==None:
mxx = max(t)
if mny==None:
mny = min(x)
if mxy==None:
mxy = max(x)
g.limits(mnx,mxx,mny,mxy)
g.box()
# draw line
g.ctype(colors[file])
#g.connect(t,m1)
#g.connect(t,m2)
g.connect(t,m3)
elif mode == 'fraction':
if file == files[0]:
# set limits
if mnx==None:
mnx = min(t)
if mxx==None:
mxx = max(t)
if mny==None:
mny = min(x)
if mxy==None:
mxy = max(x)
g.limits(mnx,mxx,mny,mxy)
f1 = m3 # stars
f2 = f1 + m4 # sn
f3 = f2 + m1 # wg
f4 = f3 + m2 # cg
# paint surfaces
tf = t[-1]+1
t = concatenate((array([0]),t ,array([tf])))
f1 = concatenate((array([0]),f1,array([0])))
f2 = concatenate((array([0]),f2,array([0])))
f3 = concatenate((array([0]),f3,array([0])))
f4 = concatenate((array([0]),f4,array([0])))
g.ctype(64)
g.shade(0,t,f4)
g.ctype(192)
g.shade(0,t,f3)
g.ctype(128)
g.shade(0,t,f2)
g.ctype(165)
g.shade(0,t,f1)
g.ctype(0)
# draw lines
g.ctype(colors[file])
g.connect(t,f1)
g.connect(t,f2)
g.connect(t,f3)
g.connect(t,f4)
g.box()
# labels
g.ctype(0)
g.xlabel('T')
g.ylabel('mass fraction')
# -- end ---
if ps==None:
g.show()
else:
g.write()
g.clean()

Event Timeline