本文整理汇总了Python中Vector.execute方法的典型用法代码示例。如果您正苦于以下问题:Python Vector.execute方法的具体用法?Python Vector.execute怎么用?Python Vector.execute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vector
的用法示例。
在下文中一共展示了Vector.execute方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: execute
# 需要导入模块: import Vector [as 别名]
# 或者: from Vector import execute [as 别名]
def execute(U, V, dx, dy):
# create an empty array the same dimensions as U
resultx = empty(U.shape, U.dtype)
resulty = empty(U.shape, U.dtype)
# flag edges as invalid
resultx[0,:] = NaN
resultx[-1,:] = NaN
resultx[1:-1,0] = NaN
resultx[1:-1,-1] = NaN
resulty[0,:] = NaN
resulty[-1,:] = NaN
resulty[1:-1,0] = NaN
resulty[1:-1,-1] = NaN
# strip off edges of dx if it's not a scalar
shapedx = shape(dx)
if len(shapedx) < sum(shapedx):
dx = dx[1:-1,1:-1]
# strip off edges of dy if it's not a scalar
shapedy = shape(dy)
if len(shapedy) < sum(shapedy):
dy = dy[1:-1,1:-1]
# Calculate deformation vector components.
qqq = 0.5/dx
www = 0.5/dy
dst = (U[1:-1,0:-2] - U[1:-1,2:]) * qqq
dst += (V[0:-2,1:-1] - V[2:,1:-1]) * www
dsh = (U[0:-2,1:-1] - U[2:,1:-1]) * qqq
dsh += (V[1:-1,2:] - V[1:-1,0:-2]) * www
qqq = dst*dst + dsh*dsh
www = sqrt(qqq)
ans = sqrt((qqq+www*dst)/2)
Q = where(ans != 0.0, www*dsh/(2*ans), www)
# put ans in the valid block of result
resultx[1:-1,1:-1] = Q
resulty[1:-1,1:-1] = ans
return Vector.execute(resultx,resulty)
示例2: execute
# 需要导入模块: import Vector [as 别名]
# 或者: from Vector import execute [as 别名]
def execute(A0, A1, B0, B1):
"Calculate the derivative of A with respect to B."
if isinstance(A0, tuple):
# Do derivitive of components of the vector
u0 = A0[2]
v0 = A0[3]
u1 = A1[2]
v1 = A1[3]
uDeriv = execute(u0, u1, B0, B1)
vDeriv = execute(v0, v1, B0, B1)
return Vector.execute(uDeriv, vDeriv)
Adiff = A1-A0
Bdiff = B1-B0
result = Adiff / Bdiff
return result
示例3: execute
# 需要导入模块: import Vector [as 别名]
# 或者: from Vector import execute [as 别名]
def execute(Height, dx, dy, coriolis):
""
# assume dx, dy, and coriolis are OK
# Because we're using the adjacent points to calculate the result, we can't
# find values for points along the edges. Since we never use any points of
# dx, dy, and coriolis except the middle block, redefine them as the slice
# we actually use. This also allows us to deal with scalars.
if not isscalar(dx):
dx = dx[1:-1, 1:-1]
if not isscalar(dy):
dy = dy[1:-1, 1:-1]
if not isscalar(coriolis):
coriolis = coriolis[1:-1, 1:-1]
# Create the cropped answer arrays.
ans_V = Height[1:-1,2:] - Height[1:-1, 0:-2]
ans_V *= g
ans_V /= 2 * dy * coriolis
ans_U = Height[2:, 1:-1] - Height[0:-2, 1:-1]
ans_U *= g
ans_U /= 2 * dx * coriolis
# Create full-sized result arrays with all cells masked.
result_U = Height + NaN
result_V = Height + NaN
# Paste the cropped arrays into the valid portion of the answer arrays.
result_U[1:-1, 1:-1] = ans_U
result_V[1:-1, 1:-1] = ans_V
# Any masked cells become NaN
# This includes the outer edges and any cells that used a masked
# value from Height.
result_U = result_U
result_V = result_V
result = Vector.execute(result_U, result_V)
return result
示例4: execute
# 需要导入模块: import Vector [as 别名]
# 或者: from Vector import execute [as 别名]
def execute(scalar, dx, dy):
"Calculate the 2D gradient arrays of a 2+D scalar array."
result_u = empty(shape(scalar), dtype=scalar.dtype)
result_v = empty(shape(scalar), dtype=scalar.dtype)
# Left/rt edges of result_u can't be calculated.
result_u[:,0] = NaN
result_u[:,-1] = NaN
# Top/bot edges of result_v can't be calculated.
result_v[0,:] = NaN
result_v[-1,:] = NaN
# If dx and dy are arrays, remove extra cells.
shapedx = shape(dx)
if len(shapedx) < sum(shapedx):
dx = dx[:,1:-1]
shapedy = shape(dy)
if len(shapedy) < sum(shapedy):
dy = dy[1:-1,:]
# assume dx and dy are never zero
# dx = masked_values(dx, 0.0, copy=False)
# dy = masked_values(dy, 0.0, copy=False)
# calculate d(scalar)/dx
ans_u = scalar[:,2:] - scalar[:,0:-2]
ans_u = ans_u/(2 * dx)
# calculate d(scalar)/dy
ans_v = scalar[0:-2,:] - scalar[2:,:]
ans_v = ans_v/(2 * dy)
result_u[:,1:-1] = ans_u
result_v[1:-1,:] = ans_v
return Vector.execute(result_u, result_v)