Page MenuHomec4science

pychem_plot_lifetime
No OneTemporary

File Metadata

Created
Mon, Nov 25, 09:57

pychem_plot_lifetime

#!/usr/bin/env python
from optparse import OptionParser
import Ptools as pt
from pNbody import *
from pNbody import units
import string
from scipy import optimize
from PyChem import chemistry
UnitLength_in_cm = 3.085e+21
UnitMass_in_g = 1.989e+43
UnitVelocity_in_cm_per_s = 20725573.785998672
UnitTime_in_s = 148849920000000.0
def parse_options():
usage = "usage: %prog [options] file"
parser = OptionParser(usage=usage)
parser = pt.add_postscript_options(parser)
parser = pt.add_ftype_options(parser)
parser = pt.add_reduc_options(parser)
parser = pt.add_center_options(parser)
parser = pt.add_select_options(parser)
parser = pt.add_cmd_options(parser)
parser = pt.add_display_options(parser)
parser = pt.add_info_options(parser)
parser = pt.add_limits_options(parser)
parser = pt.add_log_options(parser)
parser.add_option("--x",
action="store",
dest="x",
type="string",
default = 'r',
help="x value to plot",
metavar=" STRING")
parser.add_option("--y",
action="store",
dest="y",
type="string",
default = 'T',
help="y value to plot",
metavar=" STRING")
parser.add_option("--z",
action="store",
dest="z",
type="string",
default = None,
help="z value to plot",
metavar=" STRING")
parser.add_option("--legend",
action="store_true",
dest="legend",
default = False,
help="add a legend")
(options, args) = parser.parse_args()
pt.check_files_number(args)
files = args
return files,options
#######################################
# MakePlot
#######################################
def MakePlot(files,opt):
# some inits
datas = []
# read files
for file in files:
chemistry.init_chimie(file)
mmax = chemistry.get_Mmax()
mmin = chemistry.get_Mmin()
# mass range
ms = arange(mmin,mmax,1e-12).astype(float32)
z0 = 0.02
zs = z0 * 10**array([-10.,-1.,-0.25,0,0.25,0.5,])
################
# get values
################
colors = pt.Colors(n=len(zs))
for z in zs:
x = ms
y = zeros(len(x))
for i,m in enumerate(ms):
y[i] = chemistry.star_lifetime(z,x[i]) *UnitTime_in_s/(31536000)/1e6 # in Myr
x = x / (1.989e+33/UnitMass_in_g) # to solar mass
xlabel = r"$\rm{Star\,\,Mass [M_{\odot}]}$"
ylabel = r"$\rm{Life\,\,Time\,[Myr]}$"
label = "z=%6.2f (%s)"%(log10(z/z0),file)
data = pt.DataPoints(x,y,label=label,color=colors.get(),tpe='line')
datas.append(data)
# now, plot
for d in datas:
if d.tpe=='points' or d.tpe=='both':
pt.scatter(d.x,d.y,c=d.color,s=5,linewidths=0,marker='o',vmin=opt.zmin,vmax=opt.zmax)
if d.tpe=='line' or d.tpe=='both':
pt.plot(d.x,d.y,color=d.color)
# set limits and draw axis
xmin,xmax,ymin,ymax = pt.SetLimitsFromDataPoints(opt.xmin,opt.xmax,opt.ymin,opt.ymax,datas,opt.log)
# plot axis
pt.SetAxis(xmin,xmax,ymin,ymax,log=opt.log)
pt.xlabel(xlabel,fontsize=pt.labelfont)
pt.ylabel(ylabel,fontsize=pt.labelfont)
pt.grid(False)
if opt.legend:
pt.LegendFromDataPoints(datas,loc='upper right')
########################################################################
# MAIN
########################################################################
if __name__ == '__main__':
files,opt = parse_options()
pt.InitPlot(files,opt)
pt.pcolors
MakePlot(files,opt)
pt.EndPlot(files,opt)

Event Timeline