Skip to content

Commit

Permalink
Small fix to compare tool when saving diffs in no timestep nc files
Browse files Browse the repository at this point in the history
  • Loading branch information
doc78 committed Nov 5, 2024
1 parent d4c5a1b commit 05a684b
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/lisfloodutilities/compare/nc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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 '<mem>'
varname = varname or '<unknown var>'
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:
Expand Down

0 comments on commit 05a684b

Please sign in to comment.