awips2/cave/com.raytheon.uf.viz.derivparam.python/localization/derivedParameters/functions/PotVortMB.py
root 9f19e3f712 Initial revision of AWIPS2 11.9.0-7p5
Former-commit-id: 64fa9254b946eae7e61bbc3f513b7c3696c4f54f
2012-01-06 08:55:05 -06:00

78 lines
2.7 KiB
Python

##
# This software was developed and / or modified by Raytheon Company,
# pursuant to Contract DG133W-05-CQ-1067 with the US Government.
#
# U.S. EXPORT CONTROLLED TECHNICAL DATA
# This software product contains export-restricted data whose
# export/transfer/disclosure is restricted by U.S. law. Dissemination
# to non-U.S. persons whether in the United States or abroad requires
# an export license or other authorization.
#
# Contractor Name: Raytheon Company
# Contractor Address: 6825 Pine Street, Suite 340
# Mail Stop B8
# Omaha, NE 68106
# 402.291.0100
#
# See the AWIPS II Master Rights File ("Master Rights File.pdf") for
# further licensing information.
###
from numpy import zeros
import Gradient
import Vorticity
##
# Calculate the isobaric potential vorticity through a layer.
#
# User Notes:
#
# 1. Stability is defined as -dP/d(theta). We calculate this through
# the layer from the isobaric surface 'n' to the surface above it,
# 'n+1'.
# 2. Since we are dealing with a layer, we calculate a mean absolute
# vorticity using the winds at the upper and lower layers.
# 3. The PV is then [mean abs. vort]/[stability] + theta->pres term
#
# originally from pvpres.f, by J.Ramer
# @change: Converted from Fortran on 2008-16-06
#
# @param t_up: Theta on upper isobaric sfc (K)
# @param t:lo: Theta on this isobaric sfc (K)
# @param p_up: Upper pressure (mb)
# @param p_lo: This (lower) pressure (mb)
# @param Wind_up: tuple(U,V) winds on upper surface (m/s)
# @param Wind_lo: tuple(U,V) winds on lower surface (m/s)
# @param dx: Spacing in X direction (m)
# @param dy: Spacing in Y direction (m)
# @param coriolis: Coriolis parameters (/s)
# @return: Isobaric potential vorticity
# @rtype: numpy array
def execute(t_up, t_lo, p_up, p_lo, vector_up, vector_lo, dx, dy, coriolis):
""
u_up, v_up = vector_up[2], vector_up[3]
u_lo, v_lo = vector_lo[2], vector_lo[3]
# Calculate the absolute vorticity at each isobaric surface.
avort1 = Vorticity.execute(u_up, v_up, coriolis, dx, dy)
avort2 = Vorticity.execute(u_lo, v_lo, coriolis, dx, dy)
# Calculate the temperature gradient on each surface.
grad_lo = Gradient.execute(t_lo, dx, dy)
grad_up = Gradient.execute(t_up, dx, dy)
dtdx1, dtdy1 = grad_lo[2], grad_lo[3]
dtdx2, dtdy2 = grad_up[2], grad_up[3]
# Calculate difference arrays.
dp = p_up - p_lo
dt = t_up - t_lo
du = u_up - u_lo
dv = v_up - v_lo
dtdx = dtdx1 + dtdx2
dtdy = dtdy1 + dtdy2
av = avort1 + avort2
result = (-0.5 * (av*dt + (du*dtdy - dv*dtdx)) / dp)*.5
return result