Skip to content

Commit

Permalink
Merge pull request #36214 from mantidproject/36129_add_colorbar_unit_…
Browse files Browse the repository at this point in the history
…tests

Add colorbar autoscaling limits tests
  • Loading branch information
gemmaguest authored Oct 13, 2023
2 parents a6e27de + 5a85e04 commit f8d158d
Showing 1 changed file with 87 additions and 0 deletions.
87 changes: 87 additions & 0 deletions qt/python/mantidqt/mantidqt/widgets/colorbar/test/test_colorbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,93 @@ 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):
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)

vmin, vmax = self.widget._calculate_auto_color_limits(self.data)

self.assertEqual(vmin, 0.0)
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)

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):
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)

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):
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)

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_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(0)
self.widget.norm.setCurrentIndex(3)

vmin, vmax = self.widget._calculate_auto_color_limits(self.data)

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))

Expand Down

0 comments on commit f8d158d

Please sign in to comment.