Exemplo n.º 1
0
mon = ds['mon'].values

topo = dat.get_ps_clim(lat, lon) / 100
topo.units = 'hPa'

# ----------------------------------------------------------------------
# Correct for topography

u_orig = u
u = dat.correct_for_topography(u_orig, topo)

# ----------------------------------------------------------------------
# Integrated vertically dp/g

# DataArray
u_int = int_pres(u, pdim=-3)

# ndarray
u_int2 = int_pres(u.values, plev*100, pdim=-3)

p0=1e5
g = constants.g.values
scale = g/p0

m = 7
k = 5
cint=2

plt.figure(figsize=(7,10))
plt.subplot(311)
ap.contourf_latlon(u[m,k], clev=cint)
Exemplo n.º 2
0
mon = ds['mon'].values

topo = dat.get_ps_clim(lat, lon) / 100
topo.units = 'hPa'

# ----------------------------------------------------------------------
# Correct for topography

u_orig = u
u = dat.correct_for_topography(u_orig, topo)

# ----------------------------------------------------------------------
# Integrated vertically dp/g

# DataArray
u_int = int_pres(u, pdim=-3)

# ndarray
u_int2 = int_pres(u.values, plev * 100, pdim=-3)

p0 = 1e5
g = constants.g.values
scale = g / p0

m = 7
k = 5
cint = 2

plt.figure(figsize=(7, 10))
plt.subplot(311)
ap.contourf_latlon(u[m, k], clev=cint)
ap.contour_latpres(vbar, clev=0.5)

t, k = 0, 4
plt.figure(figsize=(7,8))
plt.subplot(211)
ap.pcolor_latlon(u[t,k])
plt.subplot(212)
ap.pcolor_latlon(v[t,k])

# ----------------------------------------------------------------------
# Moisture fluxes

uq = u * q
vq = v * q

uq_int = dat.int_pres(uq, pdim=-3)
vq_int = dat.int_pres(vq, pdim=-3)

t, k = 0, 4
plt.figure(figsize=(7,8))
plt.subplot(211)
ap.pcolor_latlon(uq[t,k])
plt.subplot(212)
ap.pcolor_latlon(vq[t,k])

plt.figure(figsize=(7,8))
plt.subplot(211)
ap.pcolor_latlon(uq_int[t])
plt.subplot(212)
ap.pcolor_latlon(vq_int[t])
Exemplo n.º 4
0
def moisture_flux_conv(uq,
                       vq,
                       lat=None,
                       lon=None,
                       plev=None,
                       pdim=-3,
                       pmin=0,
                       pmax=1e6,
                       return_comp=False,
                       already_int=False):
    """Return the vertically integrated moisture flux convergence.

    Parameters
    ----------
    uq : ndarray or xray.DataArray
        Zonal moisture flux, with latitude as the second-last dimension,
        longitude as the last dimension.
        i.e. zonal wind (m/s) * specific humidity (kg/kg)
        If already_int is True, then uq is already vertically integrated.
        Otherwise, uq is on vertical pressure levels.
    vq : ndarray or xray.DataArray
        Meridional moisture flux, with latitude as the second-last dimension,
        longitude as the last dimension.
        i.e. meridional wind (m/s) * specific humidity (kg/kg)
        If already_int is True, then vq is already vertically integrated.
        Otherwise, vq is on vertical pressure levels.
    lat, lon : ndarray, optional
        Latitudes and longitudes in degrees.  If omitted, then uq and
        vq must be xray.DataArrays and the coordinates are extracted
        from them.
    plev : ndarray, optional
        Pressure levels in Pascals.  If omitted, then extracted from
        DataArray inputs.
    pdim : int, optional
        Dimension of pressure levels in uq and vq.
    pmin, pmax : float, optional
        Lower and upper bounds (inclusive) of pressure levels (Pa)
        to include in integration.
    return_comp : bool, optional
        If True, return additional components, otherwise just total
        moisture flux convergence.
    already_int : bool, optional
        If True, then uq and vq inputs have already been vertically
        integrated.  Otherwise, the vertical integration is
        calculated here.

    Returns
    -------
    If return_comp is False:
    mfc : ndarray or xray.DataArray
        Vertically integrated moisture flux convergence in mm/day.

    If return_comp is True:
    mfc, mfc_x, mfc_y, uq_int, vq_int : ndarrays or xray.DataArrays
        Vertically integrated moisture flux convergence in mm/day
        (total, x- and y- components) and vertically integrated
        moisture fluxes.

    """

    if already_int:
        uq_int, vq_int = uq, vq
    else:
        uq_int = dat.int_pres(uq, plev, pdim=pdim, pmin=pmin, pmax=pmax)
        vq_int = dat.int_pres(vq, plev, pdim=pdim, pmin=pmin, pmax=pmax)

    mfc, mfc_x, mfc_y = divergence_spherical_2d(uq_int, vq_int, lat, lon)

    # Convert from divergence to convergence, and to mm/day
    mfc = -dat.precip_convert(mfc, 'kg/m2/s', 'mm/day')
    mfc_x = -dat.precip_convert(mfc_x, 'kg/m2/s', 'mm/day')
    mfc_y = -dat.precip_convert(mfc_y, 'kg/m2/s', 'mm/day')

    if isinstance(mfc, xray.DataArray):
        mfc.name = 'Vertically integrated moisture flux convergence'
        mfc.attrs['units'] = 'mm/day'

    if return_comp:
        return mfc, mfc_x, mfc_y, uq_int, vq_int
    else:
        return mfc