From ca75fe2cb572652dc236dc73e09a415c00909cc0 Mon Sep 17 00:00:00 2001 From: Mohammed Almakki Date: Wed, 4 Oct 2023 17:32:16 +0100 Subject: [PATCH 1/3] Add colorbar autoscaling limits tests --- .../widgets/colorbar/test/test_colorbar.py | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/qt/python/mantidqt/mantidqt/widgets/colorbar/test/test_colorbar.py b/qt/python/mantidqt/mantidqt/widgets/colorbar/test/test_colorbar.py index cf24b98b2d17..bad9707ccd39 100644 --- a/qt/python/mantidqt/mantidqt/widgets/colorbar/test/test_colorbar.py +++ b/qt/python/mantidqt/mantidqt/widgets/colorbar/test/test_colorbar.py @@ -90,6 +90,52 @@ def test_mixed_slice_gives_valid_clim(self): self.assertEqual(c_min, expected_c_min) self.assertEqual(c_max, 99) + def test_colorbar_limits_min_max(self): + self.widget.autoscale.setChecked(True) + self.widget.autotype.setCurrentIndex(0) + + vmin, vmax = self.widget._calculate_auto_color_limits(self.data) + + self.assertEqual(vmin, 0.0) + self.assertEqual(vmax, 99.0) + + def test_colorbar_limits_min_max_lognorm(self): + self.widget.autoscale.setChecked(True) + self.widget.autotype.setCurrentIndex(0) + self.widget.norm.setCurrentIndex(1) + + vmin, vmax = self.widget._calculate_auto_color_limits(self.data) + + self.assertEqual(vmin, 0.0099) + self.assertEqual(vmax, 99.0) + + def test_colorbar_limits_3sigma(self): + self.widget.autoscale.setChecked(True) + self.widget.autotype.setCurrentIndex(1) + + vmin, vmax = self.widget._calculate_auto_color_limits(self.data) + + self.assertEqual(vmin, 0.0) + self.assertEqual(vmax, 99.0) + + def test_colorbar_limits_15interquartile(self): + self.widget.autoscale.setChecked(True) + self.widget.autotype.setCurrentIndex(2) + + vmin, vmax = self.widget._calculate_auto_color_limits(self.data) + + self.assertEqual(vmin, 0.0) + self.assertEqual(vmax, 99.0) + + def test_colorbar_limits_15median(self): + self.widget.autoscale.setChecked(True) + self.widget.autotype.setCurrentIndex(3) + + vmin, vmax = self.widget._calculate_auto_color_limits(self.data) + + self.assertEqual(vmin, 12.0) + self.assertEqual(vmax, 87.0) + def test_invalid_cmax_range_is_reset(self): image = plt.imshow(self.data, cmap="plasma", norm=SymLogNorm(1e-8, vmin=None, vmax=None)) From 739dbf0f98d40b677bb82fb8b45bef87feb3e631 Mon Sep 17 00:00:00 2001 From: Mohammed Almakki Date: Thu, 5 Oct 2023 09:43:44 +0100 Subject: [PATCH 2/3] Fix colorbar not found error --- .../widgets/colorbar/test/test_colorbar.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/qt/python/mantidqt/mantidqt/widgets/colorbar/test/test_colorbar.py b/qt/python/mantidqt/mantidqt/widgets/colorbar/test/test_colorbar.py index bad9707ccd39..1d9a0ad2ffee 100644 --- a/qt/python/mantidqt/mantidqt/widgets/colorbar/test/test_colorbar.py +++ b/qt/python/mantidqt/mantidqt/widgets/colorbar/test/test_colorbar.py @@ -91,6 +91,9 @@ def test_mixed_slice_gives_valid_clim(self): self.assertEqual(c_max, 99) def test_colorbar_limits_min_max(self): + image = plt.imshow(self.data * np.nan, cmap="plasma", norm=Normalize(vmin=None, vmax=None)) + + self.widget.set_mappable(image) self.widget.autoscale.setChecked(True) self.widget.autotype.setCurrentIndex(0) @@ -100,6 +103,9 @@ def test_colorbar_limits_min_max(self): self.assertEqual(vmax, 99.0) def test_colorbar_limits_min_max_lognorm(self): + image = plt.imshow(self.data * np.nan, cmap="plasma", norm=Normalize(vmin=None, vmax=None)) + + self.widget.set_mappable(image) self.widget.autoscale.setChecked(True) self.widget.autotype.setCurrentIndex(0) self.widget.norm.setCurrentIndex(1) @@ -110,6 +116,9 @@ def test_colorbar_limits_min_max_lognorm(self): self.assertEqual(vmax, 99.0) def test_colorbar_limits_3sigma(self): + image = plt.imshow(self.data * np.nan, cmap="plasma", norm=Normalize(vmin=None, vmax=None)) + + self.widget.set_mappable(image) self.widget.autoscale.setChecked(True) self.widget.autotype.setCurrentIndex(1) @@ -119,6 +128,9 @@ def test_colorbar_limits_3sigma(self): self.assertEqual(vmax, 99.0) def test_colorbar_limits_15interquartile(self): + image = plt.imshow(self.data * np.nan, cmap="plasma", norm=Normalize(vmin=None, vmax=None)) + + self.widget.set_mappable(image) self.widget.autoscale.setChecked(True) self.widget.autotype.setCurrentIndex(2) @@ -128,6 +140,9 @@ def test_colorbar_limits_15interquartile(self): self.assertEqual(vmax, 99.0) def test_colorbar_limits_15median(self): + image = plt.imshow(self.data * np.nan, cmap="plasma", norm=Normalize(vmin=None, vmax=None)) + + self.widget.set_mappable(image) self.widget.autoscale.setChecked(True) self.widget.autotype.setCurrentIndex(3) From 5a85e04f7248e08ecb95c5f23b0aa7b9c92bd955 Mon Sep 17 00:00:00 2001 From: Mohammed Almakki Date: Fri, 13 Oct 2023 10:59:34 +0100 Subject: [PATCH 3/3] Add tests for other modes --- .../widgets/colorbar/test/test_colorbar.py | 50 ++++++++++++++----- 1 file changed, 38 insertions(+), 12 deletions(-) diff --git a/qt/python/mantidqt/mantidqt/widgets/colorbar/test/test_colorbar.py b/qt/python/mantidqt/mantidqt/widgets/colorbar/test/test_colorbar.py index 1d9a0ad2ffee..34b7264d87d4 100644 --- a/qt/python/mantidqt/mantidqt/widgets/colorbar/test/test_colorbar.py +++ b/qt/python/mantidqt/mantidqt/widgets/colorbar/test/test_colorbar.py @@ -102,54 +102,80 @@ def test_colorbar_limits_min_max(self): self.assertEqual(vmin, 0.0) self.assertEqual(vmax, 99.0) - def test_colorbar_limits_min_max_lognorm(self): + def test_colorbar_limits_3sigma(self): image = plt.imshow(self.data * np.nan, cmap="plasma", norm=Normalize(vmin=None, vmax=None)) self.widget.set_mappable(image) self.widget.autoscale.setChecked(True) - self.widget.autotype.setCurrentIndex(0) - self.widget.norm.setCurrentIndex(1) + self.widget.autotype.setCurrentIndex(1) vmin, vmax = self.widget._calculate_auto_color_limits(self.data) - self.assertEqual(vmin, 0.0099) + self.assertEqual(vmin, 0.0) self.assertEqual(vmax, 99.0) - def test_colorbar_limits_3sigma(self): + def test_colorbar_limits_15interquartile(self): image = plt.imshow(self.data * np.nan, cmap="plasma", norm=Normalize(vmin=None, vmax=None)) self.widget.set_mappable(image) self.widget.autoscale.setChecked(True) - self.widget.autotype.setCurrentIndex(1) + self.widget.autotype.setCurrentIndex(2) vmin, vmax = self.widget._calculate_auto_color_limits(self.data) self.assertEqual(vmin, 0.0) self.assertEqual(vmax, 99.0) - def test_colorbar_limits_15interquartile(self): + def test_colorbar_limits_15median(self): image = plt.imshow(self.data * np.nan, cmap="plasma", norm=Normalize(vmin=None, vmax=None)) self.widget.set_mappable(image) self.widget.autoscale.setChecked(True) - self.widget.autotype.setCurrentIndex(2) + self.widget.autotype.setCurrentIndex(3) + + vmin, vmax = self.widget._calculate_auto_color_limits(self.data) + + self.assertEqual(vmin, 12.0) + self.assertEqual(vmax, 87.0) + + def test_colorbar_limits_min_max_lognorm(self): + image = plt.imshow(self.data * np.nan, cmap="plasma", norm=Normalize(vmin=None, vmax=None)) + + self.widget.set_mappable(image) + self.widget.autoscale.setChecked(True) + self.widget.autotype.setCurrentIndex(0) + self.widget.norm.setCurrentIndex(1) + + vmin, vmax = self.widget._calculate_auto_color_limits(self.data) + + self.assertEqual(vmin, 0.0099) + self.assertEqual(vmax, 99.0) + + def test_colorbar_limits_min_max_symmetric_log10(self): + image = plt.imshow(self.data * np.nan, cmap="plasma", norm=Normalize(vmin=None, vmax=None)) + + self.widget.set_mappable(image) + self.widget.autoscale.setChecked(True) + self.widget.autotype.setCurrentIndex(0) + self.widget.norm.setCurrentIndex(2) vmin, vmax = self.widget._calculate_auto_color_limits(self.data) self.assertEqual(vmin, 0.0) self.assertEqual(vmax, 99.0) - def test_colorbar_limits_15median(self): + def test_colorbar_limits_min_max_power(self): image = plt.imshow(self.data * np.nan, cmap="plasma", norm=Normalize(vmin=None, vmax=None)) self.widget.set_mappable(image) self.widget.autoscale.setChecked(True) - self.widget.autotype.setCurrentIndex(3) + self.widget.autotype.setCurrentIndex(0) + self.widget.norm.setCurrentIndex(3) vmin, vmax = self.widget._calculate_auto_color_limits(self.data) - self.assertEqual(vmin, 12.0) - self.assertEqual(vmax, 87.0) + self.assertEqual(vmin, 0.0) + self.assertEqual(vmax, 99.0) def test_invalid_cmax_range_is_reset(self): image = plt.imshow(self.data, cmap="plasma", norm=SymLogNorm(1e-8, vmin=None, vmax=None))