-
Notifications
You must be signed in to change notification settings - Fork 54
/
interp_test.py
43 lines (30 loc) · 1.11 KB
/
interp_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# -*- coding: utf-8 -*-
import numpy as np
from scipy.interpolate import (
RegularGridInterpolator as SpRegularGridInterpolator,
)
from exoplanet.interp import RegularGridInterpolator
def test_basic():
def f(x, y, z):
return 2 * x ** 3 + 3 * y ** 2 - z
x = np.linspace(1, 4, 11)
y = np.linspace(4, 7, 22)
z = np.linspace(7, 9, 33)
data = f(*np.meshgrid(x, y, z, indexing="ij", sparse=True))
interpolator = SpRegularGridInterpolator((x, y, z), data)
pts = np.array([[2.1, 6.2, 8.3], [3.3, 5.2, 7.1]])
f0 = interpolator(pts)
op = RegularGridInterpolator((x, y, z), data)
f = np.squeeze(op.evaluate(pts).eval())
assert np.allclose(f, f0)
def test_fill_value():
def f(x, y, z):
return 2 * x ** 3 + 3 * y ** 2 - z
x = np.linspace(1, 4, 11)
y = np.linspace(4, 7, 22)
z = np.linspace(7, 9, 33)
data = f(*np.meshgrid(x, y, z, indexing="ij", sparse=True))
pts = np.array([[0.1, 6.2, 8.3], [3.3, 5.2, 10.1]])
op = RegularGridInterpolator((x, y, z), data, fill_value=np.nan)
f = op.evaluate(pts).eval()
assert np.all(np.isnan(f))