def get_pmf(self, point):
     """Produces an ODF from a SH bootstrap sample"""
     where_dwi = self.where_dwi
     bootdata = trilinear_interpolate4d(self.data, point)
     dwidata = bootdata[where_dwi]
     dwidata = shm.bootstrap_data_voxel(dwidata, self.H, self.R)
     bootdata[where_dwi] = dwidata
     fit = self.model.fit(bootdata)
     return fit.odf(self.sphere)
Exemplo n.º 2
0
def test_trilinear_interpolate():

    a, b, c = np.random.random(3)

    def linear_function(x, y, z):
        return a * x + b * y + c * z

    N = 6
    x, y, z = np.mgrid[:N, :N, :N]
    data = np.empty((N, N, N, 2))
    data[..., 0] = linear_function(x, y, z)
    data[..., 1] = 99.

    # Use a point not near the edges
    point = np.array([2.1, 4.8, 3.3])
    out = trilinear_interpolate4d(data, point)
    expected = [linear_function(*point), 99.]
    npt.assert_array_almost_equal(out, expected)

    # Pass in out ourselves
    out[:] = -1
    trilinear_interpolate4d(data, point, out)
    npt.assert_array_almost_equal(out, expected)

    # use a point close to an edge
    point = np.array([-.1, -.1, -.1])
    expected = [0., 99.]
    out = trilinear_interpolate4d(data, point)
    npt.assert_array_almost_equal(out, expected)

    # different edge
    point = np.array([2.4, 5.4, 3.3])
    # On the edge 5.4 get treated as the max y value, 5.
    expected = [linear_function(point[0], 5., point[2]), 99.]
    out = trilinear_interpolate4d(data, point)
    npt.assert_array_almost_equal(out, expected)

    # Test index errors
    point = np.array([2.4, 5.5, 3.3])
    npt.assert_raises(IndexError, trilinear_interpolate4d, data, point)
    point = np.array([2.4, -1., 3.3])
    npt.assert_raises(IndexError, trilinear_interpolate4d, data, point)
Exemplo n.º 3
0
def test_trilinear_interpolate():

    a, b, c = np.random.random(3)

    def linear_function(x, y, z):
        return a * x + b * y + c * z

    N = 6
    x, y, z = np.mgrid[:N, :N, :N]
    data = np.empty((N, N, N, 2))
    data[..., 0] = linear_function(x, y, z)
    data[..., 1] = 99.

    # Use a point not near the edges
    point = np.array([2.1, 4.8, 3.3])
    out = trilinear_interpolate4d(data, point)
    expected = [linear_function(*point), 99.]
    npt.assert_array_almost_equal(out, expected)

    # Pass in out ourselves
    out[:] = -1
    trilinear_interpolate4d(data, point, out)
    npt.assert_array_almost_equal(out, expected)

    # use a point close to an edge
    point = np.array([-.1, -.1, -.1])
    expected = [0., 99.]
    out = trilinear_interpolate4d(data, point)
    npt.assert_array_almost_equal(out, expected)

    # different edge
    point = np.array([2.4, 5.4, 3.3])
    # On the edge 5.4 get treated as the max y value, 5.
    expected = [linear_function(point[0], 5., point[2]), 99.]
    out = trilinear_interpolate4d(data, point)
    npt.assert_array_almost_equal(out, expected)

    # Test index errors
    point = np.array([2.4, 5.5, 3.3])
    npt.assert_raises(IndexError, trilinear_interpolate4d, data, point)
    point = np.array([2.4, -1., 3.3])
    npt.assert_raises(IndexError, trilinear_interpolate4d, data, point)
Exemplo n.º 4
0
 def get_pmf(self, point):
     coeff = trilinear_interpolate4d(self.shcoeff, point)
     pmf = np.dot(self._B, coeff)
     pmf.clip(0, out=pmf)
     return pmf
Exemplo n.º 5
0
 def get_pmf(self, point):
     return trilinear_interpolate4d(self.pmf_array, point)
Exemplo n.º 6
0
 def get_pmf(self, point):
     coeff = trilinear_interpolate4d(self.shcoeff, point)
     pmf = np.dot(self._B, coeff)
     pmf.clip(0, out=pmf)
     return pmf
Exemplo n.º 7
0
 def get_pmf(self, point):
     return trilinear_interpolate4d(self.pmf_array, point)
Exemplo n.º 8
0
 def pmf_no_boot(self, point):
     data = trilinear_interpolate4d(self.data, point)
     fit = self.model.fit(data)
     return fit.odf(self.sphere)