From eab3b1c321700ebf29c3066756c8beb615af83b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Robert?= Date: Wed, 6 Apr 2022 11:43:02 +0200 Subject: [PATCH] TST: add tests for resolved symlog issues --- yt/visualization/tests/test_plotwindow.py | 37 +++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/yt/visualization/tests/test_plotwindow.py b/yt/visualization/tests/test_plotwindow.py index 550556cf564..2e9d8437837 100644 --- a/yt/visualization/tests/test_plotwindow.py +++ b/yt/visualization/tests/test_plotwindow.py @@ -722,6 +722,43 @@ def _neg_density(field, data): plot.save(f.name) +def test_symlog_min_zero(): + # see https://github.com/yt-project/yt/issues/3791 + shape = (32, 16, 1) + a = np.linspace(0, 1, 16) + b = np.ones((32, 16)) + c = np.reshape(a * b, shape) + data = {("gas", "density"): c} + + ds = load_uniform_grid( + data, + shape, + bbox=np.array([[0.0, 5.0], [0, 1], [-0.1, +0.1]]), + ) + + p = SlicePlot(ds, "z", "density") + im_arr = p["gas", "density"].image.get_array() + + # check that no data value was mapped to a NaN (log(0)) + assert np.all(~np.isnan(im_arr)) + # 0 should be mapped to itself since we expect a symlog norm + assert np.min(im_arr) == 0.0 + + +def test_symlog_extremely_small_vals(): + # check that the plot can be constructed without crashing + # see https://github.com/yt-project/yt/issues/3858 + shape = (64, 64, 1) + arr = np.full(shape, 5.0e-324) + arr[0, 0] = -1e12 + arr[1, 1] = 200 + d = {"scalar": arr} + + ds = load_uniform_grid(d, shape) + p = SlicePlot(ds, "z", ("stream", "scalar")) + p["stream", "scalar"] + + def test_nan_data(): data = np.random.random((16, 16, 16)) - 0.5 data[:9, :9, :9] = np.nan