Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F80440994
genergy
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sat, Aug 31, 18:02
Size
3 KB
Mime Type
text/x-python
Expires
Mon, Sep 2, 18:02 (2 d)
Engine
blob
Format
Raw Data
Handle
20371412
Attached To
rGTOOLS Gtools
genergy
View Options
#!/export/revaz/local/bin/python
'''
Extract and plot energy and mass values contained in the
output Gadget file called by default "energy.txt".
Yves Revaz
ven jun 9 10:06:11 CEST 2006
'''
from numpy import *
from pNbody import *
import SM
import string
import sys
import os
from pNbody.libutil import histogram
from optparse import OptionParser
from Gtools import *
from Gtools import io
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_log_options(parser)
parser.add_option("-o",
action="store",
dest="obs",
type="string",
default = 'EnergyTot',
help="observable name",
metavar=" NAME")
parser.add_option("--relative",
action="store_true",
dest="relative",
default = 0,
help="plot relative value")
(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
log = options.log
obs = options.obs
rel = options.relative
#######################################
# open sm
#######################################
g = Graph_Init(ps)
Graph_SetDefaultsGraphSettings(g)
colors = Graph_SetColorsForFiles(files,col)
#######################################
# LOOP
#######################################
# read files
for file in files:
try:
vals = io.read_new_energy(file)
except "NotNewEgyFileError":
vals = io.read_energy(file,iobs=None)
x = vals['Time']
if obs == 'EnergyTot':
y = 0.
nrjvals = ['EnergyInt','EnergyPot','EnergyKin','EnergyRadSph','EnergyRadSticky','EnergySfr','EnergyFeedback','EnergyBubbles','EnergyAGNHeat']
for nrjval in nrjvals:
if vals.has_key(nrjval):
print nrjval
y = y + vals[nrjval]
elif vals.has_key(obs):
y = vals[obs]
else:
print "unknown observable %s"%(obs)
sys.exit()
if rel:
y = 100*(fabs(y-y[0]))/y[0]
y = fabs(y)
# use log
if log != None:
x,y = Graph_UseLog(x,y,log)
if file == files[0]:
xmin,xmax,ymin,ymax = Graph_SetLimits(g,xmin,xmax,ymin,ymax,x,y)
g.box()
# plot points
g.ctype(colors[file])
g.connect(x,y)
# labels
g.ctype(0)
g.xlabel('T')
g.ylabel('%s'%obs)
g.ctype(0)
if log == 'xy' or log == 'yx':
g.xlabel('log T')
g.ylabel('log %s'%obs)
elif log == 'x':
g.xlabel('log T')
g.ylabel('%s'%obs)
elif log == 'y':
g.xlabel('T')
g.ylabel('log %s'%obs)
else:
g.xlabel('T')
g.ylabel('%s'%obs)
# -- end ---
Graph_End(g,ps)
Event Timeline
Log In to Comment