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 29, 2025
1 parent 3898a16 commit 4758a58
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 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,40 @@ def makemasses(i, j, k):
# print("expected:\n", expected_out)
# print("recovered:\n", img.v)
assert_rel_equal(expected_out, img.v, 4)


def test_offaxisprojection_depth():
# this checks that the depth keyword argument works as expected.
# it sets up an off axis projection center at the left edge
# of the domain, looking towards the right edge, and then integrates
# the (index, ones) field at increasing depth.
# The result should scale linearly with the depth value and should
# max out at the diagonal distance of the cube. Note that because
# the depth is actually a full-width centered on the projection
# center, the actual scaling is: integrated distance = depth / 2.0

ds = fake_amr_ds()

n = [1.0, 1.0, 1.0]
c = ds.domain_left_edge
field = ("index", "ones")

diag_dist = np.linalg.norm(ds.domain_width.in_units("code_length"))

# pick a point less than the max, exactly at the max and past it
depths = np.array([diag_dist / 3.0, diag_dist * 2.0, diag_dist * 4.0])

# expected values of the integrations
expected = depths / 2.0
expected[depths > 2 * diag_dist] = diag_dist

maxvals = []
for depth in depths:
p = ProjectionPlot(
ds, n, field, depth=depth, weight_field=None, center=c, width=diag_dist
)

maxvals.append(p.frb[field].max())

maxvals = np.array(maxvals)
assert_allclose(expected, maxvals, atol=1e-2)

0 comments on commit 4758a58

Please sign in to comment.