Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F98995273
ark_idealized_dwarfs_pFevsL
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, Jan 18, 08:09
Size
7 KB
Mime Type
text/x-python
Expires
Mon, Jan 20, 08:09 (1 d, 21 h)
Engine
blob
Format
Raw Data
Handle
23685911
Attached To
rARRAKIHS ARRAKIHS
ark_idealized_dwarfs_pFevsL
View Options
#!/usr/bin/python3
import
os
import
numpy
as
np
import
argparse
import
pickle
import
matplotlib.pyplot
as
plt
####################################################################
# option parser
####################################################################
description
=
"plot the stellar metallicity as a function of luminosity"
epilog
=
"""
Examples:
--------
ark_idealized_dwarfs_pFevsL output.pkl
"""
parser
=
argparse
.
ArgumentParser
(
description
=
description
,
epilog
=
epilog
,
formatter_class
=
argparse
.
RawDescriptionHelpFormatter
)
parser
.
add_argument
(
action
=
"store"
,
dest
=
"files"
,
metavar
=
'FILE'
,
type
=
str
,
default
=
None
,
nargs
=
'*'
,
help
=
'a list of files'
)
parser
.
add_argument
(
"-o"
,
action
=
"store"
,
type
=
str
,
dest
=
"outputfilename"
,
default
=
None
,
help
=
"Name of the output file"
)
parser
.
add_argument
(
"--data"
,
action
=
"store"
,
type
=
str
,
dest
=
"data"
,
default
=
None
,
help
=
"data file"
)
parser
.
add_argument
(
'--xmin'
,
action
=
"store"
,
dest
=
"xmin"
,
metavar
=
'FLOAT'
,
type
=
float
,
default
=
1
e5
,
help
=
'x min'
)
parser
.
add_argument
(
'--xmax'
,
action
=
"store"
,
dest
=
"xmax"
,
metavar
=
'FLOAT'
,
type
=
float
,
default
=
1
e9
,
help
=
'x max'
)
parser
.
add_argument
(
'--ymin'
,
action
=
"store"
,
dest
=
"ymin"
,
metavar
=
'FLOAT'
,
type
=
float
,
default
=-
3
,
help
=
'y min'
)
parser
.
add_argument
(
'--ymax'
,
action
=
"store"
,
dest
=
"ymax"
,
metavar
=
'FLOAT'
,
type
=
float
,
default
=
0
,
help
=
'y max'
)
parser
.
add_argument
(
'--log'
,
action
=
"store"
,
dest
=
"log"
,
metavar
=
'STR'
,
type
=
str
,
default
=
'x'
,
help
=
'log scale (None,x,y,xy)'
)
def
SetAxis
(
ax
,
xmin
,
xmax
,
ymin
,
ymax
,
log
=
None
):
"""
Set ticks for the axis
"""
#####################################
# first : slightly extend the limits
#####################################
if
log
is
not
None
:
if
str
.
find
(
log
,
'x'
)
!=
-
1
:
if
xmin
is
not
None
:
xmin
=
np
.
log10
(
xmin
)
if
xmax
is
not
None
:
xmax
=
np
.
log10
(
xmax
)
if
log
is
not
None
:
if
str
.
find
(
log
,
'y'
)
!=
-
1
:
if
ymin
is
not
None
:
ymin
=
np
.
log10
(
ymin
)
if
ymax
is
not
None
:
ymax
=
np
.
log10
(
ymax
)
if
xmin
is
not
None
and
xmax
is
not
None
:
if
xmin
==
xmax
:
xmin
=
xmin
-
0.05
*
xmin
xmax
=
xmax
+
0.05
*
xmax
else
:
xmin
=
xmin
-
0.05
*
(
xmax
-
xmin
)
xmax
=
xmax
+
0.05
*
(
xmax
-
xmin
)
if
ymin
is
not
None
and
ymax
is
not
None
:
if
ymin
==
ymax
:
ymin
=
ymin
-
0.05
*
ymin
ymax
=
ymax
+
0.05
*
ymax
else
:
ymin
=
ymin
-
0.05
*
(
ymax
-
ymin
)
ymax
=
ymax
+
0.05
*
(
ymax
-
ymin
)
if
log
is
not
None
:
if
str
.
find
(
log
,
'x'
)
!=
-
1
:
xmin
=
10
**
xmin
xmax
=
10
**
xmax
if
log
is
not
None
:
if
str
.
find
(
log
,
'y'
)
!=
-
1
:
ymin
=
10
**
ymin
ymax
=
10
**
ymax
#####################################
# second : set log log or lin log
#####################################
if
log
is
not
None
:
if
str
.
find
(
log
,
'x'
)
!=
-
1
and
str
.
find
(
log
,
'y'
)
!=
-
1
:
ax
.
loglog
()
elif
str
.
find
(
log
,
'x'
)
!=
-
1
:
ax
.
semilogx
()
else
:
ax
.
semilogy
()
plt
.
axis
([
xmin
,
xmax
,
ymin
,
ymax
])
if
log
is
None
:
log
=
'None'
#####################################
# third : adapt ticks
#####################################
if
str
.
find
(
log
,
'x'
)
==
-
1
:
ax
.
xaxis
.
set_major_locator
(
plt
.
AutoLocator
())
x_major
=
ax
.
xaxis
.
get_majorticklocs
()
dx_minor
=
(
x_major
[
-
1
]
-
x_major
[
0
])
/
(
len
(
x_major
)
-
1
)
/
5.
ax
.
xaxis
.
set_minor_locator
(
plt
.
MultipleLocator
(
dx_minor
))
if
str
.
find
(
log
,
'y'
)
==
-
1
:
ax
.
yaxis
.
set_major_locator
(
plt
.
AutoLocator
())
y_major
=
ax
.
yaxis
.
get_majorticklocs
()
dy_minor
=
(
y_major
[
-
1
]
-
y_major
[
0
])
/
(
len
(
y_major
)
-
1
)
/
5.
ax
.
yaxis
.
set_minor_locator
(
plt
.
MultipleLocator
(
dy_minor
))
####################################################################
# main
####################################################################
if
__name__
==
'__main__'
:
opt
=
parser
.
parse_args
()
params
=
{
"axes.labelsize"
:
14
,
"axes.titlesize"
:
18
,
"font.size"
:
12
,
"legend.fontsize"
:
12
,
"xtick.labelsize"
:
14
,
"ytick.labelsize"
:
14
,
"text.usetex"
:
True
,
"figure.subplot.left"
:
0.15
,
"figure.subplot.right"
:
0.95
,
"figure.subplot.bottom"
:
0.15
,
"figure.subplot.top"
:
0.95
,
"figure.subplot.wspace"
:
0.02
,
"figure.subplot.hspace"
:
0.02
,
"figure.figsize"
:
(
8
,
6
),
"lines.markersize"
:
6
,
"lines.linewidth"
:
2.0
,
}
plt
.
rcParams
.
update
(
params
)
# create the plot
fig
=
plt
.
gcf
()
fig
.
set_size_inches
(
8
,
6
)
ax
=
plt
.
gca
()
# loop over files
for
filename
in
opt
.
files
:
with
open
(
filename
,
'rb'
)
as
file
:
database
=
pickle
.
load
(
file
)
xs
=
[]
ys
=
[]
for
key
in
database
.
keys
():
x
=
database
[
key
][
"Lv"
]
y
=
database
[
key
][
"Fe_mode"
]
xs
.
append
(
x
)
ys
.
append
(
y
)
ax
.
scatter
(
xs
,
ys
)
############################################################################
# add data
############################################################################
if
opt
.
data
:
if
os
.
path
.
exists
(
opt
.
data
):
f
=
open
(
opt
.
data
,
'rb'
)
dataobs
=
pickle
.
load
(
f
)
f
.
close
()
Ls
=
[]
eLps
=
[]
eLms
=
[]
FeHs
=
[]
eFeHps
=
[]
eFeHms
=
[]
for
name
in
dataobs
.
keys
():
gal
=
dataobs
[
name
]
if
gal
[
"L"
]
!=
None
and
gal
[
"FeH"
]
!=
None
:
L
=
gal
[
"L"
]
FeH
=
gal
[
"FeH"
]
eLp
=
0.0
if
gal
[
"eLp"
]
!=
None
:
eLp
=
gal
[
"eLp"
]
eLm
=
0.0
if
gal
[
"eLm"
]
!=
None
:
eLm
=
gal
[
"eLm"
]
eFeHp
=
0.0
if
gal
[
"eFeHp"
]
!=
None
:
eFeHp
=
gal
[
"eFeHp"
]
eFeHm
=
0.0
if
gal
[
"eFeHm"
]
!=
None
:
eFeHm
=
gal
[
"eFeHm"
]
Ls
.
append
(
L
)
eLps
.
append
(
eLp
)
eLms
.
append
(
eLm
)
FeHs
.
append
(
FeH
)
eFeHps
.
append
(
eFeHp
)
eFeHms
.
append
(
eFeHm
)
# now plot
Ls
=
np
.
array
(
Ls
)
eLps
=
np
.
fabs
(
np
.
array
(
eLps
))
eLms
=
np
.
fabs
(
np
.
array
(
eLms
))
FeHs
=
np
.
array
(
FeHs
)
eFeHps
=
np
.
fabs
(
np
.
array
(
eFeHps
))
eFeHms
=
np
.
fabs
(
np
.
array
(
eFeHms
))
#pt.scatter(Ls,FeHs)
ax
.
errorbar
(
x
=
Ls
,
y
=
FeHs
,
xerr
=
[
eLms
,
eLps
],
yerr
=
[
eFeHms
,
eFeHps
],
fmt
=
's'
,
c
=
'k'
,
alpha
=
0.1
,
label
=
r"$\rm{Milky\,Way\,\,dwarfs\,\,compilation}$"
)
############################################################################
# set the axis
SetAxis
(
ax
,
opt
.
xmin
,
opt
.
xmax
,
opt
.
ymin
,
opt
.
ymax
,
log
=
opt
.
log
)
# labels
ax
.
set_xlabel
(
r"V-Band Luminosity"
)
ax
.
set_ylabel
(
r"[Fe/H]"
)
# save or display
if
opt
.
outputfilename
:
plt
.
savefig
(
opt
.
outputfilename
)
else
:
plt
.
show
()
Event Timeline
Log In to Comment