Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More tests on graphical comparisons #47

Open
jcrivenaes opened this issue Sep 16, 2024 · 0 comments
Open

More tests on graphical comparisons #47

jcrivenaes opened this issue Sep 16, 2024 · 0 comments

Comments

@jcrivenaes
Copy link
Collaborator

The previous issue #46 demonstrates that unit tests that compare graphical output should be addressed.

One taks is to make a separate comparison function, used by tests, that can compare the generated plots with base line plots. This has been tried earlier but the tests need some kind of tolerance due to subtle library changes (and possibly differences between os)

E.g. (via Copilot):

# conftest.py
import os
from PIL import Image
from skimage.metrics import structural_similarity as compare_ssim
import numpy as np

def compare_plots(generated_plot_path, reference_plot_path, threshold=0.95):
    """
    Compare two plots using Structural Similarity Index (SSIM).

    :param generated_plot_path: Path to the generated plot.
    :param reference_plot_path: Path to the reference plot.
    :param threshold: SSIM threshold to consider images approximately equal.
    :return: None. Raises AssertionError if plots are not approximately equal.
    """
    # Load the images
    generated_image = Image.open(generated_plot_path).convert('L')
    reference_image = Image.open(reference_plot_path).convert('L')

    # Convert images to numpy arrays
    generated_image_np = np.array(generated_image)
    reference_image_np = np.array(reference_image)

    # Compute the Structural Similarity Index (SSIM) between the images
    ssim_index, _ = compare_ssim(generated_image_np, reference_image_np, full=True)

    print("SSIM index:", ssim_index)

    # Assert that the SSIM index is above the threshold
    assert ssim_index > threshold, "The plot has changed significantly!"
@jcrivenaes jcrivenaes changed the title More tests on graphical comparsions More tests on graphical comparisons Sep 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant