Skip to content

Commit

Permalink
AMAROC-681 catch GMM test corner case
Browse files Browse the repository at this point in the history
  • Loading branch information
regDaniel committed Nov 10, 2023
1 parent 5d0fcbc commit f46e5da
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/ampycloud/layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -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
)
Expand Down

0 comments on commit f46e5da

Please sign in to comment.