Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update subchandra volume rendering scripts #2557

Merged
merged 4 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 102 additions & 0 deletions Exec/science/subchandra/analysis/subch_slice_3d.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#!/usr/bin/env python3

import os
import sys
from functools import reduce

import matplotlib
import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.axes_grid1 import ImageGrid

import yt
from yt.frontends.boxlib.api import CastroDataset
# assume that our data is in CGS
from yt.units import amu, cm

matplotlib.use('agg')




plotfile = sys.argv[1]
ds = CastroDataset(plotfile)

domain_frac = 0.2

xmin = ds.domain_left_edge[0]
xmax = ds.domain_right_edge[0]
xctr = 0.5 * (xmin + xmax)
L_x = xmax - xmin
xmin = xctr - 0.5 * domain_frac * L_x
xmax = xctr + 0.5 * domain_frac * L_x
L_x = xmax - xmin

ymin = ds.domain_left_edge[1]
ymax = ds.domain_right_edge[1]
yctr = 0.5 * (ymin + ymax)
L_y = ymax - ymin
ymin = yctr - 0.5 * domain_frac * L_y
ymax = yctr + 0.5 * domain_frac * L_y
L_y = ymax - ymin

zmin = ds.domain_left_edge[2]
zmax = ds.domain_right_edge[2]
zctr = 0.5 * (zmin + zmax)
L_z = zmax - zmin
zmin = zctr - 0.5 * domain_frac * L_z
zmax = zctr + 0.5 * domain_frac * L_z
L_z = zmax - zmin

fig = plt.figure()


fields = ["Temp", "abar", "enuc"]

grid = ImageGrid(fig, 111, nrows_ncols=(1, len(fields)),
axes_pad=0.75, cbar_pad=0.05, label_mode="L", cbar_mode="each")


for i, f in enumerate(fields):

sp = yt.SlicePlot(ds, "y", f,
center=[xctr, yctr, zctr], width=[L_x, L_z],
fontsize="12")

sp.set_buff_size((2400,2400))
sp.swap_axes()

if f == "Temp":
sp.set_zlim(f, 5.e7, 4e9)
sp.set_cmap(f, "magma_r")
elif f == "enuc":
sp.set_log(f, True, linthresh=1.e18)
sp.set_zlim(f, -1.e22, 1.e22)
sp.set_cmap(f, "bwr")
elif f == "density":
sp.set_zlim(f, 1.e-3, 5.e8)
elif f == "z_velocity":
sp.set_zlim(f, -2.e8, 2.e8)
sp.set_log(f, False)
sp.set_cmap(f, "bwr")
elif f == "abar":
sp.set_zlim(f, 4, 28)
sp.set_log(f, False)
sp.set_cmap(f, "plasma_r")

sp.set_axes_unit("cm")

plot = sp.plots[f]
plot.figure = fig
plot.axes = grid[i].axes
plot.cax = grid.cbar_axes[i]
if i < len(fields)-1:
grid[i].axes.xaxis.offsetText.set_visible(False)

sp._setup_plots()

fig.text(0.02, 0.02, "time = {:8.5f} s".format(float(ds.current_time)), transform=fig.transFigure)

fig.set_size_inches(19.2, 10.8)
plt.tight_layout()
plt.savefig("{}_slice.png".format(os.path.basename(plotfile)))
33 changes: 14 additions & 19 deletions Exec/science/subchandra/analysis/vol-abar-subch.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
#!/usr/bin/env python

import matplotlib
matplotlib.use('agg')

import numpy as np
# render Abar for the subchandra problem setup

import sys

import matplotlib
import numpy as np

import yt
from yt.frontends.boxlib.api import CastroDataset
import numpy as np
#from yt.visualization.volume_rendering.render_source import VolumeSource
from yt.visualization.volume_rendering.api import create_volume_source, Scene
from yt.units import cm
#from yt.visualization.volume_rendering.render_source import VolumeSource
from yt.visualization.volume_rendering.api import Scene, create_volume_source

matplotlib.use('agg')

# this is for the wdconvect problem

def doit(plotfile):

Expand All @@ -26,13 +26,6 @@ def doit(plotfile):

sc = Scene()


# add a volume: select a sphere
#center = (0, 0, 0)
#R = (5.e8, 'cm')

#dd = ds.sphere(center, R)

vol = create_volume_source(ds.all_data(), field=field)
sc.add_source(vol)

Expand Down Expand Up @@ -71,14 +64,16 @@ def doit(plotfile):

cam.switch_orientation(normal_vector=normal, north_vector=[0., 0., 1.])
cam.set_width(ds.domain_width)
#cam.zoom(3.0)
cam.zoom(3.0)
sc.camera = cam

sc.save_annotated("{}_abar_annotated.png".format(plotfile),
label_fontsize="18", label_fmt="%.1f",
sigma_clip=3,
text_annotate=[[(0.05, 0.05),
"t = {}".format(ds.current_time.d),
dict(horizontalalignment="left")],
[(0.5,0.95),
f"t = {ds.current_time.d:6.3f}",
dict(horizontalalignment="left", fontsize="18")],
[(0.5, 0.95),
"Castro simulation of double detonation SN Ia",
dict(color="y", fontsize="24",
horizontalalignment="center")]])
Expand Down
2 changes: 1 addition & 1 deletion Exec/science/subchandra/analysis/vol-enuc-pos-subch.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def doit(plotfile):
ds._get_field_info(field).take_log = True

vol = create_volume_source(ds.all_data(), field=field)
vol.use_ghost_zones = True
#vol.use_ghost_zones = True

vals = [18.0, 18.5, 19.0, 19.5, 20.0, 20.5, 21.0, 21.5, 22.0]
sigma = 0.1
Expand Down
31 changes: 13 additions & 18 deletions Exec/science/subchandra/analysis/vol-enuc-subch.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
#!/usr/bin/env python

import matplotlib
matplotlib.use('agg')

import numpy as np
# render enuc for the subchandra problem setup

import sys

import matplotlib
import numpy as np

import yt
from yt.frontends.boxlib.api import CastroDataset
import numpy as np
#from yt.visualization.volume_rendering.render_source import VolumeSource
from yt.visualization.volume_rendering.api import create_volume_source, Scene
from yt.units import cm
from yt.visualization.volume_rendering.api import Scene, create_volume_source

matplotlib.use('agg')

# this is for the wdconvect problem

def _enuc_symlog(field, data):
f = np.log10(np.abs(data["boxlib", "enuc"]))
Expand All @@ -40,12 +39,6 @@ def doit(plotfile):
sc = Scene()


# add a volume: select a sphere
#center = (0, 0, 0)
#R = (5.e8, 'cm')

#dd = ds.sphere(center, R)

vol = create_volume_source(ds.all_data(), field=field)
sc.add_source(vol)

Expand Down Expand Up @@ -84,14 +77,16 @@ def doit(plotfile):

cam.switch_orientation(normal_vector=normal, north_vector=[0., 0., 1.])
cam.set_width(ds.domain_width)
#cam.zoom(3.0)
cam.zoom(3.0)
sc.camera = cam

sc.save_annotated("{}_enuc_annotated.png".format(plotfile),
label_fontsize="18",
sigma_clip=3,
text_annotate=[[(0.05, 0.05),
"t = {}".format(ds.current_time.d),
dict(horizontalalignment="left")],
[(0.5,0.95),
f"t = {ds.current_time.d:6.3f}",
dict(horizontalalignment="left", fontsize="18")],
[(0.5, 0.95),
"Castro simulation of double detonation SN Ia",
dict(color="y", fontsize="24",
horizontalalignment="center")]])
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
#!/usr/bin/env python

import matplotlib
matplotlib.use('agg')

import numpy as np
# render Temperature for the subchandra problem setup

import sys

import matplotlib
import numpy as np

import yt
from yt.frontends.boxlib.api import CastroDataset
import numpy as np
#from yt.visualization.volume_rendering.render_source import VolumeSource
from yt.visualization.volume_rendering.api import create_volume_source, Scene
from yt.units import cm
#from yt.visualization.volume_rendering.render_source import VolumeSource
from yt.visualization.volume_rendering.api import Scene, create_volume_source

matplotlib.use('agg')

# this is for the wdconvect problem

def doit(plotfile):

Expand All @@ -26,38 +26,30 @@ def doit(plotfile):

sc = Scene()


# add a volume: select a sphere
#center = (0, 0, 0)
#R = (5.e8, 'cm')

#dd = ds.sphere(center, R)

vol = create_volume_source(ds.all_data(), field=field)
#vol.use_ghost_zones = True

sc.add_source(vol)


# transfer function
vals_tmp = [5.e7, 1.e8, 5.e8, 1.e9, 2.e9, 2.5e9, 3.e9]
_vals = [1.e8, 2.e8, 5.e8, 1.e9, 2.e9, 5.e9]
vals = []
for v in vals_tmp:
for v in _vals:
vals.append(np.log10(v))

alpha = [0.05, 0.2, 0.3, 0.3, 0.4, 0.5]

sigma = 0.05

tf = yt.ColorTransferFunction((min(vals), max(vals)))

tf.clear()

cmap = "viridis"

for v in vals:
if v < 9.01:
alpha = 0.25
else:
alpha = 0.75
cmap = "Oranges"

tf.sample_colormap(v, sigma**2, alpha=alpha, colormap=cmap)
for v, a in zip(vals, alpha):
tf.sample_colormap(v, sigma**2, alpha=a, colormap=cmap)

sc.get_source(0).transfer_function = tf

Expand All @@ -79,14 +71,16 @@ def doit(plotfile):

cam.switch_orientation(normal_vector=normal, north_vector=[0., 0., 1.])
cam.set_width(ds.domain_width)
#cam.zoom(3.0)
cam.zoom(3.0)
sc.camera = cam

sc.save_annotated("{}_Hnuc_annotated.png".format(plotfile),
sc.save_annotated("{}_Temp_annotated.png".format(plotfile),
label_fontsize="18",
sigma_clip=3,
text_annotate=[[(0.05, 0.05),
"t = {}".format(ds.current_time.d),
dict(horizontalalignment="left")],
[(0.5,0.95),
f"t = {ds.current_time.d:6.3f}",
dict(horizontalalignment="left", fontsize="18")],
[(0.5, 0.95),
"Castro simulation of double detonation SN Ia",
dict(color="y", fontsize="24",
horizontalalignment="center")]])
Expand Down