Fix and test interpolation. Issue #43

This commit is contained in:
rowanc1
2014-02-20 10:06:10 -08:00
parent 9f2c976be1
commit 361fb719f0
2 changed files with 26 additions and 16 deletions
+16
View File
@@ -2,6 +2,9 @@ import numpy as np
import unittest
from TestUtils import OrderTest
from SimPEG.Utils import mkvc
from SimPEG import Mesh
import unittest
MESHTYPES = ['uniformTensorMesh', 'randomTensorMesh']
TOLERANCES = [0.9, 0.5]
@@ -50,6 +53,19 @@ class TestInterpolation1D(OrderTest):
self.name = 'Interpolation 1D: N'
self.orderTest()
class TestOutliersInterp1D(unittest.TestCase):
def setUp(self):
pass
def test_outliers(self):
M = Mesh.TensorMesh([4])
Q = M.getInterpolationMat(np.array([[0],[0.126],[0.127]]),'CC',zerosOutside=True)
x = np.arange(4)+1
self.assertTrue(np.all(Q*x == [1,1.004,1.008]))
Q = M.getInterpolationMat(np.array([[-1],[0.126],[0.127]]),'CC',zerosOutside=True)
self.assertTrue(np.all(Q*x == [0,1.004,1.008]))
class TestInterpolation2d(OrderTest):
name = "Interpolation 2D"
LOCS = np.random.rand(50,2)*0.6+0.2
+10 -16
View File
@@ -178,19 +178,13 @@ def _interpmat3D(locs, x, y, z):
if __name__ == '__main__':
from SimPEG import *
import matplotlib.pyplot as plt
M = Mesh.TensorMesh([4])
M.vectorCCx
Q = M.getInterpolationMat(np.array([[0],[0.126],[0.127]]),'CC',zerosOutside=True)
print Q.todense()
# locs = np.random.rand(50)*0.8+0.1
# x = np.linspace(0,1,7)
# dense = np.linspace(0,1,200)
# fun = lambda x: np.cos(2*np.pi*x)
# Q = Utils.interpmat(locs, x)
# plt.plot(x, fun(x), 'bs-')
# plt.plot(dense, fun(dense), 'y:')
# plt.plot(locs, Q*fun(x), 'mo')
# plt.plot(locs, fun(locs), 'rx')
# plt.show()
locs = np.random.rand(50)*0.8+0.1
x = np.linspace(0,1,7)
dense = np.linspace(0,1,200)
fun = lambda x: np.cos(2*np.pi*x)
Q = Utils.interpmat(locs, x)
plt.plot(x, fun(x), 'bs-')
plt.plot(dense, fun(dense), 'y:')
plt.plot(locs, Q*fun(x), 'mo')
plt.plot(locs, fun(locs), 'rx')
plt.show()