Ejemplo n.º 1
0
def tnflux3d(U, V, T, strm, lon, lat, lev, xdim, ydim, zdim,
             cyclic=True, limit=100, punit=100.):
    """
    Takaya & Nakamura (2001) 计算等压面上的波活动度.
    Takaya, K and H. Nakamura, 2001: A formulation of a phase-independent
      wave-activity flux for stationary and migratory quasigeostrophic eddies
      on a zonally varying basic flow, `JAS`, 58, 608-627.
    http://journals.ametsoc.org/doi/abs/10.1175/1520-0469%282001%29058%3C0608%3AAFOAPI%3E2.0.CO%3B2

    :param U: u component wind [m/s].
    :param V: v component wind [m/s].
    :param T: climate temperature [K].
    :param strm: stream function bias [m^2/s]
    :param lon: longitude degree.
    :param lat: latitude degree.
    :param lev: level pressure.
    :param xdim: longitude dimension index.
    :param ydim: latitude dimension index.
    :param zdim: level dimension index.
    :param cyclic: east-west cyclic boundary.
    :param limit:
    :param punit: level pressure unit.
    :return: east-west, south-north, vertical component.
    """

    U, V, T = np.asarray(U), np.asarray(V), np.asarray(T)
    ndim = U.ndim
    S = stability(T, lev, zdim, punit=punit)
    f = arr.expand(constants.earth_f(lat), ndim, axis=ydim)

    dstrmdx = dvardx(strm, lon, lat, xdim, ydim, cyclic=cyclic)
    dstrmdy = dvardy(strm, lat, ydim)
    dstrmdp = dvardp(strm, lev, zdim, punit=punit)
    d2strmdx2 = d2vardx2(strm, lon, lat, xdim, ydim, cyclic=cyclic)
    d2strmdy2 = d2vardy2(strm, lat, ydim)
    d2strmdxdy = dvardy(dstrmdx, lat, ydim)
    d2strmdxdp = dvardx(dstrmdp, lon, lat, xdim, ydim, cyclic=True)
    d2strmdydp = dvardy(dstrmdp, lat, ydim)

    tnx = U * (dstrmdx ** 2 - strm * d2strmdx2) + \
        V * (dstrmdx * dstrmdy - strm * d2strmdxdy)
    tny = U * (dstrmdx * dstrmdy - strm * d2strmdxdy) + \
        V * (dstrmdy ** 2 - strm * d2strmdy2)
    tnz = f ** 2 / S ** 2 * (
        U * (dstrmdx * dstrmdp - strm * d2strmdxdp) -
        V * (dstrmdy * dstrmdp - strm * d2strmdydp))

    tnx = 0.5 * tnx / np.abs(U + 1j * V)
    tny = 0.5 * tny / np.abs(U + 1j * V)

    tnxy = np.sqrt(tnx ** 2 + tny ** 2)
    tnx = np.ma.asarray(tnx)
    tny = np.ma.asarray(tny)
    tnz = np.ma.asarray(tnz)
    tnx[(U < 0) | (tnxy > limit)] = np.ma.masked
    tny[(U < 0) | (tnxy > limit)] = np.ma.masked
    tnz[(U < 0) | (tnxy > limit)] = np.ma.masked

    return tnx, tny, tnz
Ejemplo n.º 2
0
def tnflux2d(U, V, strm, lon, lat, xdim, ydim, cyclic=True, limit=100):
    """
    Takaya & Nakamura (2001) 计算水平等压面上的波活动度.
    Takaya, K and H. Nakamura, 2001: A formulation of a phase-independent
      wave-activity flux for stationary and migratory quasigeostrophic eddies
      on a zonally varying basic flow, `JAS`, 58, 608-627.
    http://journals.ametsoc.org/doi/abs/10.1175/1520-0469%282001%29058%3C0608%3AAFOAPI%3E2.0.CO%3B2

    :param U: u component wind [m/s].
    :param V: v component wind [m/s].
    :param strm: stream function [m^2/s].
    :param lon: longitude degree.
    :param lat: latitude degree.
    :param xdim: longitude dimension index.
    :param ydim: latitude dimension index.
    :param cyclic: east-west cyclic boundary.
    :param limit:
    :return:
    """

    U, V = np.asarray(U), np.asarray(V)
    ndim = U.ndim

    dstrmdx = dvardx(strm, lon, lat, xdim, ydim, cyclic=cyclic)
    dstrmdy = dvardy(strm, lat, ydim)
    d2strmdx2 = d2vardx2(strm, lon, lat, xdim, ydim, cyclic=cyclic)
    d2strmdy2 = d2vardy2(strm, lat, ydim)
    d2strmdxdy = dvardy(
        dvardx(strm, lon, lat, xdim, ydim, cyclic=cyclic),
        lat, ydim)

    tnx = U * (dstrmdx ** 2 - strm * d2strmdx2) + \
        V * (dstrmdx * dstrmdy - strm * d2strmdxdy)
    tny = U * (dstrmdx * dstrmdy - strm * d2strmdxdy) + \
        V * (dstrmdy ** 2 - strm * d2strmdy2)

    tnx = 0.5 * tnx / np.abs(U + 1j * V)
    tny = 0.5 * tny / np.abs(U + 1j * V)

    tnxy = np.sqrt(tnx ** 2 + tny ** 2)
    tnx = np.ma.asarray(tnx)
    tny = np.ma.asarray(tny)
    tnx[tnxy > limit] = np.ma.masked
    tny[tnxy > limit] = np.ma.masked
    tnx[U < 0] = np.ma.masked
    tny[U < 0] = np.ma.masked

    return tnx, tny