From 7e1578877bbf5c1009868bb5665b17cccb5acd17 Mon Sep 17 00:00:00 2001 From: Jakob Bottcher Date: Thu, 19 Dec 2024 05:07:05 -0600 Subject: [PATCH] Throw useful error if density evaluation resulted only in nans or infs --- MCEq/geometry/density_profiles.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/MCEq/geometry/density_profiles.py b/MCEq/geometry/density_profiles.py index 0783d86..d6c7ea9 100644 --- a/MCEq/geometry/density_profiles.py +++ b/MCEq/geometry/density_profiles.py @@ -86,7 +86,12 @@ def calculate_density_spline(self, n_steps=2000): # Calculate integral for each depth point rho_l = vec_rho_l(dl_vec) - X_int = cumtrapz(rho_l[np.isfinite(rho_l)], dl_vec[np.isfinite(rho_l)]) + if np.sum(np.isfinite(rho_l)) >= 1: + X_int = cumtrapz(rho_l[np.isfinite(rho_l)], + dl_vec[np.isfinite(rho_l)]) + else: + raise Exception("No finite density values found" + " in the density spline evaluation.") dl_vec = dl_vec[np.isfinite(rho_l)][1:] info(5, ".. took {0:1.2f}s".format(time() - now))