Skip to content

Commit

Permalink
add a test for the depth argument in off axis projs for grids
Browse files Browse the repository at this point in the history
  • Loading branch information
chrishavlin committed Jan 30, 2025
1 parent 3898a16 commit f935d23
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions yt/visualization/tests/test_offaxisprojection_pytestonly.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import numpy as np
import pytest
import unyt
from numpy.testing import assert_allclose

from yt.testing import (
assert_rel_equal,
cubicspline_python,
fake_amr_ds,
fake_sph_flexible_grid_ds,
integrate_kernel,
)
Expand Down Expand Up @@ -165,3 +167,45 @@ def makemasses(i, j, k):
# print("expected:\n", expected_out)
# print("recovered:\n", img.v)
assert_rel_equal(expected_out, img.v, 4)


@pytest.fixture
def fame_amr_ds_for_proj():
return fake_amr_ds()


_diag_dist = np.sqrt(3.0) # diagonal distance of a cube with length 1.
# each case is depth, center, expected integrated distance
_cases_to_test = [
(_diag_dist / 3.0, "domain_left_edge", _diag_dist / 3.0 / 2.0),
(_diag_dist * 2.0, "domain_left_edge", _diag_dist),
(_diag_dist * 4.0, "domain_left_edge", _diag_dist),
(None, "domain_center", _diag_dist),
]


@pytest.mark.parametrize("depth,proj_center,expected", _cases_to_test)
def test_offaxisprojection_depth(depth, proj_center, expected, fame_amr_ds_for_proj):
# this checks that the depth keyword argument works as expected.
# in all cases, it integrates the (index, ones) field for a normal
# pointing to the right edge corner of the domain.
#
# For the tests where the projection is centered on the left edge,
# the integrate distance will scale as depth / 2.0. When centered
# on the origin, it will scale with depth. The integrated distance
# should max out at the diagonal distance of the cube (when the depth
# exceeds the cube diagonal distance).
#
# Also note that the accuracy will depend on the buffer dimensions:
# using the default (800,800) results in accuracy of about 1 percent

ds = fame_amr_ds_for_proj

n = [1.0, 1.0, 1.0]
c = getattr(ds, proj_center)
field = ("index", "ones")

p = ProjectionPlot(ds, n, field, depth=depth, weight_field=None, center=c)

maxval = p.frb[field].max().d
assert_allclose(expected, maxval, atol=1e-2)

0 comments on commit f935d23

Please sign in to comment.