From f46e5da3980d3786f6207bd710b1e4500904d586 Mon Sep 17 00:00:00 2001 From: Daniel Regenass Date: Fri, 10 Nov 2023 10:04:40 +0100 Subject: [PATCH] AMAROC-681 catch GMM test corner case --- src/ampycloud/layer.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/ampycloud/layer.py b/src/ampycloud/layer.py index d436eb6..d91f585 100644 --- a/src/ampycloud/layer.py +++ b/src/ampycloud/layer.py @@ -191,6 +191,9 @@ def ncomp_from_gmm(vals: np.ndarray, if len(np.unique(vals_orig)) == 1: logger.debug('Skipping the GMM computation: all the values are the same.') return (1, np.zeros(len(vals_orig)), None) + elif len(np.unique(vals_orig)) < ncomp_max: + ncomp_max = len(np.unique(vals_orig)) + warnings.warn(f'Restricting ncomp_max to the max number of individual values: {ncomp_max}') # Estimate the resolution of the data (by measuring the minimum separation between two data # points). @@ -248,7 +251,7 @@ def _calc_base_alt(vals, lookback_perc, alt_perc): ] n_largest_elements = vals[n_largest_idxs] if len(n_largest_elements) == 0: - warnings.warn( + raise ValueError( 'Cloud base calculation got an empty array.' 'Maybe check lookback percentage (is set to %i)' %lookback_perc )