diff --git a/verif/driver.py b/verif/driver.py index ac4844e..e48666f 100644 --- a/verif/driver.py +++ b/verif/driver.py @@ -556,6 +556,16 @@ def run(argv): if quantiles is None: quantiles = data.quantiles verif.util.warning("Missing '-q '. Automatically setting quantiles: %s" % (','.join(["%g" % q for q in quantiles]))) + + # Check that we have the right number of quantiles + if m is not None: + if m.min_num_thresholds is not None: + if len(quantiles) < m.min_num_thresholds: + verif.util.error(f"Need to specify at least {m.min_num_thresholds} quantiles (-q)") + if m.max_num_thresholds is not None: + if len(quantiles) > m.max_num_thresholds: + verif.util.error(f"Need to specify at most {m.max_num_thresholds} quantiles (-q)") + # TODO: This is a bit of a hack, using thresholds to hold the # quantiles. But otherwise, the classes in output need to deal with # testing if the metric needs thresholds or quantiles diff --git a/verif/metric.py b/verif/metric.py index b8d8b2f..2d68136 100644 --- a/verif/metric.py +++ b/verif/metric.py @@ -143,6 +143,8 @@ class Metric(object): aggregator = verif.aggregator.Mean() supports_aggregator = False type = verif.metric_type.Deterministic() + min_num_thresholds = None + max_num_thresholds = None def compute(self, data, input_index, axis, interval): """ Compute the score along an axis @@ -1216,6 +1218,8 @@ class QuantileCoverage(Metric): # default_bin_type = "within" require_threshold_type = "quantile" supports_threshold = True + min_num_thresholds = 1 + max_num_thresholds = 2 def compute_single(self, data, input_index, axis, axis_index, interval): var0 = verif.field.Quantile(interval.lower) @@ -1336,6 +1340,8 @@ class Spread(Metric): supports_threshold = True perfect_score = 0 orientation = -1 + min_num_thresholds = 2 + max_num_thresholds = 2 def compute_single(self, data, input_index, axis, axis_index, interval): var0 = verif.field.Quantile(interval.lower) @@ -1357,6 +1363,8 @@ class SpreadSkillRatio(Metric): supports_threshold = True perfect_score = 1 orientation = 0 + min_num_thresholds = 2 + max_num_thresholds = 2 def compute_single(self, data, input_index, axis, axis_index, interval): var0 = verif.field.Quantile(interval.lower)