mirror of
https://github.com/wassname/simpeg.git
synced 2026-07-06 05:16:51 +08:00
Fix and test interpolation. Issue #43
This commit is contained in:
@@ -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
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user