From 05a684b41edd2e6a562926dff204f2a74e9c64a3 Mon Sep 17 00:00:00 2001 From: Carlo Russo Date: Tue, 5 Nov 2024 11:19:07 +0100 Subject: [PATCH] Small fix to compare tool when saving diffs in no timestep nc files --- src/lisfloodutilities/compare/nc.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/lisfloodutilities/compare/nc.py b/src/lisfloodutilities/compare/nc.py index 43d5b22..94828ef 100644 --- a/src/lisfloodutilities/compare/nc.py +++ b/src/lisfloodutilities/compare/nc.py @@ -24,7 +24,8 @@ class NetCDFComparator(Comparator): glob_expr = ['**/*.nc'] def write_diff_files(self, filepath, varname, step, vara_step, varb_step, diff_values, lats, lons, time): - self.diff_timesteps.append(time[step]) + if time: + self.diff_timesteps.append(time[step]) filename, _ = os.path.splitext(os.path.basename(filepath)) filepath_a = self.diff_folder.joinpath(filename + '_a.nc') filepath_b = self.diff_folder.joinpath(filename + '_b.nc') @@ -194,10 +195,10 @@ def compare_arrays(self, vara_step, varb_step, varname=None, step=None, filepath max_diff = np.ma.amax(diff_values_no_nan) # returns a scalar perc_wrong = different_values_size * 100 / vara_step.size if perc_wrong >= self.max_perc_diff or (perc_wrong >= self.max_perc_large_diff and max_diff > self.large_diff_th): - step = step if step is not None else '(no time)' + step_print = step if step is not None else '(no time)' filepath = os.path.basename(filepath) if filepath else '' varname = varname or '' - message = '{}/{}@{} - {:3.2f}% of different values - max diff: {:3.6f}'.format(filepath, varname, step, perc_wrong, max_diff) + message = '{}/{}@{} - {:3.2f}% of different values - max diff: {:3.6f}'.format(filepath, varname, step_print, perc_wrong, max_diff) if self.for_testing: assert False, message else: