def test_plot_image_and_multiple_contours( test_output_dirs: TestOutputDirectories) -> None: """ Test plotting of an image with two overlaid contours. """ size = (3, 3) image = np.zeros(size) image[0, 0] = -1 image[2, 2] = 1 labels1 = np.zeros(size) labels1[1, 1] = 1 labels2 = np.zeros(size) labels2[0, 0] = 1 file_name = "image_and_multiple_contours.png" plot_file = Path(test_output_dirs.root_dir) / file_name args1 = {'colors': 'r', 'linestyles': 'dashed'} args2 = {'colors': 'b'} plotting.plot_image_and_label_contour(image, [labels1, labels2], contour_arguments=[args1, args2], plot_file_name=plot_file) assert plot_file.exists() expected = full_ml_test_data_path(file_name) # To update the stored results, uncomment this line: # expected.write_bytes(plot_file.read_bytes()) assert file_as_bytes(plot_file) == file_as_bytes(expected)
def test_plot_image_and_contour(test_output_dirs: OutputFolderForTests) -> None: """ Test plotting of an image with an overlaid contour. """ size = (3, 3) image = np.zeros(size) image[0, 0] = -1 image[2, 2] = 1 labels = np.zeros(size) labels[1, 1] = 1 file_name = "image_and_contour.png" plot_file = test_output_dirs.root_dir / file_name plotting.plot_image_and_label_contour(image, labels, contour_arguments={'colors': 'r'}, plot_file_name=plot_file) assert plot_file.exists() expected = full_ml_test_data_path(file_name) # To update the stored results, uncomment this line: # expected.write_bytes(plot_file.read_bytes()) assert file_as_bytes(plot_file) == file_as_bytes(expected)
def test_plot_image_and_contour_scaled(test_output_dirs: OutputFolderForTests) -> None: """ When providing an additional scaling that is a lot larger than the image range, the output should be mostly grey. """ size = (3, 3) image = np.zeros(size) image[0, 0] = -1 image[2, 2] = 1 labels = np.zeros(size) labels[1, 1] = 1 file_name = "image_scaled_and_contour.png" plot_file = test_output_dirs.root_dir / file_name plotting.plot_image_and_label_contour(image, labels, contour_arguments={'colors': 'b'}, image_range=(-5, 5), plot_file_name=plot_file) assert plot_file.exists() expected = full_ml_test_data_path(file_name) # To update the stored results, uncomment this line: # expected.write_bytes(plot_file.read_bytes()) assert file_as_bytes(plot_file) == file_as_bytes(expected)
def test_plot_image_and_contour( test_output_dirs: TestOutputDirectories) -> None: """ Test plotting of an image with an overlaid contour. """ size = (3, 3) image = np.zeros(size) image[0, 0] = -1 image[2, 2] = 1 labels = np.zeros(size) labels[1, 1] = 1 file_name = "image_and_contour.png" plot_file = Path(test_output_dirs.root_dir) / file_name plotting.plot_image_and_label_contour(image, labels, contour_arguments={'colors': 'r'}, plot_file_name=plot_file) assert plot_file.exists() expected = full_ml_test_data_path(file_name) assert file_as_bytes(plot_file) == file_as_bytes(expected)
def test_plot_image_and_contour_scaled( test_output_dirs: TestOutputDirectories) -> None: """ When providing an additional scaling that is a lot larger than the image range, the output should be mostly grey. """ size = (3, 3) image = np.zeros(size) image[0, 0] = -1 image[2, 2] = 1 labels = np.zeros(size) labels[1, 1] = 1 file_name = "image_scaled_and_contour.png" plot_file = Path(test_output_dirs.root_dir) / file_name plotting.plot_image_and_label_contour(image, labels, contour_arguments={'colors': 'b'}, image_range=(-5, 5), plot_file_name=plot_file) assert plot_file.exists() expected = full_ml_test_data_path(file_name) assert file_as_bytes(plot_file) == file_as_bytes(expected)
def test_plot_contour_fails() -> None: with pytest.raises(ValueError) as ex: plotting.plot_image_and_label_contour(np.zeros((3, 3, 3)), np.zeros((2, 2)), plot_file_name=Path("x")) assert "should be a 2D array" in str(ex) with pytest.raises(ValueError) as ex: plotting.plot_image_and_label_contour(np.zeros((3, 3)), np.zeros((2, 2)), plot_file_name=Path("x")) assert "image and the contour data should have matching size" in str(ex) with pytest.raises(ValueError) as ex: plotting.plot_image_and_label_contour(np.zeros((3, 3)), [np.zeros((2, 2))], contour_arguments={'colors': 'r'}, plot_file_name=Path("x")) assert "Combination of input arguments is not recognized" in str(ex)