From 4cdf956170a1c99144473ffc249f93ab83745861 Mon Sep 17 00:00:00 2001 From: Nathan Korinek Date: Wed, 12 Feb 2020 09:52:28 -0700 Subject: [PATCH 1/6] First draft of get_images function --- matplotcheck/raster.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/matplotcheck/raster.py b/matplotcheck/raster.py index a8f8e4da..4fba95cd 100644 --- a/matplotcheck/raster.py +++ b/matplotcheck/raster.py @@ -163,6 +163,18 @@ def assert_legend_accuracy_classified_image( ### IMAGE TESTS/HELPER FUNCTIONS ### + def get_plot_image(self): + """Returns images stored on the Axes object as a lsit of numpy arrays.""" + im_data = [] + if self.ax.get_images(): + im_data = self.ax.get_images()[0].get_array() + assert list(im_data), "No Image Displayed" + + # If image array has 3 dims (e.g. rgb image), remove alpha channel + if len(im_data.shape) == 3: + im_data = im_data[:, :, :3] + return im_data + def assert_image( self, im_expected, im_classified=False, m="Incorrect Image Displayed" ): From f4c3bb0e201034a101d3a86a751251d561b7929d Mon Sep 17 00:00:00 2001 From: Nathan Korinek Date: Wed, 12 Feb 2020 10:12:39 -0700 Subject: [PATCH 2/6] Added a test for get_image --- matplotcheck/raster.py | 22 +++++++++++++++------- matplotcheck/tests/test_raster.py | 5 +++++ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/matplotcheck/raster.py b/matplotcheck/raster.py index 4fba95cd..23c89be3 100644 --- a/matplotcheck/raster.py +++ b/matplotcheck/raster.py @@ -164,7 +164,13 @@ def assert_legend_accuracy_classified_image( ### IMAGE TESTS/HELPER FUNCTIONS ### def get_plot_image(self): - """Returns images stored on the Axes object as a lsit of numpy arrays.""" + """Returns images stored on the Axes object as a lsit of numpy arrays. + + Returns + ------- + im_data: List + Numpy array of images stored on Axes object. + """ im_data = [] if self.ax.get_images(): im_data = self.ax.get_images()[0].get_array() @@ -182,12 +188,14 @@ def assert_image( Parameters ---------- - im_expected: array containing the expected image data - im_classified: boolean, set to True image has been classified. - Since classified images values can be reversed or shifted and still - produce the same image, setting this to True will allow those - changes. - m: string error message if assertion is not met + im_expected: Numpy Array + Array containing the expected image data. + im_classified: boolean + Set to True image has been classified. Since classified images + values can be reversed or shifted and still produce the same image, + setting this to True will allow those changes. + m: string + String error message if assertion is not met. Returns ---------- diff --git a/matplotcheck/tests/test_raster.py b/matplotcheck/tests/test_raster.py index ab59e62e..072f2514 100644 --- a/matplotcheck/tests/test_raster.py +++ b/matplotcheck/tests/test_raster.py @@ -317,3 +317,8 @@ def test_raster_assert_image_fullscreen_blank(raster_plt_blank): with pytest.raises(AssertionError, match="No image found on axes"): raster_plt_blank.assert_image_full_screen() plt.close() + +def test_get_plot_images(raster_plt_rgb): + """get_plot_image should get correct image from ax object""" + ax_im = raster_plt_rgb.get_plot_image() + raster_plt_rgb.assert_image(ax_im) From 9df15c426bfae49ab6c53af40f9ba850cea8cc57 Mon Sep 17 00:00:00 2001 From: Nathan Korinek Date: Wed, 12 Feb 2020 10:13:48 -0700 Subject: [PATCH 3/6] Changelog update --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 046dccfa..19c08878 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] * Created a vignette covering the testing of histograms (@ryla5068, #149) +* Created `get_plot_image()` function for the RasterTester object (@nkorinek, #192) ## [0.1.1] * Added test for bin heights of histograms (@ryla5068, #124) From 548e0dda5f72dc77f2dbb0a503d5e02a6caaee9b Mon Sep 17 00:00:00 2001 From: Nathan Korinek Date: Wed, 12 Feb 2020 10:17:40 -0700 Subject: [PATCH 4/6] minor formatting change. --- matplotcheck/raster.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matplotcheck/raster.py b/matplotcheck/raster.py index 23c89be3..837bc15e 100644 --- a/matplotcheck/raster.py +++ b/matplotcheck/raster.py @@ -169,7 +169,7 @@ def get_plot_image(self): Returns ------- im_data: List - Numpy array of images stored on Axes object. + Numpy array of images stored on Axes object. """ im_data = [] if self.ax.get_images(): From 5827e15a6cb9f36694e742c56c61cd7f4ca6ad16 Mon Sep 17 00:00:00 2001 From: Nathan Korinek Date: Wed, 12 Feb 2020 10:40:45 -0700 Subject: [PATCH 5/6] black changes --- matplotcheck/tests/test_raster.py | 1 + 1 file changed, 1 insertion(+) diff --git a/matplotcheck/tests/test_raster.py b/matplotcheck/tests/test_raster.py index 072f2514..dd623660 100644 --- a/matplotcheck/tests/test_raster.py +++ b/matplotcheck/tests/test_raster.py @@ -318,6 +318,7 @@ def test_raster_assert_image_fullscreen_blank(raster_plt_blank): raster_plt_blank.assert_image_full_screen() plt.close() + def test_get_plot_images(raster_plt_rgb): """get_plot_image should get correct image from ax object""" ax_im = raster_plt_rgb.get_plot_image() From c20f611e0b89ed63b1b00ba5e93c365c06b3a5e1 Mon Sep 17 00:00:00 2001 From: Nathan Korinek Date: Thu, 13 Feb 2020 10:27:16 -0700 Subject: [PATCH 6/6] Update matplotcheck/raster.py Co-Authored-By: Leah Wasser --- matplotcheck/raster.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matplotcheck/raster.py b/matplotcheck/raster.py index 837bc15e..c84612df 100644 --- a/matplotcheck/raster.py +++ b/matplotcheck/raster.py @@ -164,7 +164,7 @@ def assert_legend_accuracy_classified_image( ### IMAGE TESTS/HELPER FUNCTIONS ### def get_plot_image(self): - """Returns images stored on the Axes object as a lsit of numpy arrays. + """Returns images stored on the Axes object as a list of numpy arrays. Returns -------