From 2330ae4ec185e07accdbc26d710e9d5552b07071 Mon Sep 17 00:00:00 2001 From: Rowan Cockett Date: Fri, 30 Aug 2013 23:51:58 -0700 Subject: [PATCH] upgraded documentation. Added plots to docs. --- SimPEG/BaseMesh.py | 175 +++++++++++++----- SimPEG/TensorView.py | 22 ++- .../mesh/{plot_grid.py => plot_grid_2D.py} | 3 +- docs/examples/mesh/plot_grid_3D.py | 12 ++ docs/index.rst | 4 +- 5 files changed, 159 insertions(+), 57 deletions(-) rename docs/examples/mesh/{plot_grid.py => plot_grid_2D.py} (77%) create mode 100644 docs/examples/mesh/plot_grid_3D.py diff --git a/SimPEG/BaseMesh.py b/SimPEG/BaseMesh.py index fd799dea..c57828e9 100644 --- a/SimPEG/BaseMesh.py +++ b/SimPEG/BaseMesh.py @@ -3,31 +3,12 @@ from utils import mkvc class BaseMesh(object): - """BaseMesh does all the counting you don't want to do. + """ + BaseMesh does all the counting you don't want to do. + BaseMesh should be inherited by meshes with a regular structure. - x0 origin ndarray (dim, ) - n number of cells ndarray (dim, ) - dim dimension of mesh int 1, 2, or 3 - - nCx num cells in x dir int - nCy num cells in y dir int - nCz num cells in z dir int - nC total number of cells int - - nNx num nodes in x dir int - nNy num nodes in y dir int - nNz num nodes in z dir int - nN total number of nodes int - - nEx num edges in x dir ndarray [nEx_x, nEx_y, nEx_z] - nEy num edges in y dir ndarray [nEy_x, nEy_y, nEy_z] - nEz num edges in z dir ndarray [nEz_x, nEz_y, nEz_z] - nE total number of edges ndarray (dim, ) - - nFx num faces in x dir ndarray [nFx_x, nFx_y, nFx_z] - nFy num faces in y dir ndarray [nFy_x, nFy_y, nFy_z] - nFz num faces in z dir ndarray [nFz_x, nFz_y, nFz_z] - nF total number of faces ndarray (dim, ) + :param numpy.array,list n: number of cells in each direction (dim, ) + :param numpy.array,list x0: Origin of the mesh (dim, ) """ def __init__(self, n, x0=None): @@ -48,7 +29,12 @@ class BaseMesh(object): self._dim = len(n) def x0(): - doc = "Origin of the mesh" + doc = """ + Origin of the mesh + + :rtype: numpy.array (dim, ) + :return: x0 + """ fget = lambda self: self._x0 return locals() x0 = property(**x0()) @@ -161,25 +147,45 @@ class BaseMesh(object): return switchKernal(x) def n(): - doc = "Number of Cells in each dimension (array of integers)" + doc = """ + Number of Cells in each dimension (array of integers) + + :rtype: numpy.array + :return: n + """ fget = lambda self: self._n return locals() n = property(**n()) def dim(): - doc = "The dimension of the mesh (1, 2, or 3)." + doc = """ + The dimension of the mesh (1, 2, or 3). + + :rtype: int + :return: dim + """ fget = lambda self: self._dim return locals() dim = property(**dim()) def nCx(): - doc = "Number oc cells in the x direction" + doc = """ + Number of cells in the x direction + + :rtype: int + :return: nCx + """ fget = lambda self: self.n[0] return locals() nCx = property(**nCx()) def nCy(): - doc = "Number of cells in the y direction" + doc = """ + Number of cells in the y direction + + :rtype: int + :return: nCy or None if dim < 2 + """ def fget(self): if self.dim > 1: @@ -190,7 +196,11 @@ class BaseMesh(object): nCy = property(**nCy()) def nCz(): - doc = "Number of cells in the z direction" + doc = """Number of cells in the z direction + + :rtype: int + :return: nCz or None if dim < 3 + """ def fget(self): if self.dim > 2: @@ -201,19 +211,34 @@ class BaseMesh(object): nCz = property(**nCz()) def nC(): - doc = "Total number of cells" + doc = """ + Total number of cells in the model. + + :rtype: int + :return: nC + """ fget = lambda self: np.prod(self.n) return locals() nC = property(**nC()) def nNx(): - doc = "Number of nodes in the x-direction" + doc = """ + Number of nodes in the x-direction + + :rtype: int + :return: nNx + """ fget = lambda self: self.nCx + 1 return locals() nNx = property(**nNx()) def nNy(): - doc = "Number of noes in the y-direction" + doc = """ + Number of noes in the y-direction + + :rtype: int + :return: nNy or None if dim < 2 + """ def fget(self): if self.dim > 1: @@ -224,7 +249,12 @@ class BaseMesh(object): nNy = property(**nNy()) def nNz(): - doc = "Number of nodes in the z-direction" + doc = """ + Number of nodes in the z-direction + + :rtype: int + :return: nNz or None if dim < 3 + """ def fget(self): if self.dim > 2: @@ -235,19 +265,34 @@ class BaseMesh(object): nNz = property(**nNz()) def nN(): - doc = "Total number of nodes" + doc = """ + Total number of nodes + + :rtype: int + :return: nN + """ fget = lambda self: np.prod(self.n + 1) return locals() nN = property(**nN()) def nEx(): - doc = "Number of x-edges" + doc = """ + Number of x-edges in each direction + + :rtype: numpy.array (dim, ) + :return: nEx + """ fget = lambda self: np.array([x for x in [self.nCx, self.nNy, self.nNz] if not x is None]) return locals() nEx = property(**nEx()) def nEy(): - doc = "Number of y-edges" + doc = """ + Number of y-edges in each direction + + :rtype: numpy.array (dim, ) + :return: nEy or None if dim < 2 + """ def fget(self): if self.dim > 1: @@ -258,7 +303,12 @@ class BaseMesh(object): nEy = property(**nEy()) def nEz(): - doc = "Number of z-edges" + doc = """ + Number of z-edges in each direction + + :rtype: numpy.array (dim, ) + :return: nEz or None if dim < 3 + """ def fget(self): if self.dim > 2: @@ -269,19 +319,34 @@ class BaseMesh(object): nEz = property(**nEz()) def nE(): - doc = "Total number of edges" + doc = """ + Total number of edges in each direction + + :rtype: numpy.array (dim, ) + :return: [prod(nEx), prod(nEy), prod(nEz)] + """ fget = lambda self: np.array([np.prod(x) for x in [self.nEx, self.nEy, self.nEz] if not x is None]) return locals() nE = property(**nE()) def nFx(): - doc = "Number of x-faces" + doc = """ + Number of x-faces in each direction + + :rtype: numpy.array (dim, ) + :return: nFx + """ fget = lambda self: np.array([x for x in [self.nNx, self.nCy, self.nCz] if not x is None]) return locals() nFx = property(**nFx()) def nFy(): - doc = "Number of y-faces" + doc = """ + Number of y-faces in each direction + + :rtype: numpy.array (dim, ) + :return: nFy or None if dim < 2 + """ def fget(self): if self.dim > 1: @@ -292,7 +357,12 @@ class BaseMesh(object): nFy = property(**nFy()) def nFz(): - doc = "Number of z-faces" + doc = """ + Number of z-faces in each direction + + :rtype: numpy.array (dim, ) + :return: nFz or None if dim < 3 + """ def fget(self): if self.dim > 2: @@ -303,13 +373,23 @@ class BaseMesh(object): nFz = property(**nFz()) def nF(): - doc = "Total number of faces in each dimension" + doc = """ + Total number of faces in each direction + + :rtype: numpy.array (dim, ) + :return: [prod(nFx), prod(nFy), prod(nFz)] + """ fget = lambda self: np.array([np.prod(x) for x in [self.nFx, self.nFy, self.nFz] if not x is None]) return locals() nF = property(**nF()) def normals(): - doc = "Face Normals" + doc = """ + Face Normals + + :rtype: numpy.array (sum(nF), dim) + :return: normals + """ def fget(self): if self.dim == 2: @@ -325,7 +405,12 @@ class BaseMesh(object): normals = property(**normals()) def tangents(): - doc = "Edge Tangents" + doc = """ + Edge Tangents + + :rtype: numpy.array (sum(nE), dim) + :return: normals + """ def fget(self): if self.dim == 2: diff --git a/SimPEG/TensorView.py b/SimPEG/TensorView.py index 01cad4e4..3140bdd5 100644 --- a/SimPEG/TensorView.py +++ b/SimPEG/TensorView.py @@ -13,7 +13,7 @@ class TensorView(object): def __init__(self): pass - def plotImage(self, I, imageType='CC', figNum=1,ax=None,direction='z',numbering=True,annotationColor='w'): + def plotImage(self, I, imageType='CC', figNum=1,ax=None,direction='z',numbering=True,annotationColor='w',showIt=False): """ Mesh.plotImage(I) @@ -164,11 +164,19 @@ class TensorView(object): ax.text((ix+1)*self.vectorNx[-1]-pad,(iy)*self.vectorNy[-1]+pad, '#%i'%iz,color=annotationColor,verticalalignment='bottom',horizontalalignment='right',size='x-large') - plt.show() + if showIt: plt.show() return ph - def plotGrid(self): - """Plot the nodal, cell-centered and staggered grids for 1,2 and 3 dimensions.""" + def plotGrid(self, showIt=False): + """Plot the nodal, cell-centered and staggered grids for 1,2 and 3 dimensions. + + + .. plot:: examples/mesh/plot_grid_2D.py + :include-source: + + .. plot:: examples/mesh/plot_grid_3D.py + :include-source: + """ if self.dim == 1: fig = plt.figure(1) fig.clf() @@ -182,7 +190,7 @@ class TensorView(object): ax.grid(True) ax.hold(False) ax.set_xlabel('x1') - plt.show() + if showIt: plt.show() elif self.dim == 2: fig = plt.figure(2) fig.clf() @@ -201,7 +209,7 @@ class TensorView(object): ax.hold(False) ax.set_xlabel('x1') ax.set_ylabel('x2') - plt.show() + if showIt: plt.show() elif self.dim == 3: fig = plt.figure(3) fig.clf() @@ -230,4 +238,4 @@ class TensorView(object): ax.set_xlabel('x1') ax.set_ylabel('x2') ax.set_zlabel('x3') - plt.show() + if showIt: plt.show() diff --git a/docs/examples/mesh/plot_grid.py b/docs/examples/mesh/plot_grid_2D.py similarity index 77% rename from docs/examples/mesh/plot_grid.py rename to docs/examples/mesh/plot_grid_2D.py index 6eafb939..c53a8e02 100644 --- a/docs/examples/mesh/plot_grid.py +++ b/docs/examples/mesh/plot_grid_2D.py @@ -2,10 +2,9 @@ import numpy as np import matplotlib.pyplot as plt from SimPEG import TensorMesh -x0 = np.zeros(2) h1 = np.linspace(.1,.5,3) h2 = np.linspace(.1,.5,5) -mesh = TensorMesh([h1,h2],x0) +mesh = TensorMesh([h1, h2]) mesh.plotGrid() plt.show() diff --git a/docs/examples/mesh/plot_grid_3D.py b/docs/examples/mesh/plot_grid_3D.py new file mode 100644 index 00000000..8da62346 --- /dev/null +++ b/docs/examples/mesh/plot_grid_3D.py @@ -0,0 +1,12 @@ +import numpy as np +import matplotlib.pyplot as plt +from SimPEG import TensorMesh + +h1 = np.linspace(.1,.5,3) +h2 = np.linspace(.1,.5,5) +h3 = np.linspace(.1,.5,3) +mesh = TensorMesh([h1,h2,h3]) +mesh.plotGrid() + +plt.show() + diff --git a/docs/index.rst b/docs/index.rst index c30567cc..20998c3f 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -24,9 +24,7 @@ Contents api_BaseMesh api_TensorMesh - -.. plot:: examples/mesh/plot_grid.py - :include-source: + api_TensorView Project Index & Search