Skip to content

Commit df9a16a

Browse files
committed
Small improvements to input checks. In particular, the warnings for single-scattering albedo
(`omega_arr`) and phase function Legendre coefficients (`Leg_coeffs`) being past their respective soft caps now takes into account delta-scaling.
1 parent 51b8efc commit df9a16a

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

src/PythonicDISORT/pydisort.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,6 @@ def pydisort(
226226
# Single-scattering albedo must be between 0 and 1, excluding 1
227227
if not (np.all(omega_arr >= 0) and np.all(omega_arr < 1)):
228228
raise ValueError("Single-scattering albedo must be between 0 and 1, excluding 1.")
229-
if np.any(omega_arr > 1 - 1e-6):
230-
warnings.warn("Some single-scattering albedos are very close to 1 which may cause numerical instability.")
231229
# There must be a positive number of Legendre coefficients each with magnitude <= 1
232230
# The user must supply at least as many phase function Legendre coefficients as intended for use
233231
if not NLeg > 0:
@@ -249,8 +247,6 @@ def pydisort(
249247
Leg_coeffs_all[:, 0] = 1
250248
if not (np.all(-1 <= Leg_coeffs_all) and np.all(Leg_coeffs_all <= 1)):
251249
raise ValueError("The phase function Legendre coefficients must all be between -1 and 1.")
252-
if (np.any(-0.95 > Leg_coeffs_all[:, 1:]) and np.any(Leg_coeffs_all[:, 1:] > 0.95)):
253-
warnings.warn("Some phase function Legendre coefficients have a magnitude that is very close to 1 (this excludes the zeroth index coefficient which must be 1) and this may cause numerical instability.")
254250
# Conditions on the number of quadrature angles (NQuad), Legendre coefficients (NLeg) and loops (NFourier)
255251
if not NQuad >= 2:
256252
raise ValueError("There must be at least two streams.")
@@ -321,9 +317,8 @@ def pydisort(
321317
scale_tau = 1 - omega_arr * f_arr
322318
scaled_thickness_arr = scale_tau * thickness_arr
323319
scaled_tau_arr_with_0 = np.insert(np.cumsum(scaled_thickness_arr), 0, 0)
324-
weighted_scaled_Leg_coeffs = ((Leg_coeffs - f_arr[:, None]) / (1 - f_arr[:, None])) * (
325-
2 * np.arange(NLeg) + 1
326-
)[None, :]
320+
scaled_Leg_coeffs = (Leg_coeffs - f_arr[:, None]) / (1 - f_arr[:, None])
321+
weighted_scaled_Leg_coeffs = scaled_Leg_coeffs * (2 * np.arange(NLeg) + 1)[None, :]
327322
scaled_omega_arr = (1 - f_arr) / scale_tau * omega_arr
328323

329324
translations = scaled_tau_arr_with_0[:-1] - scale_tau * np.insert(tau_arr[:-1], 0, 0)
@@ -336,9 +331,17 @@ def pydisort(
336331
# This is a shortcut to the same results
337332
scale_tau = np.ones(NLayers)
338333
scaled_tau_arr_with_0 = np.insert(tau_arr, 0, 0)
339-
weighted_scaled_Leg_coeffs = Leg_coeffs * (2 * np.arange(NLeg) + 1)[None, :]
334+
scaled_Leg_coeffs = Leg_coeffs
335+
weighted_scaled_Leg_coeffs = scaled_Leg_coeffs * (2 * np.arange(NLeg) + 1)[None, :]
340336
scaled_omega_arr = omega_arr
341337
scaled_s_poly_coeffs = s_poly_coeffs
338+
339+
if np.any(scaled_omega_arr > 1 - 1e-6):
340+
warnings.warn("Some delta-scaled single-scattering albedos are very close to 1 which may cause numerical instability.")
341+
if (np.any(-0.95 > scaled_Leg_coeffs[:, 1:]) and np.any(scaled_Leg_coeffs[:, 1:] > 0.95)):
342+
warnings.warn("Some delta-scaled phase function Legendre coefficients have a magnitude that is very close to 1" +
343+
" (this excludes the zeroth index coefficient which must be 1) and this may cause numerical instability.")
344+
342345
# --------------------------------------------------------------------------------------------------------------------------
343346

344347
# Rescale of sources

0 commit comments

Comments
 (0)