def test_out_of_bounds_extrap(self):
     points, values = self._get_sample_4d()
     sample = np.asarray([[-.1, -.1, -.1, -.1], [1.1, 1.1, 1.1, 1.1],
                          [21, 2.1, -1.1, -11], [2.1, 2.1, -1.1, -1.1]])
     interp = _RegularGridInterpolator(points, sample.T, method="nn")
     wanted = np.asarray([0., 1111., 11., 11.])
     assert_array_almost_equal(interp(values, fill_value=None), wanted)
     interp = _RegularGridInterpolator(points, sample.T, method="lin")
     wanted = np.asarray([-111.1, 1222.1, -11068., -1186.9])
     assert_array_almost_equal(interp(values, fill_value=None), wanted)
 def test_out_of_bounds_extrap(self):
     points, values = self._get_sample_4d()
     sample = np.asarray([[-.1, -.1, -.1, -.1], [1.1, 1.1, 1.1, 1.1],
                          [21, 2.1, -1.1, -11], [2.1, 2.1, -1.1, -1.1]])
     interp = _RegularGridInterpolator(points, sample.T, method="nn")
     wanted = np.asarray([0., 1111., 11., 11.])
     assert_array_almost_equal(interp(values, fill_value=None), wanted)
     interp = _RegularGridInterpolator(points, sample.T, method="lin")
     wanted = np.asarray([-111.1, 1222.1, -11068., -1186.9])
     assert_array_almost_equal(interp(values, fill_value=None), wanted)
    def test_complex(self):
        points, values = self._get_sample_4d()
        values = values - 2j*values
        sample = np.asarray([[0.1, 0.1, 1., .9], [0.2, 0.1, .45, .8], [0.5, 0.5, .5, .5]])

        for method in ['lin', 'nn']:
            interp = _RegularGridInterpolator(points, sample.T, method=method)
            rinterp = _RegularGridInterpolator(points, sample.real.T, method=method)
            iinterp = _RegularGridInterpolator(points, sample.imag.T, method=method)

            v1 = interp(values)
            v2 = rinterp(values) + 1j*iinterp(values)
            assert_allclose(v1, v2)
    def test_list_input(self):
        points, values = self._get_sample_4d()

        sample = np.asarray([[0.1, 0.1, 1., .9], [0.2, 0.1, .45, .8],
                                          [0.5, 0.5, .5, .5]])

        for method in ['lin', 'nn']:
            interp = _RegularGridInterpolator(points,
                                             sample.T.tolist(), method=method)
            v1 = interp(values.tolist())
            interp = _RegularGridInterpolator(points,
                                             sample.T, method=method)
            v2 = interp(values)
            assert_allclose(v1, v2)
    def test_list_input(self):
        points, values = self._get_sample_4d()

        sample = np.asarray([[0.1, 0.1, 1., .9], [0.2, 0.1, .45, .8],
                             [0.5, 0.5, .5, .5]])

        for method in ['lin', 'nn']:
            interp = _RegularGridInterpolator(points,
                                              sample.T.tolist(),
                                              method=method)
            v1 = interp(values.tolist())
            interp = _RegularGridInterpolator(points, sample.T, method=method)
            v2 = interp(values)
            assert_allclose(v1, v2)
 def test_linear_xi3d(self):
     points, values = self._get_sample_4d()
     sample = np.asarray([[0.1, 0.1, 1., .9], [0.2, 0.1, .45, .8],
                          [0.5, 0.5, .5, .5]])
     wanted = np.asarray([1001.1, 846.2, 555.5])
     interp = _RegularGridInterpolator(points, sample.T)
     assert_array_almost_equal(interp(values), wanted)
 def test_linear_xi3d(self):
     points, values = self._get_sample_4d()
     sample = np.asarray([[0.1, 0.1, 1., .9], [0.2, 0.1, .45, .8],
                                                  [0.5, 0.5, .5, .5]])
     wanted = np.asarray([1001.1, 846.2, 555.5])
     interp = _RegularGridInterpolator(points, sample.T)
     assert_array_almost_equal(interp(values), wanted)
 def test_fillvalue_type(self):
     # from #3703; test that interpolator object construction succeeds
     values = np.ones((10, 20, 30), dtype='>f4')
     points = [np.arange(n) for n in values.shape]
     xi = np.asarray([1, 1, 1])
     interpolator = _RegularGridInterpolator(points, xi.T)
     interpolator(values, fill_value=0.)
    def test_out_of_bounds_fill(self):
        points, values = self._get_sample_4d()

        sample = np.asarray([[-.1, -.1, -.1, -.1], [1.1, 1.1, 1.1, 1.1],
                             [2.1, 2.1, -1.1, -1.1]])
        interp = _RegularGridInterpolator(points, sample.T, method="nn")
        # Assert that all of the elements are masked
        assert all(interp(values, fill_value=np.nan).mask)
        interp = _RegularGridInterpolator(points, sample.T, method="lin")
        assert all(interp(values, fill_value=np.nan).mask)

        sample = np.asarray([[0.1, 0.1, 1., .9], [0.2, 0.1, .45, .8],
                             [0.5, 0.5, .5, .5]])
        wanted = np.asarray([1001.1, 846.2, 555.5])
        interp = _RegularGridInterpolator(points, sample.T)
        assert_array_almost_equal(interp(values, fill_value=np.nan), wanted)
    def test_out_of_bounds_fill(self):
        points, values = self._get_sample_4d()

        sample = np.asarray([[-.1, -.1, -.1, -.1], [1.1, 1.1, 1.1, 1.1],
                             [2.1, 2.1, -1.1, -1.1]])
        interp = _RegularGridInterpolator(points, sample.T, method="nn")
        # Assert that all of the elements are masked
        assert all(interp(values, fill_value=np.nan).mask)
        interp = _RegularGridInterpolator(points, sample.T, method="lin")
        assert all(interp(values, fill_value=np.nan).mask)

        sample = np.asarray([[0.1, 0.1, 1., .9], [0.2, 0.1, .45, .8],
                             [0.5, 0.5, .5, .5]])
        wanted = np.asarray([1001.1, 846.2, 555.5])
        interp = _RegularGridInterpolator(points, sample.T)
        assert_array_almost_equal(interp(values, fill_value=np.nan), wanted)
 def test_fillvalue_type(self):
     # from #3703; test that interpolator object construction succeeds
     values = np.ones((10, 20, 30), dtype='>f4')
     points = [np.arange(n) for n in values.shape]
     xi = np.asarray([1, 1, 1])
     interpolator = _RegularGridInterpolator(points, xi.T)
     interpolator(values, fill_value=0.)
 def test_valid_call(self):
     points, values = self._get_sample_4d()
     sample = np.asarray([[0., 0., 0., 0.], [1., 1., 1., 1.]])
     interp = _RegularGridInterpolator(points, sample.T)
     assert_raises(ValueError, interp, values, "undefmethod")
     # This is actually an error on creation now
     sample = np.asarray([[0., 0., 0.], [1., 1., 1.]])
     assert_raises(ValueError, _RegularGridInterpolator, points, sample)
 def test_valid_call(self):
     points, values = self._get_sample_4d()
     sample = np.asarray([[0., 0., 0., 0.], [1., 1., 1., 1.]])
     interp = _RegularGridInterpolator(points, sample.T)
     assert_raises(ValueError, interp, values, "undefmethod")
     # This is actually an error on creation now
     sample = np.asarray([[0., 0., 0.], [1., 1., 1.]])
     assert_raises(ValueError, _RegularGridInterpolator, points, sample)
    def test_complex(self):
        points, values = self._get_sample_4d()
        values = values - 2j * values
        sample = np.asarray([[0.1, 0.1, 1., .9], [0.2, 0.1, .45, .8],
                             [0.5, 0.5, .5, .5]])

        for method in ['lin', 'nn']:
            interp = _RegularGridInterpolator(points, sample.T, method=method)
            rinterp = _RegularGridInterpolator(points,
                                               sample.real.T,
                                               method=method)
            iinterp = _RegularGridInterpolator(points,
                                               sample.imag.T,
                                               method=method)

            v1 = interp(values)
            v2 = rinterp(values) + 1j * iinterp(values)
            assert_allclose(v1, v2)
 def test_linear_compare_qhull(self):
     points, values = self._get_sample_4d()
     sample = np.asarray([[0.1, 0.1, 1., .9], [0.2, 0.1, .45, .8],
                          [0.5, 0.5, .5, .5]])
     interp = _RegularGridInterpolator(points, sample.T)
     points_qhull = itertools.product(*points)
     points_qhull = [p for p in points_qhull]
     points_qhull = np.asarray(points_qhull)
     values_qhull = values.reshape(-1)
     interp_qhull = LinearNDInterpolator(points_qhull, values_qhull)
     assert_array_almost_equal(interp(values), interp_qhull(sample))
 def test_linear_compare_qhull(self):
     points, values = self._get_sample_4d()
     sample = np.asarray([[0.1, 0.1, 1., .9], [0.2, 0.1, .45, .8],
                          [0.5, 0.5, .5, .5]])
     interp = _RegularGridInterpolator(points, sample.T)
     points_qhull = itertools.product(*points)
     points_qhull = [p for p in points_qhull]
     points_qhull = np.asarray(points_qhull)
     values_qhull = values.reshape(-1)
     interp_qhull = LinearNDInterpolator(points_qhull, values_qhull)
     assert_array_almost_equal(interp(values), interp_qhull(sample))
    def test_invalid_fill_value(self):
        np.random.seed(1234)
        x = np.linspace(0, 2, 5)
        y = np.linspace(0, 1, 7)
        values = np.random.rand(5, 7)

        # integers can be cast to floats
        interp = _RegularGridInterpolator((x, y), [0.4, 0.7])
        interp(values, fill_value=1)

        # complex values cannot
        assert_raises(ValueError, interp, values, fill_value=1+2j)
    def test_invalid_fill_value(self):
        np.random.seed(1234)
        x = np.linspace(0, 2, 5)
        y = np.linspace(0, 1, 7)
        values = np.random.rand(5, 7)

        # integers can be cast to floats
        interp = _RegularGridInterpolator((x, y), [0.4, 0.7])
        interp(values, fill_value=1)

        # complex values cannot
        assert_raises(ValueError, interp, values, fill_value=1 + 2j)
 def test_nearest(self):
     points, values = self._get_sample_4d()
     sample = np.asarray([0.1, 0.1, .9, .9])
     wanted = 1100.
     interp = _RegularGridInterpolator(points, sample.T, method="nn")
     assert_array_almost_equal(interp(values), wanted)
     sample = np.asarray([0.1, 0.1, 0.1, 0.1])
     wanted = 0.
     interp = _RegularGridInterpolator(points, sample.T, method="nn")
     assert_array_almost_equal(interp(values), wanted)
     sample = np.asarray([0., 0., 0., 0.])
     wanted = 0.
     interp = _RegularGridInterpolator(points, sample.T, method="nn")
     assert_array_almost_equal(interp(values), wanted)
     sample = np.asarray([1., 1., 1., 1.])
     wanted = 1111.
     interp = _RegularGridInterpolator(points, sample.T, method="nn")
     assert_array_almost_equal(interp(values), wanted)
     sample = np.asarray([0.1, 0.4, 0.6, 0.9])
     wanted = 1055.
     interp = _RegularGridInterpolator(points, sample.T, method="nn")
     assert_array_almost_equal(interp(values), wanted)
 def test_nearest(self):
     points, values = self._get_sample_4d()
     sample = np.asarray([0.1, 0.1, .9, .9])
     wanted = 1100.
     interp = _RegularGridInterpolator(points, sample.T, method="nn")
     assert_array_almost_equal(interp(values), wanted)
     sample = np.asarray([0.1, 0.1, 0.1, 0.1])
     wanted = 0.
     interp = _RegularGridInterpolator(points, sample.T, method="nn")
     assert_array_almost_equal(interp(values), wanted)
     sample = np.asarray([0., 0., 0., 0.])
     wanted = 0.
     interp = _RegularGridInterpolator(points, sample.T, method="nn")
     assert_array_almost_equal(interp(values), wanted)
     sample = np.asarray([1., 1., 1., 1.])
     wanted = 1111.
     interp = _RegularGridInterpolator(points, sample.T, method="nn")
     assert_array_almost_equal(interp(values), wanted)
     sample = np.asarray([0.1, 0.4, 0.6, 0.9])
     wanted = 1055.
     interp = _RegularGridInterpolator(points, sample.T, method="nn")
     assert_array_almost_equal(interp(values), wanted)
 def test_linear_edges(self):
     points, values = self._get_sample_4d()
     sample = np.asarray([[0., 0., 0., 0.], [1., 1., 1., 1.]])
     wanted = np.asarray([0., 1111.])
     interp = _RegularGridInterpolator(points, sample.T)
     assert_array_almost_equal(interp(values), wanted)
 def test_linear_xi1d(self):
     points, values = self._get_sample_4d_2()
     sample = np.asarray([0.1, 0.1, 10., 9.])
     wanted = 1001.1
     interp = _RegularGridInterpolator(points, sample.T)
     assert_array_almost_equal(interp(values), wanted)
 def test_linear_xi1d(self):
     points, values = self._get_sample_4d_2()
     sample = np.asarray([0.1, 0.1, 10., 9.])
     wanted = 1001.1
     interp = _RegularGridInterpolator(points, sample.T)
     assert_array_almost_equal(interp(values), wanted)
 def test_linear_edges(self):
     points, values = self._get_sample_4d()
     sample = np.asarray([[0., 0., 0., 0.], [1., 1., 1., 1.]])
     wanted = np.asarray([0., 1111.])
     interp = _RegularGridInterpolator(points, sample.T)
     assert_array_almost_equal(interp(values), wanted)