From 1c140b3cbf33ecff993c3930b5be4dd15e3f892f Mon Sep 17 00:00:00 2001 From: arjunsavel Date: Wed, 5 Mar 2025 10:23:49 -0500 Subject: [PATCH] add numerical hygiene --- src/scope/broadening.py | 10 ++++++---- src/scope/rm_effect.py | 4 +++- src/scope/utils.py | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/scope/broadening.py b/src/scope/broadening.py index 98b544f..4035bce 100644 --- a/src/scope/broadening.py +++ b/src/scope/broadening.py @@ -212,10 +212,12 @@ def I_darken_disk(x, y, epsilon): ------- :res1: the intensity at that point on the disk. """ - lon = np.arcsin(x) - lat = np.arcsin(y) - - return I_darken(lon, lat, epsilon) + if x**2 + y**2 <= 1: + lon = np.arcsin(x) + lat = np.arcsin(y) + return I_darken(lon, lat, epsilon) + else: + return 0.0 def I_darken_disk_integrated(x, y, epsilon): diff --git a/src/scope/rm_effect.py b/src/scope/rm_effect.py index f86760d..f5bb9b2 100644 --- a/src/scope/rm_effect.py +++ b/src/scope/rm_effect.py @@ -135,7 +135,9 @@ def occult_grid(occulted_grid, grid, planet_location, r_p): theta2 = planet_location[1] # calculate the distance between the planet and the grid points - r = np.sqrt(r1**2 + r2**2 - 2 * r1 * r2 * np.cos(theta1 - theta2)) + r = np.sqrt( + np.clip(r1**2 + r2**2 - 2 * r1 * r2 * np.cos(theta1 - theta2), 0, None) + ) # find the points where the planet is planet_points = np.where(r <= r_p) diff --git a/src/scope/utils.py b/src/scope/utils.py index efde534..2c3e1f2 100644 --- a/src/scope/utils.py +++ b/src/scope/utils.py @@ -180,7 +180,7 @@ def calc_limb_darkening(u1, u2, a, b, Rstar, ph, LD): """ if LD: # apply limb darkening. 1D style! x = (a * np.sin(2 * np.pi * ph)) / (Rstar * rsun) - mu = np.sqrt(1 - x**2 - b**2) + mu = np.sqrt(np.clip(1 - x**2 - b**2, 0, 1)) if x**2 <= 1 - b**2: I = 1 - u1 * (1 - mu) - u2 * (1 - mu) ** 2 else: