Page MenuHomec4science

gplot_histoT
No OneTemporary

File Metadata

Created
Sat, Feb 1, 09:51

gplot_histoT

#!/usr/bin/env python
'''
Plot an histogram of temperature of particles
Yves Revaz
lun jui 3 15:45:37 CEST 2006
'''
from numarray import *
from Nbody import *
from Nbody import myNumeric
import SM
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_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_histogram_options(parser)
parser.add_option("-t",
action="store",
dest="ftype",
type="string",
default = None,
help="type of the file",
metavar=" TYPE")
parser.add_option("--cgs",
action="store_true",
dest="cgs",
default = 0,
help="invert into cgs units")
# parser.add_option("--gamma",
# action="store",
# dest="gamma",
# type="float",
# default=5/3.,
# help="adiabatic index")
# parser.add_option("--mu",
# action="store",
# dest="mu",
# type="float",
# default=2,
# help="mean molecular mass")
parser.add_option("--av",
action="store",
dest="av",
type="float",
default=0,
help="Av consante (in cgs)")
parser.add_option("--bv",
action="store",
dest="bv",
type="float",
default=0,
help="Bv consante (in cgs)")
(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
histogram = options.histogram
cgs = options.cgs
ftype = options.ftype
#gamma = options.gamma
#mu = options.mu
av = options.av
bv = options.bv
localsystem = Set_SystemUnits_From_Options(options)
#######################################
# define output system of unit
#######################################
outputunits = UnitSystem('mks',[Unit_kpc, Unit_Ms, Unit_yr , Unit_K, Unit_mol, 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)
nb = nb.select('gas')
#
nb.localsystem_of_units = localsystem
# compute temperature
x = nb.T()
y = nb.mass/sum(nb.mass)
# plot points
if histogram:
nb = 50
xmn = min(x)
xmx = max(x)
xb = arange(xmn,xmx,(xmx-xmn)/nb)
yb = myNumeric.whistogram(x.astype(Float),y.astype(Float),xb.astype(Float))
x = xb
y = yb
# use log
if log != None:
x,y = Graph_UseLog(x,y,log)
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,log)
g.ctype(colors[file])
# plot points
if histogram:
g.histogram(x,y)
else:
g.points(x,y)
g.ctype(0)
if log == 'xy' or log == 'yx':
g.xlabel('log T')
g.ylabel('log mass fraction')
elif log == 'x':
g.xlabel('log T')
g.ylabel('mass fraction')
elif log == 'y':
g.xlabel('T')
g.ylabel('log mass fraction')
else:
g.xlabel('T')
g.ylabel('mass fraction')
# -- end ---
Graph_End(g,ps)

Event Timeline