From 5d0fcbc16b993d2c2a785098b45696b2694a2f88 Mon Sep 17 00:00:00 2001 From: Daniel Regenass Date: Thu, 9 Nov 2023 17:37:56 +0100 Subject: [PATCH] AMAROC-681 handle empty array in cloud base calc --- src/ampycloud/layer.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/ampycloud/layer.py b/src/ampycloud/layer.py index a53ff11..d436eb6 100644 --- a/src/ampycloud/layer.py +++ b/src/ampycloud/layer.py @@ -247,9 +247,12 @@ def _calc_base_alt(vals, lookback_perc, alt_perc): - int(len(vals) * lookback_perc / 100): ] n_largest_elements = vals[n_largest_idxs] - print("NLARGEST") - print(n_largest_elements) - print(vals) + if len(n_largest_elements) == 0: + warnings.warn( + 'Cloud base calculation got an empty array.' + 'Maybe check lookback percentage (is set to %i)' %lookback_perc + ) + return np.nan return np.percentile(n_largest_elements, alt_perc) mean_comp_heights = [