當前位置: 首頁>>代碼示例>>Python>>正文


Python Vector.execute方法代碼示例

本文整理匯總了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)
開發者ID:KeithLatteri,項目名稱:awips2,代碼行數:48,代碼來源:DeformationComponent.py

示例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
開發者ID:KeithLatteri,項目名稱:awips2,代碼行數:21,代碼來源:Derivative.py

示例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
開發者ID:KeithLatteri,項目名稱:awips2,代碼行數:44,代碼來源:GeoWind.py

示例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)
開發者ID:KeithLatteri,項目名稱:awips2,代碼行數:39,代碼來源:Gradient.py


注:本文中的Vector.execute方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。