Skip to content

Commit

Permalink
Changed scipy version check to try/except, issue #74
Browse files Browse the repository at this point in the history
  • Loading branch information
rapoliveira committed Dec 14, 2023
1 parent 35f76ac commit 8e879bb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions data/interpolate_elliptic_integral_3.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ def get_ellip(x, y):
add_y = []
p = get_ellip(x, y)

if scipy.__version__ >= "1.9.0":
interp_p = RGI((x, y), p, method='cubic', bounds_error=False)
else:
interp_p = interp2d(x, y, p.T, kind='cubic')
try:
interp_p = RGI((x, y), p, method="cubic", bounds_error=False)
except ValueError:
interp_p = interp2d(x, y, p.T, kind="cubic")

check_x = []
for i in range(len(x)-1):
Expand All @@ -66,7 +66,7 @@ def get_ellip(x, y):
cond = np.array(check_y) > cx
check_p[ix, cond] = 1.
check_true_p[ix, cond] = 1.
if scipy.__version__ >= "1.9.0":
if isinstance(interp_p, RGI):
check_p[ix, ~cond] = interp_p((cx, np.array(check_y)[~cond]))
else:
check_p[ix, ~cond] = interp_p(cx, np.array(check_y)[~cond]).T[0]
Expand Down
6 changes: 3 additions & 3 deletions source/MulensModel/pointlens.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ def _read_elliptic_files(self):
yy = np.array([float(t) for t in line.split()[2:]])
pp = np.loadtxt(file_3)

if scipy.__version__ >= "1.9.0":
try:
PointLens._interpolate_3 = RGI((xx, yy), pp, method='cubic',
bounds_error=False)
else:
except ValueError:
PointLens._interpolate_3 = interp2d(xx, yy, pp.T, kind='cubic')
PointLens._interpolate_3_min_x = np.min(xx)
PointLens._interpolate_3_max_x = np.max(xx)
Expand Down Expand Up @@ -602,7 +602,7 @@ def _get_ellip3(self, n, k):
cond_4 = (k <= PointLens._interpolate_3_max_y)

if cond_1 and cond_2 and cond_3 and cond_4:
if scipy.__version__ >= "1.9.0":
if isinstance(PointLens._interpolate_3, RGI):
return float(PointLens._interpolate_3((n, k)).T)
else:
return PointLens._interpolate_3(n, k)[0]
Expand Down

0 comments on commit 8e879bb

Please sign in to comment.