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: