Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
SWIFTsim
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
70
Issues
70
List
Boards
Labels
Milestones
Merge Requests
13
Merge Requests
13
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
SWIFT
SWIFTsim
Commits
d897e2f9
Commit
d897e2f9
authored
Feb 03, 2020
by
Loic Hausammann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
GEAR: update plots
parent
9b3c6ca2
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
109 additions
and
14 deletions
+109
-14
examples/GEAR/ZoomIn/halo_distribution.py
examples/GEAR/ZoomIn/halo_distribution.py
+37
-6
examples/GEAR/ZoomIn/make_image.py
examples/GEAR/ZoomIn/make_image.py
+28
-5
examples/GEAR/ZoomIn/phase_plot.py
examples/GEAR/ZoomIn/phase_plot.py
+1
-1
examples/GEAR/ZoomIn/projection_plot.py
examples/GEAR/ZoomIn/projection_plot.py
+2
-2
examples/GEAR/ZoomIn/velocity_plot.py
examples/GEAR/ZoomIn/velocity_plot.py
+41
-0
No files found.
examples/GEAR/ZoomIn/halo_distribution.py
View file @
d897e2f9
#!/usr/bin/env
#!/usr/bin/env
import
yt
from
yt.extensions.astro_analysis.halo_analysis.api
import
HaloCatalog
from
yt.extensions.astro_analysis.halo_analysis.api
import
HaloCatalog
import
matplotlib.pyplot
as
plt
import
numpy
as
np
Nbins
=
20
def
savePlot
(
data
):
plt
.
figure
()
plt
.
tight_layout
(
pad
=
0.4
,
w_pad
=
0.5
,
h_pad
=
0.5
)
markers
=
[
"s"
,
"o"
]
d_min
=
None
d_max
=
None
for
d
in
data
[
0
]:
if
d_min
is
None
or
d
.
min
()
<
d_min
:
d_min
=
d
.
min
()
if
d_max
is
None
or
d
.
max
()
>
d_max
:
d_max
=
d
.
max
()
for
i
,
d
in
enumerate
(
data
[
0
]):
plt
.
hist
(
d
,
Nbins
,
histtype
=
"step"
,
log
=
True
,
range
=
[
d_min
,
d_max
])
plt
.
xlabel
(
"$
\
m
a
thrm{Mass
\
\
mathrm{(M_{
\
odo
t
})}}$"
,
fontsize
=
'large'
)
plt
.
ylabel
(
r"$\
m
athrm{Number}\
o
\mathrm{f}\
\mathrm{Halos}$"
,
fontsize
=
'large'
)
plt
.
legend
(
data
[
1
],
loc
=
4
,
frameon
=
True
,
ncol
=
2
,
fancybox
=
True
)
leg
=
plt
.
gca
().
get_legend
()
ltext
=
leg
.
get_texts
()
plt
.
setp
(
ltext
,
fontsize
=
'small'
)
plt
.
grid
(
True
)
plt
.
savefig
(
"halo_distribution.png"
)
def
doPlot
(
f
,
name
,
i
):
def
doPlot
(
f
,
name
,
i
):
hc
=
HaloCatalog
(
data_ds
=
f
,
finder_method
=
"fof"
,
hc
=
HaloCatalog
(
data_ds
=
f
,
finder_method
=
"fof"
)
finder_kwargs
=
{
"padding"
:
0.02
})
hc
.
create
()
hc
.
create
()
print
(
hc
)
print
(
dir
(
hc
))
masses
=
np
.
zeros
(
len
(
hc
.
catalog
))
exit
()
for
i
,
halo
in
enumerate
(
hc
.
catalog
):
masses
[
i
]
=
halo
[
"particle_mass"
].
in_units
(
"Msun"
)
return
masses
examples/GEAR/ZoomIn/make_image.py
View file @
d897e2f9
...
@@ -6,6 +6,7 @@ import unyt
...
@@ -6,6 +6,7 @@ import unyt
import
sys
import
sys
import
matplotlib
import
matplotlib
import
projection_plot
import
projection_plot
import
velocity_plot
import
phase_plot
import
phase_plot
import
halo_distribution
import
halo_distribution
import
add_fields
import
add_fields
...
@@ -26,9 +27,10 @@ do_plot = {
...
@@ -26,9 +27,10 @@ do_plot = {
"projection_density"
:
False
,
"projection_density"
:
False
,
"projection_temperature"
:
False
,
"projection_temperature"
:
False
,
"projection_mass"
:
False
,
"projection_mass"
:
False
,
"halo_distribution"
:
Tru
e
,
"halo_distribution"
:
Fals
e
,
"phase_1d"
:
False
,
"phase_1d"
:
False
,
"phase_2d"
:
False
"phase_2d"
:
False
,
"velocity"
:
True
}
}
# Generate the figures
# Generate the figures
...
@@ -70,9 +72,13 @@ axes = {
...
@@ -70,9 +72,13 @@ axes = {
# Data
# Data
data
=
{
data
=
{
"phase_1d"
:
([],
[])
"phase_1d"
:
([],
[]),
"halo_distribution"
:
([],
[]),
"velocity"
:
([],
[]),
}
}
names
=
[]
def
savePlot
():
def
savePlot
():
if
do_plot
[
"projection_density"
]:
if
do_plot
[
"projection_density"
]:
...
@@ -87,13 +93,25 @@ def savePlot():
...
@@ -87,13 +93,25 @@ def savePlot():
"mass"
)
"mass"
)
if
do_plot
[
"phase_1d"
]:
if
do_plot
[
"phase_1d"
]:
data
[
"phase_1d"
][
1
].
extend
(
names
)
phase_plot
.
save1DPlot
(
data
[
"phase_1d"
])
phase_plot
.
save1DPlot
(
data
[
"phase_1d"
])
if
do_plot
[
"phase_2d"
]:
if
do_plot
[
"phase_2d"
]:
phase_plot
.
save2DPlot
(
figures
[
"phase_2d"
])
phase_plot
.
save2DPlot
(
figures
[
"phase_2d"
])
# halo distribution
if
do_plot
[
"halo_distribution"
]:
data
[
"halo_distribution"
][
1
].
extend
(
names
)
halo_distribution
.
savePlot
(
data
[
"halo_distribution"
])
if
do_plot
[
"velocity"
]:
data
[
"velocity"
][
1
].
extend
(
names
)
velocity_plot
.
save1DPlot
(
data
[
"velocity"
])
def
doPlot
(
filename
,
i
,
name
):
def
doPlot
(
filename
,
i
,
name
):
names
.
append
(
name
)
f
=
yt
.
load
(
filename
)
f
=
yt
.
load
(
filename
)
if
(
do_plot
[
"projection_temperature"
]
or
do_plot
[
"phase_2d"
]):
if
(
do_plot
[
"projection_temperature"
]
or
do_plot
[
"phase_2d"
]):
add_fields
.
addTemperature
(
f
)
add_fields
.
addTemperature
(
f
)
...
@@ -128,7 +146,6 @@ def doPlot(filename, i, name):
...
@@ -128,7 +146,6 @@ def doPlot(filename, i, name):
if
do_plot
[
"phase_1d"
]:
if
do_plot
[
"phase_1d"
]:
p
=
phase_plot
.
do1DPlot
(
f
,
name
,
i
)
p
=
phase_plot
.
do1DPlot
(
f
,
name
,
i
)
data
[
"phase_1d"
][
0
].
append
(
p
)
data
[
"phase_1d"
][
0
].
append
(
p
)
data
[
"phase_1d"
][
1
].
append
(
name
)
# 2D Phase plot
# 2D Phase plot
if
do_plot
[
"phase_2d"
]:
if
do_plot
[
"phase_2d"
]:
...
@@ -137,7 +154,13 @@ def doPlot(filename, i, name):
...
@@ -137,7 +154,13 @@ def doPlot(filename, i, name):
# halo distribution
# halo distribution
if
do_plot
[
"halo_distribution"
]:
if
do_plot
[
"halo_distribution"
]:
halo_distribution
.
doPlot
(
f
,
name
,
i
)
m
=
halo_distribution
.
doPlot
(
f
,
name
,
i
)
data
[
"halo_distribution"
][
0
].
append
(
m
)
# Velocity plot
if
do_plot
[
"velocity"
]:
p
=
velocity_plot
.
do1DPlot
(
f
,
name
,
i
)
data
[
"velocity"
][
0
].
append
(
p
)
doPlot
(
swift
,
0
,
"SWIFT"
)
doPlot
(
swift
,
0
,
"SWIFT"
)
...
...
examples/GEAR/ZoomIn/phase_plot.py
View file @
d897e2f9
...
@@ -7,7 +7,7 @@ import matplotlib.pyplot as plt
...
@@ -7,7 +7,7 @@ import matplotlib.pyplot as plt
width
=
5
*
kpc
width
=
5
*
kpc
limits_temperature
=
(
1e1
*
K
,
1e7
*
K
)
limits_temperature
=
(
1e1
*
K
,
1e7
*
K
)
limits_density
=
(
1e-
7
*
amu
/
cm
**
3
,
1e7
*
amu
/
cm
**
3
)
limits_density
=
(
1e-
10
*
amu
/
cm
**
3
,
1e3
*
amu
/
cm
**
3
)
limits_mass
=
(
1e3
*
Msun
,
1e7
*
Msun
)
limits_mass
=
(
1e3
*
Msun
,
1e7
*
Msun
)
...
...
examples/GEAR/ZoomIn/projection_plot.py
View file @
d897e2f9
...
@@ -10,8 +10,8 @@ cmap_mass = "inferno"
...
@@ -10,8 +10,8 @@ cmap_mass = "inferno"
center
=
(
1441.9954833984375000
,
center
=
(
1441.9954833984375000
,
1666.1169433593750000
,
1666.1169433593750000
,
1891.6248779296875000
)
1891.6248779296875000
)
small_width
=
2
0
0
*
kpc
small_width
=
2
5
0
*
kpc
large_width
=
1
000
*
kpc
large_width
=
3
000
*
kpc
limits_density
=
(
1e-10
*
g
/
cm
**
2
,
1e-2
*
g
/
cm
**
2
)
limits_density
=
(
1e-10
*
g
/
cm
**
2
,
1e-2
*
g
/
cm
**
2
)
limits_temperature
=
(
10
*
K
,
1e5
*
K
)
limits_temperature
=
(
10
*
K
,
1e5
*
K
)
limits_mass
=
None
limits_mass
=
None
...
...
examples/GEAR/ZoomIn/velocity_plot.py
0 → 100644
View file @
d897e2f9
#!/usr/bin/env python3
import
yt
from
yt.units
import
kpc
import
matplotlib.pyplot
as
plt
width
=
1500
*
kpc
def
save1DPlot
(
profiles
):
plt
.
figure
(
figsize
=
(
8
,
8
))
plt
.
tight_layout
(
pad
=
0.4
,
w_pad
=
0.5
,
h_pad
=
0.5
)
markers
=
[
"s"
,
"o"
]
for
i
,
p
in
enumerate
(
profiles
[
0
]):
velocity
=
p
.
x
.
in_units
(
"km/s"
).
d
mass
=
p
[
"Masses"
].
in_units
(
"Msun"
).
d
plt
.
plot
(
velocity
,
mass
,
linestyle
=
"-"
,
marker
=
markers
[
i
],
markeredgecolor
=
'none'
,
linewidth
=
1.2
,
alpha
=
0.8
)
plt
.
semilogx
()
plt
.
semilogy
()
plt
.
xlabel
(
"$
\
m
a
thrm{Velocity
\
(km/s)}$
"
, fontsize='large')
plt.ylabel(r"
$
\
mathrm
{
Mass
,}
\
/
\
mathrm
{
d
}
M
\
mathrm
{
/
dlog
}
\
/
\
mathrm
{
\
rho
}
\
/
\
mathrm
{(
M_
{
\
odot
})}
$
", fontsize='large')
plt.legend(profiles[1], loc=4, frameon=True, ncol=2, fancybox=True)
leg = plt.gca().get_legend()
ltext = leg.get_texts()
plt.setp(ltext, fontsize='small')
plt.grid(True)
plt.savefig("
velocity
.
png
", bbox_inches='tight', pad_inches=0.03, dpi=300)
def do1DPlot(f, name, i):
sp = f.sphere("
max
", width)
# Because ParticleProfilePlot doesn't exist, I will do the following trick.
p = yt.create_profile(sp, ("
PartType0
", "
velocity_magnitude
"), ("
PartType0
", "
Masses
"),
weight_field=None, n_bins=50,
accumulation=False)
return p
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment