Skip to content

Commit d968227

Browse files
Fix autoassess normalise error (#4187)
Co-authored-by: Julien Lenhardt <45034763+jlenh@users.noreply.github.com>
1 parent 3ed5f2d commit d968227

1 file changed

Lines changed: 15 additions & 5 deletions

File tree

esmvaltool/diag_scripts/autoassess/_plot_mo_metrics.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@
3737
]
3838

3939

40+
class TestError(Exception):
41+
"""Error with the tests provided."""
42+
43+
4044
def merge_obs_acc(obs, acc):
4145
"""
4246
Merge observation errors.
@@ -409,17 +413,17 @@ def metric_colours(test, ref=None, var=None, obs=None, acc=None):
409413
return colours
410414

411415

412-
def normalise(test, ref, strict=True):
416+
def normalise(test, ref, same=False):
413417
"""
414418
Routine to normalise contents of test by contents of ref.
415419
416420
:param dict test: Dictionary of test metrics
417421
:param dict ref: Dictionary of reference metrics
418-
:param bool strict: if True then test and ref must have same metrics
422+
:param bool same: if True then test and ref must have same metrics
419423
:returns: Dictionary of normalised test metrics
420424
:rtype: dict.
421425
"""
422-
if strict:
426+
if same:
423427
# Test to make sure reference metrics dictionary contains the same
424428
# metrics as test metrics dictionary
425429
assert sorted(test.keys()) == sorted(ref.keys()), (
@@ -651,10 +655,16 @@ def plot_nac(
651655
plot_obs(ax, metrics, n_obs, color=OBS_GREY, zorder=2)
652656

653657
# Plot metric data
658+
# Check enough MARKERS for number of tests
659+
if len(tests) > len(MARKERS):
660+
raise TestError(
661+
f"Number of tests, {len(tests)}, is larger than available "
662+
f"plot MARKERS, {len(MARKERS)}."
663+
)
654664
n_tests = []
655-
for test, marker in zip(tests, MARKERS, strict=True):
665+
for test, marker in zip(tests, MARKERS[: len(tests)], strict=True):
656666
# Normalise test by ref
657-
n_test = normalise(test, ref, strict=True)
667+
n_test = normalise(test, ref, same=True)
658668

659669
# Check for green/amber/red/grey
660670
colours = metric_colours(n_test, var=n_var, obs=n_obs, acc=n_acc)

0 commit comments

Comments
 (0)