Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F101346106
gSNvsTime
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, Feb 8, 05:11
Size
3 KB
Mime Type
text/x-python
Expires
Mon, Feb 10, 05:11 (1 d, 21 h)
Engine
blob
Format
Raw Data
Handle
24140363
Attached To
rGTOOLS Gtools
gSNvsTime
View Options
#!/usr/bin/env python
'''
Extract and plot sfr contained in the
output Gadget file called by default "sfr.txt".
Yves Revaz
Mon Feb 2 19:15:39 CET 2009
'''
import
Ptools
as
pt
from
numpy
import
*
from
pNbody
import
*
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
=
pt
.
add_postscript_options
(
parser
)
parser
=
pt
.
add_limits_options
(
parser
)
parser
=
pt
.
add_log_options
(
parser
)
parser
=
pt
.
add_cmd_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
=
"rel"
,
default
=
0
,
help
=
"plot relative value"
)
parser
.
add_option
(
"--nc"
,
action
=
"store"
,
dest
=
"nc"
,
type
=
"float"
,
default
=
1000
,
help
=
"number of points per bin"
)
parser
.
add_option
(
"--rf"
,
action
=
"store"
,
dest
=
"rf"
,
type
=
"float"
,
default
=
1
,
help
=
"reduction factor"
)
parser
.
add_option
(
"--integrate"
,
action
=
"store_true"
,
dest
=
"integrate"
,
default
=
0
,
help
=
"integrate values"
)
parser
.
add_option
(
"--derive"
,
action
=
"store_true"
,
dest
=
"derive"
,
default
=
0
,
help
=
"derive values"
)
(
options
,
args
)
=
parser
.
parse_args
()
if
len
(
args
)
==
0
:
print
"you must specify a filename"
sys
.
exit
(
0
)
files
=
args
return
files
,
options
#######################################
# MakePlot
#######################################
def
MakePlot
(
files
,
opt
):
# some inits
palette
=
pt
.
GetPalette
()
colors
=
pt
.
SetColorsForFiles
(
files
,
palette
)
labels
=
[]
# observable
opt
.
obs
=
string
.
split
(
opt
.
obs
,
','
)
# read files
for
file
in
files
:
t
,
Nchim
,
NSNIa
,
NSNII
,
EgySN
,
EgySNThermal
,
EgySNKinetic
,
Nwind
,
Noldwind
,
Nflag
=
pt
.
io
.
read_ascii
(
file
,[
0
,
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
])
data
=
{}
data
[
't'
]
=
t
data
[
'Nchim'
]
=
Nchim
data
[
'NSNIa'
]
=
NSNIa
data
[
'NSNII'
]
=
NSNII
data
[
'EgySN'
]
=
EgySN
data
[
'EgySNThermal'
]
=
EgySNThermal
data
[
'EgySNKinetic'
]
=
EgySNKinetic
data
[
'Nwind'
]
=
Nwind
data
[
'Noldwind'
]
=
Noldwind
data
[
'Nflag'
]
=
Nflag
datas
=
[]
for
obs
in
opt
.
obs
:
if
obs
==
'EperSN'
:
x
=
data
[
't'
]
y
=
where
((
NSNIa
+
NSNII
)
>
0
,
EgySN
/
(
NSNIa
+
NSNII
),
0
)
datas
.
append
(
pt
.
DataPoints
(
x
,
y
))
else
:
datas
.
append
(
pt
.
DataPoints
(
data
[
't'
],
data
[
obs
]))
# reduction
if
opt
.
rf
>
1
:
for
d
in
datas
:
d
.
reduc
(
opt
.
rf
)
# integrate
if
opt
.
integrate
:
for
d
in
datas
:
d
.
integrate
()
# derive
if
opt
.
derive
:
for
d
in
datas
:
d
.
derive
()
# plot points
for
d
in
datas
:
pt
.
plot
(
d
.
x
,
d
.
y
)
xmin
,
xmax
,
ymin
,
ymax
=
pt
.
SetLimitsFromDataPoints
(
opt
.
xmin
,
opt
.
xmax
,
opt
.
ymin
,
opt
.
ymax
,
datas
,
opt
.
log
)
pt
.
SetAxis
(
xmin
,
xmax
,
ymin
,
ymax
,
log
=
opt
.
log
)
# labels
pt
.
xlabel
(
r'$\textrm{Time}$'
,
fontsize
=
pt
.
labelfont
)
pt
.
ylabel
(
r'$\textrm{
%s
}$'
%
(
opt
.
obs
),
fontsize
=
pt
.
labelfont
)
if
__name__
==
'__main__'
:
files
,
opt
=
parse_options
()
pt
.
InitPlot
(
files
,
opt
)
#pt.figure(figsize=(8*2,6*2))
#pt.figure(dpi=10)
pt
.
pcolors
#fig = pt.gcf()
#fig.subplots_adjust(left=0.1)
#fig.subplots_adjust(right=1)
#fig.subplots_adjust(bottom=0.12)
#fig.subplots_adjust(top=0.95)
#fig.subplots_adjust(wspace=0.25)
#fig.subplots_adjust(hspace=0.02)
MakePlot
(
files
,
opt
)
pt
.
EndPlot
(
files
,
opt
)
Event Timeline
Log In to Comment