From d9e454f09972d34a642b7d661e38581992c61e89 Mon Sep 17 00:00:00 2001 From: chavlin Date: Tue, 10 Dec 2024 17:10:17 -0500 Subject: [PATCH] add more image tests --- examples/amr_spherical_volume_rendering.py | 10 ++- yt_idv/tests/test_spherical_vol_rendering.py | 82 ++++++++++++++++---- 2 files changed, 77 insertions(+), 15 deletions(-) diff --git a/examples/amr_spherical_volume_rendering.py b/examples/amr_spherical_volume_rendering.py index c66892e..90ea76b 100644 --- a/examples/amr_spherical_volume_rendering.py +++ b/examples/amr_spherical_volume_rendering.py @@ -18,8 +18,6 @@ "ew_hemi": np.array([[0.1, 1.0], [0.0, np.pi], [0.0, np.pi]]), "quadrant_shell": np.array([[0.6, 1.0], [0.0, np.pi / 2], [0.0, np.pi / 2]]), } -sz = (256, 256, 256) -fake_data = {"density": np.random.random(sz)} if __name__ == "__main__": @@ -40,9 +38,15 @@ parser.add_argument( "-np", "--nprocs", default=64, help="number of grids to decompose domain to" ) + parser.add_argument( + "-sz", "--size", default=256, help="dimensions, will be (size, size size)" + ) args = parser.parse_args() + sz = (int(args.size),) * 3 + fake_data = {"density": np.random.random(sz)} + field = str(args.field).split(",") if len(field) == 1: field = ("gas", str(field).strip()) @@ -117,5 +121,7 @@ def _r_rev(field, data): rc = yt_idv.render_context(height=800, width=800, gui=True) sg = rc.add_scene(ds, field, no_ghost=True) rc.scene.components[0].sample_factor = 20.0 + rc.scene.components[0].cmap_log = False + rc.scene.components[0]._reset_cmap_bounds() rc.run() diff --git a/yt_idv/tests/test_spherical_vol_rendering.py b/yt_idv/tests/test_spherical_vol_rendering.py index f13d60f..57f32e8 100644 --- a/yt_idv/tests/test_spherical_vol_rendering.py +++ b/yt_idv/tests/test_spherical_vol_rendering.py @@ -6,31 +6,87 @@ @pytest.fixture() -def osmesa_fake_spherical(): - """Return an OSMesa context that has a "fake" AMR dataset added, with "radius" - as the field. - """ +def osmesa_empty_rc(): + """yield an OSMesa empy context then destroy""" + + rc = yt_idv.render_context("osmesa", width=1024, height=1024) + yield rc + rc.osmesa.OSMesaDestroyContext(rc.context) + + +bbox_options = { + "partial": { + "bbox": np.array([[0.5, 1.0], [0.0, np.pi / 3], [np.pi / 4, np.pi / 2]]), + "field": ("index", "r"), + "camera_position": [-0.5, -1, 2.5], + }, + "whole": { + "bbox": np.array([[0.0, 1.0], [0.0, 2 * np.pi], [0, np.pi]]), + "field": ("index", "phi"), + "camera_position": [0.5, 0.5, 2], + }, + "quadrant_shell": { + "bbox": np.array([[0.6, 1.0], [0.0, np.pi / 2], [0.0, np.pi / 2]]), + "field": ("index", "theta"), + }, +} + + +@pytest.mark.parametrize("bbox_option", bbox_options.keys()) +def test_spherical_bounds(osmesa_empty_rc, image_store, bbox_option): sz = (32, 32, 32) fake_data = {"density": np.random.random(sz)} - bbox = np.array([[0.1, 1.0], [0.0, 2 * np.pi], [0, np.pi]]) + bbox = bbox_options[bbox_option]["bbox"] ds = yt.load_uniform_grid( fake_data, sz, bbox=bbox, - nprocs=1, + nprocs=8, + geometry=("spherical", ("r", "phi", "theta")), + length_unit="m", + ) + dd = ds.all_data() + + field = bbox_options[bbox_option]["field"] + osmesa_empty_rc.add_scene(dd, field, no_ghost=True) + osmesa_empty_rc.scene.components[0].sample_factor = 20.0 + osmesa_empty_rc.scene.components[0].cmap_log = False + cpos = bbox_options[bbox_option].get("camera_position", None) + if cpos: + osmesa_empty_rc.scene.camera.position = cpos + + image_store(osmesa_empty_rc) + + +@pytest.mark.parametrize("nprocs", [1, 2, 4, 16]) +def test_spherical_nprocs(osmesa_empty_rc, image_store, nprocs): + + sz = (32, 32, 32) + fake_data = {"density": np.random.random(sz)} + + bbox_option = "whole" + bbox = bbox_options[bbox_option]["bbox"] + + ds = yt.load_uniform_grid( + fake_data, + sz, + bbox=bbox, + nprocs=nprocs, geometry=("spherical", ("r", "phi", "theta")), length_unit="m", ) dd = ds.all_data() - rc = yt_idv.render_context("osmesa", width=1024, height=1024) - rc.add_scene(dd, ("index", "phi"), no_ghost=True) - rc.scene.components[0].sample_factor = 20.0 - yield rc - rc.osmesa.OSMesaDestroyContext(rc.context) + field = bbox_options[bbox_option]["field"] + osmesa_empty_rc.add_scene(dd, field, no_ghost=True) + osmesa_empty_rc.scene.components[0].sample_factor = 20.0 + osmesa_empty_rc.scene.components[0].cmap_log = False + osmesa_empty_rc.scene.components[0]._reset_cmap_bounds() + cpos = bbox_options[bbox_option].get("camera_position", None) + if cpos: + osmesa_empty_rc.scene.camera.position = cpos -def test_spherical(osmesa_fake_spherical, image_store): - image_store(osmesa_fake_spherical) + image_store(osmesa_empty_rc)