|
28 | 28 |
|
29 | 29 |
|
30 | 30 | def sewar_rmse(a, b):
|
31 |
| - a,b = sewar_initial_check(a,b) |
| 31 | + assert a.shape == b.shape, "Supplied images have different sizes " + \ |
| 32 | + str(a.shape) + " and " + str(b.shape) |
| 33 | + if len(a.shape) == 2: |
| 34 | + a = a[:,:,numpy.newaxis] |
| 35 | + b = b[:,:,numpy.newaxis] |
| 36 | + a = a.astype(numpy.float64) |
| 37 | + b = b.astype(numpy.float64) |
32 | 38 | return numpy.sqrt(numpy.mean((a.astype(numpy.float64)-b.astype(numpy.float64))**2))
|
33 | 39 |
|
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 |
| - |
48 | 40 | class ChartTestTask(TestTask):
|
49 | 41 | def __init__(self, analysis_file_name, id, chart_name, simulation_project=None, name="chart test", **kwargs):
|
50 | 42 | super().__init__(name=name, **kwargs)
|
@@ -77,8 +69,12 @@ def run_protected(self, keep_charts=True, output_stream=sys.stdout, **kwargs):
|
77 | 69 | if os.path.exists(old_file_name):
|
78 | 70 | new_image = matplotlib.image.imread(new_file_name)
|
79 | 71 | old_image = matplotlib.image.imread(old_file_name)
|
| 72 | + if old_image.shape != new_image.shape: |
| 73 | + return self.task_result_class(self, result="FAIL", reason="Supplied images have different sizes" + str(old_image.shape) + " and " + str(new_image.shape)) |
80 | 74 | metric = sewar_rmse(old_image, new_image)
|
81 |
| - if metric == 0 or not keep_charts: |
| 75 | + if type(metric) == str: |
| 76 | + _logger.info(metric) |
| 77 | + elif metric == 0 or not keep_charts: |
82 | 78 | os.remove(new_file_name)
|
83 | 79 | else:
|
84 | 80 | image_diff = numpy.abs(new_image - old_image)
|
@@ -183,7 +179,10 @@ def run_protected(self, keep_charts=True, **kwargs):
|
183 | 179 | if os.path.exists(old_file_name):
|
184 | 180 | new_image = matplotlib.image.imread(new_file_name)
|
185 | 181 | old_image = matplotlib.image.imread(old_file_name)
|
186 |
| - metric = sewar_rmse(old_image, new_image) |
| 182 | + if old_image.shape != new_image.shape: |
| 183 | + metric = 1 |
| 184 | + else: |
| 185 | + metric = sewar_rmse(old_image, new_image) |
187 | 186 | if metric == 0:
|
188 | 187 | os.remove(new_file_name)
|
189 | 188 | else:
|
|
0 commit comments