add future warnings for new map names to ensure backwards compatibility (for a time)

This commit is contained in:
Lindsey Heagy
2016-02-17 14:32:49 -08:00
parent 20f7f9be1d
commit a5be262171
2 changed files with 62 additions and 24 deletions
+33
View File
@@ -4,6 +4,7 @@ from Tests import checkDerivative
from PropMaps import PropMap, Property from PropMaps import PropMap, Property
from numpy.polynomial import polynomial from numpy.polynomial import polynomial
from scipy.interpolate import UnivariateSpline from scipy.interpolate import UnivariateSpline
import warnings
class IdentityMap(object): class IdentityMap(object):
""" """
@@ -327,6 +328,12 @@ class SurjectFull(IdentityMap):
""" """
return np.ones([self.mesh.nC,1]) return np.ones([self.mesh.nC,1])
class FullMap(SurjectFull):
def __init__(self,mesh,**kwargs):
warnings.warn(
"`FullMap` is deprecated and will be removed in future versions. Use `SurjectFull` instead",
FutureWarning)
SurjectFull.__init__(self,mesh,**kwargs)
class SurjectVertical1D(IdentityMap): class SurjectVertical1D(IdentityMap):
"""SurjectVertical1DMap """SurjectVertical1DMap
@@ -369,6 +376,12 @@ class SurjectVertical1D(IdentityMap):
), shape=(repNum, 1)) ), shape=(repNum, 1))
return sp.kron(sp.identity(self.nP), repVec) return sp.kron(sp.identity(self.nP), repVec)
class Vertical1DMap(SurjectVertical1D):
def __init__(self,mesh,**kwargs):
warnings.warn(
"`Vertical1DMap` is deprecated and will be removed in future versions. Use `SurjectVertical1D` instead",
FutureWarning)
SurjectVertical1D.__init__(self,mesh,**kwargs)
class Surject2Dto3D(IdentityMap): class Surject2Dto3D(IdentityMap):
"""Map2Dto3D """Map2Dto3D
@@ -425,6 +438,13 @@ class Surject2Dto3D(IdentityMap):
), shape=(nC, nP)) ), shape=(nC, nP))
return P return P
class Map2Dto3D(Surject2Dto3D):
def __init__(self,mesh,**kwargs):
warnings.warn(
"`Map2Dto3D` is deprecated and will be removed in future versions. Use `Surject2Dto3D` instead",
FutureWarning)
Surject2Dto3D.__init__(self,mesh,**kwargs)
class Mesh2Mesh(IdentityMap): class Mesh2Mesh(IdentityMap):
""" """
Takes a model on one mesh are translates it to another mesh. Takes a model on one mesh are translates it to another mesh.
@@ -506,6 +526,13 @@ class InjectActiveCells(IdentityMap):
def deriv(self, m): def deriv(self, m):
return self.P return self.P
class ActiveCells(InjectActiveCells):
def __init__(self, mesh, indActive, valInactive, nC=None):
warnings.warn(
"`ActiveCells` is deprecated and will be removed in future versions. Use `InjectActiveCells` instead",
FutureWarning)
InjectActiveCells.__init__(self, mesh, indActive, valInactive, nC)
class InjectActiveCellsTopo(IdentityMap): class InjectActiveCellsTopo(IdentityMap):
""" """
Active model parameters. Extend for cells on topography to air cell (only works for tensor mesh) Active model parameters. Extend for cells on topography to air cell (only works for tensor mesh)
@@ -577,6 +604,12 @@ class InjectActiveCellsTopo(IdentityMap):
def deriv(self, m): def deriv(self, m):
return self.P return self.P
class ActiveCellsTopo(InjectActiveCellsTopo):
def __init__(self, mesh, indActive, valInactive, nC=None):
warnings.warn(
"`ActiveCellsTopo` is deprecated and will be removed in future versions. Use `InjectActiveCellsTopo` instead",
FutureWarning)
InjectActiveCellsTopo.__init__(self, mesh, indActive, valInactive, nC)
class Weighting(IdentityMap): class Weighting(IdentityMap):
""" """
+29 -24
View File
@@ -5,8 +5,8 @@ from scipy.sparse.linalg import dsolve
TOL = 1e-14 TOL = 1e-14
MAPS_TO_TEST_2D = ["CircleMap", "ComplexMap", "ExpMap", "IdentityMap", "SurjectVertical1D", "Weighting", "SurjectFull"] MAPS_TO_TEST_2D = ["CircleMap", "ComplexMap", "ExpMap", "IdentityMap", "SurjectVertical1D", "Weighting", "SurjectFull","FullMap","Vertical1DMap"]
MAPS_TO_TEST_3D = [ "ComplexMap", "ExpMap", "IdentityMap", "SurjectVertical1D", "Weighting", "SurjectFull"] MAPS_TO_TEST_3D = [ "ComplexMap", "ExpMap", "IdentityMap", "SurjectVertical1D", "Weighting", "SurjectFull","FullMap","Vertical1DMap"]
class MapTests(unittest.TestCase): class MapTests(unittest.TestCase):
@@ -83,16 +83,17 @@ class MapTests(unittest.TestCase):
def test_activeCells(self): def test_activeCells(self):
M = Mesh.TensorMesh([2,4],'0C') M = Mesh.TensorMesh([2,4],'0C')
expMap = Maps.ExpMap(M) expMap = Maps.ExpMap(M)
actMap = Maps.InjectActiveCells(M, M.vectorCCy <=0, 10, nC=M.nCy) for actMap in [Maps.InjectActiveCells(M, M.vectorCCy <=0, 10, nC=M.nCy), Maps.ActiveCells(M, M.vectorCCy <=0, 10, nC=M.nCy)]:
vertMap = Maps.SurjectVertical1D(M) # actMap = Maps.InjectActiveCells(M, M.vectorCCy <=0, 10, nC=M.nCy)
combo = vertMap * actMap vertMap = Maps.SurjectVertical1D(M)
m = np.r_[1,2.] combo = vertMap * actMap
mod = Models.Model(m,combo) m = np.r_[1,2.]
# import matplotlib.pyplot as plt mod = Models.Model(m,combo)
# plt.colorbar(M.plotImage(mod.transform)[0]) # import matplotlib.pyplot as plt
# plt.show() # plt.colorbar(M.plotImage(mod.transform)[0])
self.assertLess(np.linalg.norm(mod.transform - np.r_[1,1,2,2,10,10,10,10.]), TOL) # plt.show()
self.assertLess((mod.transformDeriv - combo.deriv(m)).toarray().sum(), TOL) self.assertLess(np.linalg.norm(mod.transform - np.r_[1,1,2,2,10,10,10,10.]), TOL)
self.assertLess((mod.transformDeriv - combo.deriv(m)).toarray().sum(), TOL)
def test_tripleMultiply(self): def test_tripleMultiply(self):
M = Mesh.TensorMesh([2,4],'0C') M = Mesh.TensorMesh([2,4],'0C')
@@ -115,29 +116,33 @@ class MapTests(unittest.TestCase):
M2 = Mesh.TensorMesh([2,4]) M2 = Mesh.TensorMesh([2,4])
M3 = Mesh.TensorMesh([3,2,4]) M3 = Mesh.TensorMesh([3,2,4])
m = np.random.rand(M2.nC) m = np.random.rand(M2.nC)
m2to3 = Maps.Surject2Dto3D(M3, normal='X')
m = np.arange(m2to3.nP) for m2to3 in [Maps.Surject2Dto3D(M3, normal='X'), Maps.Map2Dto3D(M3, normal='X')]:
self.assertTrue(m2to3.test()) # m2to3 = Maps.Surject2Dto3D(M3, normal='X')
self.assertTrue(np.all(Utils.mkvc( (m2to3 * m).reshape(M3.vnC,order='F')[0,:,:] ) == m)) m = np.arange(m2to3.nP)
self.assertTrue(m2to3.test())
self.assertTrue(np.all(Utils.mkvc( (m2to3 * m).reshape(M3.vnC,order='F')[0,:,:] ) == m))
def test_map2Dto3D_y(self): def test_map2Dto3D_y(self):
M2 = Mesh.TensorMesh([3,4]) M2 = Mesh.TensorMesh([3,4])
M3 = Mesh.TensorMesh([3,2,4]) M3 = Mesh.TensorMesh([3,2,4])
m = np.random.rand(M2.nC) m = np.random.rand(M2.nC)
m2to3 = Maps.Surject2Dto3D(M3, normal='Y') for m2to3 in [Maps.Surject2Dto3D(M3, normal='Y'),Maps.Map2Dto3D(M3, normal='Y')]:
m = np.arange(m2to3.nP) # m2to3 = Maps.Surject2Dto3D(M3, normal='Y')
self.assertTrue(m2to3.test()) m = np.arange(m2to3.nP)
self.assertTrue(np.all(Utils.mkvc( (m2to3 * m).reshape(M3.vnC,order='F')[:,0,:] ) == m)) self.assertTrue(m2to3.test())
self.assertTrue(np.all(Utils.mkvc( (m2to3 * m).reshape(M3.vnC,order='F')[:,0,:] ) == m))
def test_map2Dto3D_z(self): def test_map2Dto3D_z(self):
M2 = Mesh.TensorMesh([3,2]) M2 = Mesh.TensorMesh([3,2])
M3 = Mesh.TensorMesh([3,2,4]) M3 = Mesh.TensorMesh([3,2,4])
m = np.random.rand(M2.nC) m = np.random.rand(M2.nC)
m2to3 = Maps.Surject2Dto3D(M3, normal='Z') for m2to3 in [Maps.Surject2Dto3D(M3, normal='Z'),Maps.Map2Dto3D(M3, normal='Z')]:
m = np.arange(m2to3.nP) # m2to3 = Maps.Surject2Dto3D(M3, normal='Z')
self.assertTrue(m2to3.test()) m = np.arange(m2to3.nP)
self.assertTrue(np.all(Utils.mkvc( (m2to3 * m).reshape(M3.vnC,order='F')[:,:,0] ) == m)) self.assertTrue(m2to3.test())
self.assertTrue(np.all(Utils.mkvc( (m2to3 * m).reshape(M3.vnC,order='F')[:,:,0] ) == m))
if __name__ == '__main__': if __name__ == '__main__':