From a31e192ffde68265033730c0f3a1fc3b64923f2f Mon Sep 17 00:00:00 2001 From: Cameron Hummels Date: Thu, 19 Dec 2024 14:50:55 -0800 Subject: [PATCH 1/3] Removing code that removes field type --- yt/visualization/profile_plotter.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/yt/visualization/profile_plotter.py b/yt/visualization/profile_plotter.py index 8d2ef567b42..dcfbc9c32ba 100644 --- a/yt/visualization/profile_plotter.py +++ b/yt/visualization/profile_plotter.py @@ -1319,8 +1319,6 @@ def annotate_title(self, title): """ for f in self._profile.field_data: - if isinstance(f, tuple): - f = f[1] self.plot_title[self.data_source._determine_fields(f)[0]] = title return self From 874fc7134b3653d7eb3e1463d8d58b5fe387cb96 Mon Sep 17 00:00:00 2001 From: Cameron Hummels Date: Thu, 19 Dec 2024 18:08:33 -0800 Subject: [PATCH 2/3] Adding unit tests for SPH-based profile plots --- yt/visualization/tests/test_profile_plots.py | 60 +++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) diff --git a/yt/visualization/tests/test_profile_plots.py b/yt/visualization/tests/test_profile_plots.py index 6c25bfbefc9..787fb5c4320 100644 --- a/yt/visualization/tests/test_profile_plots.py +++ b/yt/visualization/tests/test_profile_plots.py @@ -2,11 +2,12 @@ import shutil import tempfile import unittest +import numpy as np import pytest import yt -from yt.testing import assert_allclose_units, fake_random_ds +from yt.testing import assert_allclose_units, fake_random_ds, fake_random_sph_ds from yt.visualization.api import PhasePlot @@ -65,6 +66,63 @@ def test_phaseplot_set_ylim(self): p.render() return p.plots["gas", "mass"].figure +class TestPhasePlotParticleAPI: + @classmethod + def setup_class(cls): + bbox = np.array([[-1.0, 3.0], [1.0, 5.2], [-1.0, 3.0]]) + cls.ds = fake_random_sph_ds( + 50, bbox + ) + + def get_plot(self): + return PhasePlot( + self.ds, ("gas", "density"), ("gas", "density"), ("gas", "mass") + ) + + @pytest.mark.parametrize("kwargs", [{}, {"color": "b"}]) + @pytest.mark.mpl_image_compare + def test_phaseplot_annotate_text(self, kwargs): + p = self.get_plot() + p.annotate_text(1e-4, 1e-2, "Test text annotation", **kwargs) + p.render() + return p.plots["gas", "mass"].figure + + @pytest.mark.mpl_image_compare + def test_phaseplot_set_title(self): + p = self.get_plot() + p.annotate_title("Test Title") + p.render() + return p.plots["gas", "mass"].figure + + @pytest.mark.mpl_image_compare + def test_phaseplot_set_log(self): + p = self.get_plot() + p.set_log(("gas", "mass"), False) + p.render() + return p.plots["gas", "mass"].figure + + @pytest.mark.mpl_image_compare + def test_phaseplot_set_unit(self): + p = self.get_plot() + p.set_unit(("gas", "mass"), "Msun") + p.render() + return p.plots["gas", "mass"].figure + + @pytest.mark.mpl_image_compare + def test_phaseplot_set_xlim(self): + p = self.get_plot() + p.set_xlim(1e-3, 1e0) + p.render() + return p.plots["gas", "mass"].figure + + @pytest.mark.mpl_image_compare + def test_phaseplot_set_ylim(self): + p = self.get_plot() + p.set_ylim(1e-2, 1e0) + p.render() + return p.plots["gas", "mass"].figure + + def test_set_units(): fields = ("density", "temperature") From 7f7ebca87add255917ddaed06383f34d289d282d Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 20 Dec 2024 06:15:06 +0000 Subject: [PATCH 3/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- yt/visualization/tests/test_profile_plots.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/yt/visualization/tests/test_profile_plots.py b/yt/visualization/tests/test_profile_plots.py index 787fb5c4320..96fea028b8a 100644 --- a/yt/visualization/tests/test_profile_plots.py +++ b/yt/visualization/tests/test_profile_plots.py @@ -2,8 +2,8 @@ import shutil import tempfile import unittest -import numpy as np +import numpy as np import pytest import yt @@ -66,13 +66,12 @@ def test_phaseplot_set_ylim(self): p.render() return p.plots["gas", "mass"].figure + class TestPhasePlotParticleAPI: @classmethod def setup_class(cls): bbox = np.array([[-1.0, 3.0], [1.0, 5.2], [-1.0, 3.0]]) - cls.ds = fake_random_sph_ds( - 50, bbox - ) + cls.ds = fake_random_sph_ds(50, bbox) def get_plot(self): return PhasePlot( @@ -123,7 +122,6 @@ def test_phaseplot_set_ylim(self): return p.plots["gas", "mass"].figure - def test_set_units(): fields = ("density", "temperature") units = (