From 5080983389e4c3058e3fe967508ffcb5c33eba2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Robert?= Date: Thu, 31 Oct 2024 09:35:25 +0100 Subject: [PATCH] TST: add image tests for cylindrical pixelization of a box with rmin>0 --- tests/pytest_mpl_baseline | 2 +- yt/testing.py | 16 ++++++++--- .../tests/test_image_comp_2D_plots.py | 28 +++++++++++++++++++ 3 files changed, 41 insertions(+), 5 deletions(-) diff --git a/tests/pytest_mpl_baseline b/tests/pytest_mpl_baseline index 8a30c989a30..a4bf2e0e56a 160000 --- a/tests/pytest_mpl_baseline +++ b/tests/pytest_mpl_baseline @@ -1 +1 @@ -Subproject commit 8a30c989a30b00e681db645cc767cb9047508169 +Subproject commit a4bf2e0e56a037c911f4a5e0443dd60f1e9c82c7 diff --git a/yt/testing.py b/yt/testing.py index 98bfb596152..a7afe0bd7d4 100644 --- a/yt/testing.py +++ b/yt/testing.py @@ -431,7 +431,14 @@ def fake_random_ds( def fake_amr_ds( - fields=None, units=None, geometry="cartesian", particles=0, length_unit=None + fields=None, + units=None, + geometry="cartesian", + particles=0, + length_unit=None, + *, + domain_left_edge=None, + domain_right_edge=None, ): from yt.loaders import load_amr_grids @@ -447,9 +454,10 @@ def fake_amr_ds( ) prng = RandomState(0x4D3D3D3) - LE, RE = _geom_transforms[geometry] - LE = np.array(LE) - RE = np.array(RE) + default_LE, default_RE = _geom_transforms[geometry] + + LE = np.array(domain_left_edge or default_LE, dtype="float64") + RE = np.array(domain_right_edge or default_RE, dtype="float64") data = [] for gspec in _amr_grid_index: level, left_edge, right_edge, dims = gspec diff --git a/yt/visualization/tests/test_image_comp_2D_plots.py b/yt/visualization/tests/test_image_comp_2D_plots.py index 371256c0eb4..b7f99100fce 100644 --- a/yt/visualization/tests/test_image_comp_2D_plots.py +++ b/yt/visualization/tests/test_image_comp_2D_plots.py @@ -433,6 +433,34 @@ def test_cylindrical_z_linear(self, field): self.plot.set_log("noise0", False) return self.plot.plots[field].figure + @pytest.mark.parametrize( + "theta_min, theta_max", + [ + pytest.param(0, 2 * np.pi, id="full_azimuthal_domain"), + pytest.param(3 / 4 * np.pi, 5 / 4 * np.pi, id="restricted_sector"), + ], + ) + @pytest.mark.mpl_image_compare + def test_exclude_pixels_with_partial_bbox_intersection(self, theta_min, theta_max): + rmin = 1.0 + rmax = 2.0 + ds = fake_amr_ds( + geometry="cylindrical", + domain_left_edge=[rmin, 0, theta_min], + domain_right_edge=[rmax, 1, theta_max], + ) + add_noise_fields(ds) + plot = SlicePlot(ds, "z", ("gas", "noise0")) + for radius in [rmin - 0.01, rmax]: + plot.annotate_sphere( + center=[0, 0, 0], + radius=radius, + circle_args={"color": "red", "alpha": 0.4, "linewidth": 3}, + ) + plot.annotate_title("all pixels beyond (or on) red lines should be white") + plot.render() + return plot.plots["gas", "noise0"].figure + class TestSphericalPhiSlicePlot: @classmethod