-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add percentile getter methods to CILViewerBase and CILViewer (#336)
* Add percentile getters * Add CILViewerBase test * update changelog and add skipping of tests in gh-actions * Automated autoyapf fixes * add hack for skipping viewer test on gh-a docker build
- Loading branch information
1 parent
d1d29f9
commit 2c619c7
Showing
6 changed files
with
195 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
# Copyright 2023 STFC, United Kingdom Research and Innovation | ||
# | ||
# Author 2023 Laura Murgatroyd | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
import os | ||
import unittest | ||
from unittest import mock | ||
|
||
from ccpi.viewer.CILViewer import CILViewer | ||
|
||
# skip the tests on GitHub actions | ||
if os.environ.get('CONDA_BUILD', '0') == '1': | ||
skip_test = True | ||
else: | ||
skip_test = False | ||
|
||
print("skip_test is set to ", skip_test) | ||
|
||
|
||
@unittest.skipIf(skip_test, "Skipping tests on GitHub Actions") | ||
class CILViewer3DTest(unittest.TestCase): | ||
|
||
def setUp(self): | ||
self.cil_viewer = CILViewer() | ||
|
||
def test_getGradientOpacityPercentiles_returns_correct_percentiles_when_image_values_start_at_zero(self): | ||
self.cil_viewer.gradient_opacity_limits = [40, 50] | ||
self.cil_viewer.getImageMapWholeRange = mock.MagicMock(return_value=[0, 50]) | ||
expected_percentages = (80.0, 100.0) | ||
actual_percentages = self.cil_viewer.getGradientOpacityPercentiles() | ||
self.assertEqual(expected_percentages, actual_percentages) | ||
|
||
def test_getGradientOpacityPercentiles_returns_correct_percentiles_when_image_values_start_at_non_zero(self): | ||
self.cil_viewer.gradient_opacity_limits = [40, 50] | ||
self.cil_viewer.getImageMapWholeRange = mock.MagicMock(return_value=[10, 50]) | ||
expected_percentages = (75.0, 100.0) | ||
actual_percentages = self.cil_viewer.getGradientOpacityPercentiles() | ||
self.assertEqual(expected_percentages, actual_percentages) | ||
|
||
def test_getScalarOpacityPercentiles_returns_correct_percentiles_when_image_values_start_at_zero(self): | ||
self.cil_viewer.scalar_opacity_limits = [40, 50] | ||
self.cil_viewer.getImageMapWholeRange = mock.MagicMock(return_value=[0, 50]) | ||
expected_percentages = (80.0, 100.0) | ||
actual_percentages = self.cil_viewer.getScalarOpacityPercentiles() | ||
self.assertEqual(expected_percentages, actual_percentages) | ||
|
||
def test_getScalarOpacityPercentiles_returns_correct_percentiles_when_image_values_start_at_non_zero(self): | ||
self.cil_viewer.scalar_opacity_limits = [40, 50] | ||
self.cil_viewer.getImageMapWholeRange = mock.MagicMock(return_value=[10, 50]) | ||
expected_percentages = (75.0, 100.0) | ||
actual_percentages = self.cil_viewer.getScalarOpacityPercentiles() | ||
self.assertEqual(expected_percentages, actual_percentages) | ||
|
||
def test_getVolumeColorPercentiles_returns_correct_percentiles_when_image_values_start_at_zero(self): | ||
self.cil_viewer.volume_colormap_limits = [40, 50] | ||
self.cil_viewer.getImageMapWholeRange = mock.MagicMock(return_value=[0, 50]) | ||
expected_percentages = (80.0, 100.0) | ||
actual_percentages = self.cil_viewer.getVolumeColorPercentiles() | ||
self.assertEqual(expected_percentages, actual_percentages) | ||
|
||
def test_getVolumeColorPercentiles_returns_correct_percentiles_when_image_values_start_at_non_zero(self): | ||
self.cil_viewer.volume_colormap_limits = [40, 50] | ||
self.cil_viewer.getImageMapWholeRange = mock.MagicMock(return_value=[10, 50]) | ||
expected_percentages = (75.0, 100.0) | ||
actual_percentages = self.cil_viewer.getVolumeColorPercentiles() | ||
self.assertEqual(expected_percentages, actual_percentages) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# Copyright 2023 STFC, United Kingdom Research and Innovation | ||
# | ||
# Author 2023 Laura Murgatroyd | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
import unittest | ||
from unittest import mock | ||
import os | ||
|
||
from ccpi.viewer.CILViewer import CILViewerBase | ||
|
||
# skip the tests on GitHub actions | ||
if os.environ.get('CONDA_BUILD', '0') == '1': | ||
skip_test = True | ||
else: | ||
skip_test = False | ||
|
||
print("skip_test is set to ", skip_test) | ||
|
||
|
||
@unittest.skipIf(skip_test, "Skipping tests on GitHub Actions") | ||
class CILViewer3DTest(unittest.TestCase): | ||
|
||
def setUp(self): | ||
self.cil_viewer = CILViewerBase() | ||
|
||
def test_getSliceColorPercentiles_returns_correct_percentiles_when_slice_values_start_at_zero(self): | ||
self.cil_viewer.getSliceMapRange = mock.MagicMock(return_value=[40, 50]) | ||
self.cil_viewer.getSliceMapWholeRange = mock.MagicMock(return_value=[0, 50]) | ||
expected_percentages = (80.0, 100.0) | ||
actual_percentages = self.cil_viewer.getSliceColorPercentiles() | ||
self.assertEqual(expected_percentages, actual_percentages) | ||
|
||
def test_getSliceColorPercentiles_returns_correct_percentiles_when_slice_values_start_at_non_zero(self): | ||
self.cil_viewer.getSliceMapRange = mock.MagicMock(return_value=[40, 50]) | ||
self.cil_viewer.getSliceMapWholeRange = mock.MagicMock(return_value=[10, 50]) | ||
expected_percentages = (75.0, 100.0) | ||
actual_percentages = self.cil_viewer.getSliceColorPercentiles() | ||
self.assertEqual(expected_percentages, actual_percentages) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |