From 8e879bbe9e336cdb8081c095c993979cb8b6f837 Mon Sep 17 00:00:00 2001 From: "Raphael A. P. Oliveira" Date: Thu, 14 Dec 2023 19:54:16 +0100 Subject: [PATCH] Changed scipy version check to try/except, issue #74 --- data/interpolate_elliptic_integral_3.py | 10 +++++----- source/MulensModel/pointlens.py | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/data/interpolate_elliptic_integral_3.py b/data/interpolate_elliptic_integral_3.py index 1eb8d105..86e77c8c 100644 --- a/data/interpolate_elliptic_integral_3.py +++ b/data/interpolate_elliptic_integral_3.py @@ -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): @@ -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] diff --git a/source/MulensModel/pointlens.py b/source/MulensModel/pointlens.py index b084e336..eb541465 100644 --- a/source/MulensModel/pointlens.py +++ b/source/MulensModel/pointlens.py @@ -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) @@ -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]