Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F119357342
pychem_plot_SNII_yields_withZ
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
Thu, Jun 26, 08:37
Size
4 KB
Mime Type
text/x-python
Expires
Sat, Jun 28, 08:37 (1 d, 19 h)
Engine
blob
Format
Raw Data
Handle
26992056
Attached To
rGEAR Gear
pychem_plot_SNII_yields_withZ
View Options
#!/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")
parser.add_option("--MgFe",
action="store_true",
dest="MgFe",
default = False,
help="add Mg/Fe ratio")
parser.add_option("--elts",
action="store",
type="string",
dest="elts",
default = None,
help="element name")
parser.add_option("-Z","--Z",
action="store",
dest="Z",
type="float",
default = 0.02,
help="metallicity",
metavar=" FLOAT")
(options, args) = parser.parse_args()
pt.check_files_number(args)
files = args
return files,options
#######################################
# MakePlot
#######################################
def MakePlot(files,opt):
# some inits
datas = []
linest = pt.LineStyles()
if opt.elts !=None:
opt.elts = string.split(opt.elts,',')
# read files
for file in files:
chemistry.init_chimie(file)
nelts = chemistry.get_allnelts()
labels = chemistry.get_allelts_labels()
mmax = chemistry.get_Mmax()
mmin = chemistry.get_Mmin()
# mass range
ms = arange(mmin,mmax,1e-12).astype(float32)
################
# get values
################
if opt.elts==None:
elts = labels
else:
elts = opt.elts
colors = pt.Colors(n=len(elts))
#for nelt in xrange(nelts):
for elt in elts:
nelt = labels.index(elt)
print elt,nelt
x = ms
y = zeros(len(x))
for i,m in enumerate(ms):
y[i] = chemistry.SNII_single_mass_ejection_Z(m,opt.Z)[nelt]
x = x / (1.989e+33/UnitMass_in_g) # to solar mass
xlabel = r"$\rm{Star\,\,Mass [M_{\odot}]}$"
ylabel = r"$\rm{Mass\,\,Fraction}$"
label = "%s (%s)"%(labels[nelt],file)
data = pt.DataPoints(x,y,label=label,color=colors.get(),tpe='line',linestyle=linest.current())
datas.append(data)
linest.next()
if opt.MgFe:
Mg=None
Fe=None
for d in datas:
if d.label[:2]=='Mg':
Mg=d.y
x=d.x
if d.label[:2]=='Fe':
Fe=d.y
x=d.x
if Mg!=None and Fe!=None:
y=Mg/Fe
label = "%s"%("MgFe")
data = pt.DataPoints(x,y,label=label,color=colors.get(),tpe='line',linestyle=linest.current())
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,ls=d.linestyle)
# 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='lower left')
########################################################################
# MAIN
########################################################################
if __name__ == '__main__':
files,opt = parse_options()
pt.InitPlot(files,opt)
pt.pcolors
MakePlot(files,opt)
pt.EndPlot(files,opt)
Event Timeline
Log In to Comment