Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F92585213
ark_idealized_dwarfs_sample
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, Nov 21, 17:29
Size
3 KB
Mime Type
text/x-python
Expires
Sat, Nov 23, 17:29 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
22464261
Attached To
rARRAKIHS ARRAKIHS
ark_idealized_dwarfs_sample
View Options
#!/usr/bin/env python3
import
argparse
import
numpy
as
np
import
os
####################################################################
# option parser
####################################################################
description
=
"""generate a set of idealized dwarf galaxies in the hdf5 mockimg format
"""
epilog
=
"""
Examples:
--------
ark_idealized_dwarfs_sample --output_directory ../dwarfs -N 50
"""
parser
=
argparse
.
ArgumentParser
(
description
=
description
,
epilog
=
epilog
,
formatter_class
=
argparse
.
RawDescriptionHelpFormatter
)
parser
.
add_argument
(
'--output_directory'
,
dest
=
"output_directory"
,
type
=
str
,
default
=
'idealized_dwarfs'
,
help
=
'output directory'
)
parser
.
add_argument
(
'--dry-run'
,
dest
=
"dryrun"
,
action
=
'store_true'
,
default
=
False
,
help
=
'dry-run mode'
)
parser
.
add_argument
(
'--flat-sfr'
,
dest
=
"flatsfr"
,
action
=
'store_true'
,
default
=
False
,
help
=
'consider a flat sfr'
)
parser
.
add_argument
(
'-N'
,
dest
=
"N"
,
type
=
int
,
default
=
10
,
help
=
'number of dwarfs'
)
class
Sampler
():
def
__init__
(
self
):
pass
def
sample
(
self
,
mass
):
mean
=
np
.
interp
(
mass
,
self
.
mass
,
self
.
mean
)
std
=
np
.
interp
(
mass
,
self
.
mass
,
self
.
std
)
return
np
.
random
.
normal
(
mean
,
std
,
len
(
mass
))
class
FeH_Sampler
(
Sampler
):
def
__init__
(
self
):
self
.
mass
=
np
.
array
([
5
,
6
,
7
,
8
,
9
])
self
.
mean
=
np
.
array
([
-
2.2
,
-
1.9
,
-
1.5
,
-
1.1
,
-
0.5
])
self
.
std
=
np
.
array
([
1.0
,
1.0
,
1.0
,
1.0
,
1.0
])
*
0.2
class
R12_Sampler
(
Sampler
):
def
__init__
(
self
):
self
.
mass
=
np
.
array
([
5
,
6
,
7
,
8
,
9
])
self
.
mean
=
np
.
log10
(
np
.
array
([
0.3
,
0.476
,
0.75
,
1.
,
1.5
]))
self
.
std
=
np
.
array
([
0.2
,
0.2
,
0.2
,
0.2
,
0.2
])
class
Age_Sampler
(
Sampler
):
def
__init__
(
self
):
self
.
mass
=
np
.
array
([
5
,
6.7
,
8.7
])
self
.
mean
=
np
.
array
([
1
,
3
,
6
])
self
.
std
=
np
.
array
([
0.2
,
0.5
,
1.0
])
####################################################################
# main
####################################################################
opt
=
parser
.
parse_args
()
# generate a set of masses (in log10)
masses
=
np
.
random
.
uniform
(
5
,
9
,
opt
.
N
)
# Sample FeH
FeH
=
FeH_Sampler
()
fes
=
FeH
.
sample
(
masses
)
# Sample R12
R12
=
R12_Sampler
()
r12s
=
10
**
R12
.
sample
(
masses
)
# Sample Ages
Age
=
Age_Sampler
()
ages
=
Age
.
sample
(
masses
)
#from matplotlib import pylab as plt
#plt.scatter(masses,r12s)
#plt.loglog()
#plt.show()
#exit()
if
not
os
.
path
.
exists
(
opt
.
output_directory
):
os
.
makedirs
(
opt
.
output_directory
)
for
i
in
range
(
opt
.
N
):
M0
=
10
**
masses
[
i
]
age
=
ages
[
i
]
e
=
r12s
[
i
]
Fe
=
fes
[
i
]
output_filename
=
'M0_{0:10.4e}_e_{1:4.2f}_Fe_{2:5.2f}_age_{3:05.2f}.hdf5'
.
format
(
M0
,
e
,
Fe
,
age
)
output_filename
=
os
.
path
.
join
(
opt
.
output_directory
,
output_filename
)
if
opt
.
flatsfr
:
cmd
=
'./ark_idealized_dwarfs_generate --Fe {0:6.3f} --AgeMean {1:6.3f} --M0 {2:10.4e} -e {3:5.3f} -N {4:d} -o {5:s} --AgeFlat'
.
format
(
Fe
,
age
,
M0
,
e
,
50000
,
output_filename
)
else
:
cmd
=
'./ark_idealized_dwarfs_generate --Fe {0:6.3f} --AgeMean {1:6.3f} --M0 {2:10.4e} -e {3:5.3f} -N {4:d} -o {5:s}'
.
format
(
Fe
,
age
,
M0
,
e
,
50000
,
output_filename
)
# Generate the dwarfs
print
(
cmd
)
if
not
opt
.
dryrun
:
os
.
system
(
cmd
)
Event Timeline
Log In to Comment