|
| 1 | +#!/usr/bin/env python |
| 2 | + |
| 3 | +# render enuc for the subchandra problem setup |
| 4 | + |
| 5 | +import sys |
| 6 | + |
| 7 | +import matplotlib |
| 8 | +import numpy as np |
| 9 | + |
| 10 | +import yt |
| 11 | +from yt.frontends.boxlib.api import CastroDataset |
| 12 | +from yt.units import cm |
| 13 | +from yt.visualization.volume_rendering.api import Scene, create_volume_source |
| 14 | + |
| 15 | +matplotlib.use('agg') |
| 16 | + |
| 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 | + t_drive = 0.0 |
| 38 | + if "[*] castro.drive_initial_convection_tmax" in ds.parameters: |
| 39 | + t_drive = ds.parameters["[*] castro.drive_initial_convection_tmax"] |
| 40 | + elif "castro.drive_initial_convection_tmax" in ds.parameters: |
| 41 | + t_drive = ds.parameters["castro.drive_initial_convection_tmax"] |
| 42 | + print(t_drive) |
| 43 | + |
| 44 | + field = ('boxlib', 'enuc_symlog') |
| 45 | + ds._get_field_info(field).take_log = False |
| 46 | + |
| 47 | + sc = Scene() |
| 48 | + |
| 49 | + |
| 50 | + vol = create_volume_source(ds.all_data(), field=field) |
| 51 | + sc.add_source(vol) |
| 52 | + |
| 53 | + |
| 54 | + # transfer function |
| 55 | + vals = [-20, -19.5, -19, -18.5, -18, -17, -16, -15, -14, |
| 56 | + 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 | + sigma = 0.1 |
| 60 | + |
| 61 | + tf = yt.ColorTransferFunction((min(vals), max(vals))) |
| 62 | + |
| 63 | + tf.clear() |
| 64 | + |
| 65 | + cmap = "coolwarm" |
| 66 | + |
| 67 | + for v, a in zip(vals, alpha): |
| 68 | + tf.sample_colormap(v, sigma**2, alpha=a, colormap=cmap) |
| 69 | + |
| 70 | + sc.get_source(0).transfer_function = tf |
| 71 | + |
| 72 | + cam = sc.add_camera(ds, lens_type="perspective") |
| 73 | + cam.resolution = (1920, 1280) |
| 74 | + |
| 75 | + # view 1 |
| 76 | + |
| 77 | + cam.position = [ds.domain_right_edge[0], |
| 78 | + ds.domain_right_edge[1], |
| 79 | + ds.domain_right_edge[2]] |
| 80 | + |
| 81 | + # look toward the center |
| 82 | + center = 0.5 * (ds.domain_left_edge + ds.domain_right_edge) |
| 83 | + # set the center in the vertical direction to be the height of the underlying base layer |
| 84 | + |
| 85 | + normal = (center - cam.position) |
| 86 | + normal /= np.sqrt(normal.dot(normal)) |
| 87 | + |
| 88 | + cam.switch_orientation(normal_vector=normal, north_vector=[0., 0., 1.]) |
| 89 | + cam.set_width(ds.domain_width) |
| 90 | + cam.zoom(5.0) |
| 91 | + sc.camera = cam |
| 92 | + |
| 93 | + sc.save_annotated(f"{plotfile}_enuc_annotated.png", |
| 94 | + label_fontsize="18", |
| 95 | + label_fmt="%.1f", |
| 96 | + sigma_clip=3, |
| 97 | + text_annotate=[[(0.05, 0.05), |
| 98 | + f"$t - \\tau_\\mathrm{{drive}}$ = {float(ds.current_time) - t_drive:6.1f} s", |
| 99 | + dict(horizontalalignment="left", fontsize="18")]]) |
| 100 | + |
| 101 | + |
| 102 | +if __name__ == "__main__": |
| 103 | + |
| 104 | + # Choose a field |
| 105 | + plotfile = "" |
| 106 | + |
| 107 | + |
| 108 | + try: plotfile = sys.argv[1] |
| 109 | + except: sys.exit("ERROR: no plotfile specified") |
| 110 | + |
| 111 | + doit(plotfile) |
0 commit comments