Skip to content

Commit

Permalink
add more image tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chrishavlin committed Dec 10, 2024
1 parent 1020705 commit d9e454f
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 15 deletions.
10 changes: 8 additions & 2 deletions examples/amr_spherical_volume_rendering.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__":

Expand All @@ -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())
Expand Down Expand Up @@ -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()
82 changes: 69 additions & 13 deletions yt_idv/tests/test_spherical_vol_rendering.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit d9e454f

Please sign in to comment.