Exemplo n.º 1
0
def test_interpolateArray():
    data = np.array([[1., 2., 4.], [10., 20., 40.], [100., 200., 400.]])

    x = np.array([[0.3, 0.6], [1., 1.], [0.5, 1.], [0.5, 2.5], [10., 10.]])

    result = pg.interpolateArray(data, x)

    #import scipy.ndimage
    #spresult = scipy.ndimage.map_coordinates(data, x.T, order=1)
    spresult = np.array([5.92, 20., 11., 0.,
                         0.])  # generated with the above line

    assert_array_almost_equal(result, spresult)

    # test mapping when x.shape[-1] < data.ndim
    x = np.array([[0.3, 0], [0.3, 1], [0.3, 2]])

    r1 = pg.interpolateArray(data, x)
    r2 = pg.interpolateArray(data, x[0, :1])
    assert_array_almost_equal(r1, r2)

    # test mapping 2D array of locations
    x = np.array([[[0.5, 0.5], [0.5, 1.0], [0.5, 1.5]],
                  [[1.5, 0.5], [1.5, 1.0], [1.5, 1.5]]])

    r1 = pg.interpolateArray(data, x)
    #r2 = scipy.ndimage.map_coordinates(data, x.transpose(2,0,1), order=1)
    r2 = np.array([
        [8.25, 11., 16.5],  # generated with the above line
        [82.5, 110., 165.]
    ])

    assert_array_almost_equal(r1, r2)
Exemplo n.º 2
0
def test_interpolateArray():
    data = np.array([[ 1.,   2.,   4.  ],
                     [ 10.,  20.,  40. ],
                     [ 100., 200., 400.]])
    
    x = np.array([[  0.3,   0.6],
                  [  1. ,   1. ],
                  [  0.5,   1. ],
                  [  0.5,   2.5],
                  [ 10. ,  10. ]])
    
    result = pg.interpolateArray(data, x)
    
    #import scipy.ndimage
    #spresult = scipy.ndimage.map_coordinates(data, x.T, order=1)
    spresult = np.array([  5.92,  20.  ,  11.  ,   0.  ,   0.  ])  # generated with the above line
    
    assert_array_almost_equal(result, spresult)
    
    # test mapping when x.shape[-1] < data.ndim
    x = np.array([[  0.3,   0],
                  [  0.3,   1],
                  [  0.3,   2]])
    
    r1 = pg.interpolateArray(data, x)
    r2 = pg.interpolateArray(data, x[0,:1])
    assert_array_almost_equal(r1, r2)
    
    
    # test mapping 2D array of locations
    x = np.array([[[0.5, 0.5], [0.5, 1.0], [0.5, 1.5]],
                  [[1.5, 0.5], [1.5, 1.0], [1.5, 1.5]]])
    
    r1 = pg.interpolateArray(data, x)
    #r2 = scipy.ndimage.map_coordinates(data, x.transpose(2,0,1), order=1)
    r2 = np.array([[   8.25,   11.  ,   16.5 ],  # generated with the above line
                   [  82.5 ,  110.  ,  165.  ]])

    assert_array_almost_equal(r1, r2)
Exemplo n.º 3
0
 def interpolateArray(data, x):
     result = pg.interpolateArray(data, x, order=order)
     assert result.shape == x.shape[:-1] + data.shape[x.shape[-1]:]
     return result
Exemplo n.º 4
0
 def interpolateArray(data, x):
     result = pg.interpolateArray(data, x, order=order)
     assert result.shape == x.shape[:-1] + data.shape[x.shape[-1]:]
     return result