Skip to content

Commit c1daa45

Browse files
committed
python: copied relevant sewar functions
1 parent d7a672f commit c1daa45

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

python/inet/test/chart.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import logging
1414
import matplotlib
1515
import numpy
16-
import sewar
16+
import importlib.util
1717

1818
import omnetpp
1919
import omnetpp.scave
@@ -26,6 +26,25 @@
2626

2727
_logger = logging.getLogger(__name__)
2828

29+
30+
def sewar_rmse(a, b):
31+
a,b = sewar_initial_check(a,b)
32+
return numpy.sqrt(numpy.mean((a.astype(numpy.float64)-b.astype(numpy.float64))**2))
33+
34+
def sewar_initial_check(GT,P):
35+
assert GT.shape == P.shape, "Supplied images have different sizes " + \
36+
str(GT.shape) + " and " + str(P.shape)
37+
if GT.dtype != P.dtype:
38+
msg = "Supplied images have different dtypes " + \
39+
str(GT.dtype) + " and " + str(P.dtype)
40+
_logger.warn(msg)
41+
42+
if len(GT.shape) == 2:
43+
GT = GT[:,:,numpy.newaxis]
44+
P = P[:,:,numpy.newaxis]
45+
46+
return GT.astype(numpy.float64),P.astype(numpy.float64)
47+
2948
class ChartTestTask(TestTask):
3049
def __init__(self, analysis_file_name, id, chart_name, simulation_project=None, name="chart test", **kwargs):
3150
super().__init__(name=name, **kwargs)
@@ -58,7 +77,7 @@ def run_protected(self, keep_charts=True, output_stream=sys.stdout, **kwargs):
5877
if os.path.exists(old_file_name):
5978
new_image = matplotlib.image.imread(new_file_name)
6079
old_image = matplotlib.image.imread(old_file_name)
61-
metric = sewar.rmse(old_image, new_image)
80+
metric = sewar_rmse(old_image, new_image)
6281
if metric == 0 or not keep_charts:
6382
os.remove(new_file_name)
6483
else:
@@ -164,7 +183,7 @@ def run_protected(self, keep_charts=True, **kwargs):
164183
if os.path.exists(old_file_name):
165184
new_image = matplotlib.image.imread(new_file_name)
166185
old_image = matplotlib.image.imread(old_file_name)
167-
metric = sewar.rmse(old_image, new_image)
186+
metric = sewar_rmse(old_image, new_image)
168187
if metric == 0:
169188
os.remove(new_file_name)
170189
else:

0 commit comments

Comments
 (0)