Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions Utilities/Python/scripts/make_smv_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,39 @@
# Make Smokeview images for the FDS Manuals.
# The script gets the smokeview executable appropriate for your OS from the smv repository
# unless you provide an optional full path to the executable as an argument.
# After images are created, a comparison is made with the reference figures in the fig repository.

import pandas as pd
import os
import subprocess
import shutil
import platform
import argparse
import sys
from PIL import Image
import numpy as np

def compare_images(image1_path, image2_path):

img1 = Image.open(image1_path).convert('RGB')
img2 = Image.open(image2_path).convert('RGB')

if img1.size != img2.size:
print(f"Warning: Images have different sizes. Resizing {image2_path} to match {image1_path}")
img2 = img2.resize(img1.size, Image.LANCZOS)

arr1 = np.array(img1, dtype=np.float64)
arr2 = np.array(img2, dtype=np.float64)

# Calculate Mean Squared Error (MSE)
mse = np.mean((arr1 - arr2) ** 2)

# Calculate normalized similarity percentage (0-100%)
max_mse = 255.0 ** 2
similarity_percentage = (1 - (mse / max_mse)) * 100

return { 'mse': mse, 'similarity_percentage': similarity_percentage }


parser = argparse.ArgumentParser(description="A script to generate Smokeview images")
parser.add_argument("message", nargs="?", default="null", help="Optional smokeview path")
Expand Down Expand Up @@ -57,3 +83,29 @@

os.chdir(original_dir)

# Compare images just created against the reference images in the fig repository

from pathlib import Path

mandir = '../../Manuals/'
refdir = '../../../fig/fds/Reference_Figures/'
directories = [mandir+'FDS_User_Guide/SCRIPT_FIGURES/' , mandir+'FDS_Verification_Guide/SCRIPT_FIGURES/']

print('comparing images with reference figures...')

for directory in directories:
dir_path = Path(directory)

for png_file in dir_path.glob("*.png"):

try:
results = compare_images(directory+png_file.name, refdir+png_file.name)
if results['similarity_percentage'] < 90:
print('Warning: ',png_file.name,f"{results['similarity_percentage']:.2f}%")
except FileNotFoundError as e:
print(f"Error: Could not find image file - {e}")
sys.exit(1)
except Exception as e:
print(f"Error: {e}")
sys.exit(1)