Skip to content

Commit f491822

Browse files
authored
add a 2nd option for massive star enuc vis (#3188)
this uses 2 different transfer funcitons to capture the positive and negative also add radial velocity vis
1 parent 6e0b6fc commit f491822

File tree

3 files changed

+238
-4
lines changed

3 files changed

+238
-4
lines changed

Exec/science/massive_star/analysis/vol-enuc-massivestar.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ def doit(plotfile):
3434
ds = CastroDataset(plotfile)
3535
ds._periodicity = (True, True, True)
3636

37+
zoom = 5
38+
3739
t_drive = 0.0
3840
if "[*] castro.drive_initial_convection_tmax" in ds.parameters:
3941
t_drive = ds.parameters["[*] castro.drive_initial_convection_tmax"]
@@ -54,8 +56,8 @@ def doit(plotfile):
5456
# transfer function
5557
vals = [-20, -19.5, -19, -18.5, -18, -17, -16, -15, -14,
5658
14, 15, 16, 17, 18, 18.5, 19, 19.5, 20]
57-
alpha = [0.5, 0.4, 0.4, 0.3, 0.3, 0.2, 0.2, 0.1, 0.1,
58-
0.1, 0.1, 0.2, 0.2, 0.3, 0.3, 0.4, 0.4, 0.5]
59+
alpha = [0.5, 0.4, 0.35, 0.3, 0.25, 0.2, 0.15, 0.1, 0.05,
60+
0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.5]
5961
sigma = 0.1
6062

6163
tf = yt.ColorTransferFunction((min(vals), max(vals)))
@@ -87,10 +89,10 @@ def doit(plotfile):
8789

8890
cam.switch_orientation(normal_vector=normal, north_vector=[0., 0., 1.])
8991
cam.set_width(ds.domain_width)
90-
cam.zoom(5.0)
92+
cam.zoom(zoom)
9193
sc.camera = cam
9294

93-
sc.save_annotated(f"{plotfile}_enuc_annotated.png",
95+
sc.save_annotated(f"{plotfile}_enuc_zoom{zoom}.png",
9496
label_fontsize="18",
9597
label_fmt="%.1f",
9698
sigma_clip=3,
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
#!/usr/bin/env python
2+
3+
# render a enuc using 2 separate transfer functions to better
4+
# show positive and negative
5+
6+
import sys
7+
8+
import matplotlib
9+
import numpy as np
10+
11+
import yt
12+
from yt.frontends.boxlib.api import CastroDataset
13+
from yt.units import cm
14+
from yt.visualization.volume_rendering.api import Scene, create_volume_source
15+
16+
matplotlib.use('agg')
17+
18+
def _enuc_symlog(field, data):
19+
f = np.log10(np.abs(data["boxlib", "enuc"]))
20+
f[f < 10] = 0.0
21+
return np.copysign(f, data["boxlib", "enuc"])
22+
23+
yt.add_field(
24+
name = ("boxlib", "enuc_symlog"),
25+
display_name = "", #r"\mathrm{log}_{10}(\epsilon_\mathrm{nuc})~ [\mathrm{erg/g/s}]",
26+
function = _enuc_symlog,
27+
sampling_type = "local",
28+
units = None
29+
)
30+
31+
32+
def doit(plotfile):
33+
34+
ds = CastroDataset(plotfile)
35+
ds._periodicity = (True, True, True)
36+
37+
zoom = 1.5
38+
39+
t_drive = 0.0
40+
if "[*] castro.drive_initial_convection_tmax" in ds.parameters:
41+
t_drive = ds.parameters["[*] castro.drive_initial_convection_tmax"]
42+
elif "castro.drive_initial_convection_tmax" in ds.parameters:
43+
t_drive = ds.parameters["castro.drive_initial_convection_tmax"]
44+
print(t_drive)
45+
46+
sc = Scene()
47+
48+
field = ("boxlib", "enuc_symlog")
49+
ds._get_field_info(field).take_log = False
50+
51+
vals = [12, 13, 14, 15, 15.5, 16, 16.5, 17]
52+
sigma = 0.15
53+
alpha = [0.025, 0.05, 0.1, 0.125, 0.15, 0.2, 0.3, 0.4]
54+
55+
# negative values of enuc
56+
57+
vol2 = create_volume_source(ds.all_data(), field=field)
58+
#vol2.use_ghost_zones = True
59+
60+
vals_r = [-v for v in reversed(vals)]
61+
alpha_r = [a for a in reversed(alpha)]
62+
63+
cmap = "Blues_r"
64+
65+
tf = yt.ColorTransferFunction((min(vals_r), max(vals_r)))
66+
tf.clear()
67+
68+
for v, a in zip(vals_r, alpha_r):
69+
tf.sample_colormap(v, sigma**2, alpha=a, colormap=cmap)
70+
71+
vol2.set_transfer_function(tf)
72+
73+
sc.add_source(vol2)
74+
75+
# positive values of enuc
76+
77+
vol = create_volume_source(ds.all_data(), field=field)
78+
#vol.use_ghost_zones = True
79+
80+
cmap = "Reds"
81+
82+
tf = yt.ColorTransferFunction((min(vals), max(vals)))
83+
tf.clear()
84+
85+
for v, a in zip(vals, alpha):
86+
tf.sample_colormap(v, sigma**2, alpha=a, colormap=cmap)
87+
88+
vol.set_transfer_function(tf)
89+
90+
sc.add_source(vol)
91+
92+
93+
# camera
94+
95+
cam = sc.add_camera(ds, lens_type="perspective")
96+
cam.resolution = (1920, 1280)
97+
98+
# view 1
99+
100+
cam.position = [ds.domain_right_edge[0],
101+
ds.domain_right_edge[1],
102+
ds.domain_right_edge[2]]
103+
104+
# look toward the center
105+
center = 0.5 * (ds.domain_left_edge + ds.domain_right_edge)
106+
# set the center in the vertical direction to be the height of the underlying base layer
107+
108+
normal = (center - cam.position)
109+
normal /= np.sqrt(normal.dot(normal))
110+
111+
cam.switch_orientation(normal_vector=normal, north_vector=[0., 0., 1.])
112+
cam.set_width(ds.domain_width)
113+
cam.zoom(zoom)
114+
sc.camera = cam
115+
116+
sc.save_annotated(f"{plotfile}_enuc_zoom{zoom}.png",
117+
label_fontsize="18",
118+
label_fmt="%.3f",
119+
sigma_clip=3,
120+
text_annotate=[[(0.05, 0.05),
121+
f"$t - \\tau_\\mathrm{{drive}}$ = {float(ds.current_time) - t_drive:6.1f} s",
122+
dict(horizontalalignment="left", fontsize="18")]])
123+
124+
125+
if __name__ == "__main__":
126+
127+
# Choose a field
128+
plotfile = ""
129+
130+
try:
131+
plotfile = sys.argv[1]
132+
except:
133+
sys.exit("ERROR: no plotfile specified")
134+
135+
doit(plotfile)
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#!/usr/bin/env python
2+
3+
# render the radial velocity for the massive star problem setup
4+
# pass in the plotfile name
5+
6+
import sys
7+
8+
import matplotlib
9+
import numpy as np
10+
11+
import yt
12+
from yt.frontends.boxlib.api import CastroDataset
13+
from yt.units import cm
14+
from yt.visualization.volume_rendering.api import Scene, create_volume_source
15+
16+
matplotlib.use('agg')
17+
18+
19+
def doit(plotfile):
20+
21+
ds = CastroDataset(plotfile)
22+
ds._periodicity = (True, True, True)
23+
24+
zoom = 1.5
25+
26+
t_drive = 0.0
27+
if "[*] castro.drive_initial_convection_tmax" in ds.parameters:
28+
t_drive = ds.parameters["[*] castro.drive_initial_convection_tmax"]
29+
elif "castro.drive_initial_convection_tmax" in ds.parameters:
30+
t_drive = ds.parameters["castro.drive_initial_convection_tmax"]
31+
print(t_drive)
32+
33+
sc = Scene()
34+
35+
field = ("boxlib", "radvel")
36+
ds._get_field_info(field).take_log = False
37+
38+
vol = create_volume_source(ds.all_data(), field=field)
39+
sc.add_source(vol)
40+
41+
42+
# transfer function
43+
vals = [-8.e7, -4.e7, -2.e7, -1.e7, 1.e7, 2.e7, 4.e7, 8.e7]
44+
alpha = [0.2, 0.1, 0.05, 0.02, 0.02, 0.05, 0.1, 0.2]
45+
sigma = 1.e6
46+
47+
tf = yt.ColorTransferFunction((min(vals), max(vals)))
48+
49+
tf.clear()
50+
51+
cmap = "coolwarm"
52+
53+
for v, a in zip(vals, alpha):
54+
tf.sample_colormap(v, sigma**2, alpha=a, colormap=cmap)
55+
56+
sc.get_source(0).transfer_function = tf
57+
58+
cam = sc.add_camera(ds, lens_type="perspective")
59+
cam.resolution = (1920, 1280)
60+
61+
# view 1
62+
63+
cam.position = [ds.domain_right_edge[0],
64+
ds.domain_right_edge[1],
65+
ds.domain_right_edge[2]]
66+
67+
# look toward the center
68+
center = 0.5 * (ds.domain_left_edge + ds.domain_right_edge)
69+
# set the center in the vertical direction to be the height of the underlying base layer
70+
71+
normal = (center - cam.position)
72+
normal /= np.sqrt(normal.dot(normal))
73+
74+
cam.switch_orientation(normal_vector=normal, north_vector=[0., 0., 1.])
75+
cam.set_width(ds.domain_width)
76+
cam.zoom(zoom)
77+
sc.camera = cam
78+
79+
sc.save_annotated(f"{plotfile}_radvel_zoom{zoom}.png",
80+
label_fontsize="18",
81+
sigma_clip=5,
82+
text_annotate=[[(0.05, 0.05),
83+
f"$t - \\tau_\\mathrm{{drive}}$ = {float(ds.current_time) - t_drive:6.1f} s",
84+
dict(horizontalalignment="left", fontsize="18")]])
85+
86+
87+
if __name__ == "__main__":
88+
89+
# Choose a field
90+
plotfile = ""
91+
92+
try:
93+
plotfile = sys.argv[1]
94+
except:
95+
sys.exit("ERROR: no plotfile specified")
96+
97+
doit(plotfile)

0 commit comments

Comments
 (0)