mirror of
https://github.com/wassname/simpeg.git
synced 2026-09-09 11:34:26 +08:00
Migrated % string formating
This commit is contained in:
@@ -522,7 +522,7 @@ class BaseRectangularMesh(BaseMesh):
|
||||
assert xType in outType, 'You cannot change type of components.'
|
||||
if type(x) == list:
|
||||
for i, xi in enumerate(x):
|
||||
assert isinstance(x, np.ndarray), "x[%i] must be a numpy array" % i
|
||||
assert isinstance(x, np.ndarray), "x[{0:d}] must be a numpy array".format(i)
|
||||
assert xi.size == x[0].size, "Number of elements in list must not change."
|
||||
|
||||
x_array = np.ones((x.size, len(x)))
|
||||
|
||||
@@ -49,8 +49,8 @@ class CurvilinearMesh(BaseRectangularMesh, DiffOperators, InnerProducts,
|
||||
assert len(nodes) > 1, "len(node) must be greater than 1"
|
||||
|
||||
for i, nodes_i in enumerate(nodes):
|
||||
assert isinstance(nodes_i, np.ndarray), ("nodes[%i] is not a numpy array." % i)
|
||||
assert nodes_i.shape == nodes[0].shape, ("nodes[%i] is not the same shape as nodes[0]" % i)
|
||||
assert isinstance(nodes_i, np.ndarray), ("nodes[{0:d}] is not a numpy array.".format(i))
|
||||
assert nodes_i.shape == nodes[0].shape, ("nodes[{0:d}] is not the same shape as nodes[0]".format(i))
|
||||
|
||||
assert len(nodes[0].shape) == len(nodes), "Dimension mismatch"
|
||||
assert len(nodes[0].shape) > 1, "Not worth using Curv for a 1D mesh."
|
||||
|
||||
@@ -421,7 +421,7 @@ class InnerProducts(object):
|
||||
def _getEdgePx(M):
|
||||
"""Returns a function for creating projection matrices"""
|
||||
def Px(xEdge):
|
||||
assert xEdge == 'eX0', 'xEdge = %s, not eX0' % xEdge
|
||||
assert xEdge == 'eX0', 'xEdge = {0!s}, not eX0'.format(xEdge)
|
||||
return sp.identity(M.nC)
|
||||
return Px
|
||||
|
||||
|
||||
@@ -198,11 +198,11 @@ class TensorMeshIO(object):
|
||||
"""
|
||||
assert mesh.dim == 3
|
||||
s = ''
|
||||
s += '%i %i %i\n' %tuple(mesh.vnC)
|
||||
s += '{0:d} {1:d} {2:d}\n'.format(*tuple(mesh.vnC))
|
||||
origin = mesh.x0 + np.array([0,0,mesh.hz.sum()]) # Have to it in the same operation or use mesh.x0.copy(), otherwise the mesh.x0 is updated.
|
||||
origin.dtype = float
|
||||
|
||||
s += '%.2f %.2f %.2f\n' %tuple(origin)
|
||||
s += '{0:.2f} {1:.2f} {2:.2f}\n'.format(*tuple(origin))
|
||||
s += ('%.2f '*mesh.nCx+'\n')%tuple(mesh.hx)
|
||||
s += ('%.2f '*mesh.nCy+'\n')%tuple(mesh.hy)
|
||||
s += ('%.2f '*mesh.nCz+'\n')%tuple(mesh.hz[::-1])
|
||||
|
||||
@@ -23,8 +23,8 @@ class BaseTensorMesh(BaseMesh):
|
||||
h_i = self._unitDimensions[i] * np.ones(int(h_i))/int(h_i)
|
||||
elif type(h_i) is list:
|
||||
h_i = Utils.meshTensor(h_i)
|
||||
assert isinstance(h_i, np.ndarray), ("h[%i] is not a numpy array." % i)
|
||||
assert len(h_i.shape) == 1, ("h[%i] must be a 1D numpy array." % i)
|
||||
assert isinstance(h_i, np.ndarray), ("h[{0:d}] is not a numpy array.".format(i))
|
||||
assert len(h_i.shape) == 1, ("h[{0:d}] must be a 1D numpy array.".format(i))
|
||||
h[i] = h_i[:] # make a copy.
|
||||
|
||||
x0 = np.zeros(len(h))
|
||||
@@ -41,7 +41,7 @@ class BaseTensorMesh(BaseMesh):
|
||||
elif x_i == 'N':
|
||||
x0[i] = -h_i.sum()
|
||||
else:
|
||||
raise Exception("x0[%i] must be a scalar or '0' to be zero, 'C' to center, or 'N' to be negative." % i)
|
||||
raise Exception("x0[{0:d}] must be a scalar or '0' to be zero, 'C' to center, or 'N' to be negative.".format(i))
|
||||
|
||||
if isinstance(self, BaseRectangularMesh):
|
||||
BaseRectangularMesh.__init__(self, np.array([x.size for x in h]), x0)
|
||||
@@ -239,7 +239,7 @@ class BaseTensorMesh(BaseMesh):
|
||||
'CCVz' -> z-component of vector field defined on cell centers
|
||||
"""
|
||||
if self._meshType == 'CYL' and self.isSymmetric and locType in ['Ex','Ez','Fy']:
|
||||
raise Exception('Symmetric CylMesh does not support %s interpolation, as this variable does not exist.' % locType)
|
||||
raise Exception('Symmetric CylMesh does not support {0!s} interpolation, as this variable does not exist.'.format(locType))
|
||||
|
||||
loc = Utils.asArray_N_x_Dim(loc, self.dim)
|
||||
|
||||
|
||||
@@ -177,7 +177,7 @@ class TreeMesh(BaseTensorMesh, InnerProducts, TreeMeshIO):
|
||||
return l
|
||||
|
||||
def __str__(self):
|
||||
outStr = ' ---- %sTreeMesh ---- '%('Oc' if self.dim == 3 else 'Quad')
|
||||
outStr = ' ---- {0!s}TreeMesh ---- '.format(('Oc' if self.dim == 3 else 'Quad'))
|
||||
def printH(hx, outStr=''):
|
||||
i = -1
|
||||
while True:
|
||||
@@ -213,7 +213,7 @@ class TreeMesh(BaseTensorMesh, InnerProducts, TreeMeshIO):
|
||||
outStr += printH(self.hy, outStr='\n hy:')
|
||||
outStr += printH(self.hz, outStr='\n hz:')
|
||||
outStr += '\n nC: {0:d}'.format(self.nC)
|
||||
outStr += '\n Fill: %2.2f%%'%(self.fill*100)
|
||||
outStr += '\n Fill: {0:2.2f}%'.format((self.fill*100))
|
||||
return outStr
|
||||
|
||||
@property
|
||||
@@ -2210,7 +2210,7 @@ class TreeMesh(BaseTensorMesh, InnerProducts, TreeMeshIO):
|
||||
|
||||
ax.set_xlabel('y' if normal == 'X' else 'x')
|
||||
ax.set_ylabel('y' if normal == 'Z' else 'z')
|
||||
ax.set_title('Slice %d, %s = %4.2f' % (ind,normal,indLoc))
|
||||
ax.set_title('Slice {0:d}, {1!s} = {2:4.2f}'.format(ind, normal, indLoc))
|
||||
|
||||
if grid:
|
||||
_ = antiNormalInd
|
||||
@@ -2240,7 +2240,7 @@ class TreeMesh(BaseTensorMesh, InnerProducts, TreeMeshIO):
|
||||
if key < 0 : #Handle negative indices
|
||||
key += len( self )
|
||||
if key >= len( self ) :
|
||||
raise IndexError, "The index (%d) is out of range."%key
|
||||
raise IndexError, "The index ({0:d}) is out of range.".format(key)
|
||||
|
||||
self._numberCells() # no-op if numbered
|
||||
index = self._i2cc[key]
|
||||
|
||||
+8
-8
@@ -171,7 +171,7 @@ class TensorView(object):
|
||||
iz = ix + iy*nX
|
||||
if iz < self.nCz:
|
||||
ax.text((ix+1)*(self.vectorNx[-1]-self.x0[0])-pad,(iy)*(self.vectorNy[-1]-self.x0[1])+pad,
|
||||
'#%i'%iz,color=annotationColor,verticalalignment='bottom',horizontalalignment='right',size='x-large')
|
||||
'#{0:d}'.format(iz),color=annotationColor,verticalalignment='bottom',horizontalalignment='right',size='x-large')
|
||||
|
||||
ax.set_title(vType)
|
||||
if showIt: plt.show()
|
||||
@@ -221,10 +221,10 @@ class TensorView(object):
|
||||
vTypeOpts = ['CC', 'CCv','N','F','E','Fx','Fy','Fz','E','Ex','Ey','Ez']
|
||||
|
||||
# Some user error checking
|
||||
assert vType in vTypeOpts, "vType must be in ['%s']" % "','".join(vTypeOpts)
|
||||
assert vType in vTypeOpts, "vType must be in ['{0!s}']".format("','".join(vTypeOpts))
|
||||
assert self.dim == 3, 'Must be a 3D mesh. Use plotImage.'
|
||||
assert view in viewOpts, "view must be in ['%s']" % "','".join(viewOpts)
|
||||
assert normal in normalOpts, "normal must be in ['%s']" % "','".join(normalOpts)
|
||||
assert view in viewOpts, "view must be in ['{0!s}']".format("','".join(viewOpts))
|
||||
assert normal in normalOpts, "normal must be in ['{0!s}']".format("','".join(normalOpts))
|
||||
assert type(grid) is bool, 'grid must be a boolean'
|
||||
|
||||
szSliceDim = getattr(self, 'nC'+normal.lower()) #: Size of the sliced dimension
|
||||
@@ -295,7 +295,7 @@ class TensorView(object):
|
||||
|
||||
ax.set_xlabel('y' if normal == 'X' else 'x')
|
||||
ax.set_ylabel('y' if normal == 'Z' else 'z')
|
||||
ax.set_title('Slice %d' % ind)
|
||||
ax.set_title('Slice {0:d}'.format(ind))
|
||||
return out
|
||||
|
||||
|
||||
@@ -316,11 +316,11 @@ class TensorView(object):
|
||||
vTypeOptsV = ['CCv','F','E']
|
||||
vTypeOpts = vTypeOptsCC + vTypeOptsV
|
||||
if view == 'vec':
|
||||
assert vType in vTypeOptsV, "vType must be in ['%s'] when view='vec'" % "','".join(vTypeOptsV)
|
||||
assert vType in vTypeOpts, "vType must be in ['%s']" % "','".join(vTypeOpts)
|
||||
assert vType in vTypeOptsV, "vType must be in ['{0!s}'] when view='vec'".format("','".join(vTypeOptsV))
|
||||
assert vType in vTypeOpts, "vType must be in ['{0!s}']".format("','".join(vTypeOpts))
|
||||
|
||||
viewOpts = ['real','imag','abs','vec']
|
||||
assert view in viewOpts, "view must be in ['%s']" % "','".join(viewOpts)
|
||||
assert view in viewOpts, "view must be in ['{0!s}']".format("','".join(viewOpts))
|
||||
|
||||
|
||||
if ax is None:
|
||||
|
||||
Reference in New Issue
Block a user