How to use the wradlib.trafo function in wradlib

To help you get started, we’ve selected a few wradlib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github wradlib / wradlib / wradlib / dp.py View on Github external
----------
    zdr : float or :class:`numpy:numpy.ndarray`
        differential reflectivity
    rho : float or :class:`numpy:numpy.ndarray`
        crosscorrelation coefficient

    Returns
    ------
    depolarization : :class:`numpy:numpy.ndarray`
        array of depolarization ratios with the same shape as input data,
        numpy broadcasting rules apply
    """
    zdr = trafo.idecibel(np.asanyarray(zdr))
    m = 2 * np.asanyarray(rho) * zdr ** 0.5

    return trafo.decibel((1 + zdr - m) / (1 + zdr + m))
github wradlib / wradlib / wradlib / zr.py View on Github external
def _z_to_r_enhanced_mdcorr(z, xmode='reflect', ymode='wrap'):
    """multidimensional version

    assuming the two last dimensions represent a 2-D image
    Uses :func:`scipy:scipy.ndimage.filters.correlate` to reduce the number of
    for-loops even more.
    """
    # get the shape of the input
    # dimy = z.shape[-2]
    # dimx = z.shape[-1]

    # calculate the decibel values from the input
    db = trafo.decibel(z)
    # calculate the shower differences by 1-d correlation with a differencing
    # kernel
    db_diffx = np.abs(filters.correlate1d(db, [1, -1], axis=-1,
                                          mode=xmode, origin=-1))
    db_diffy = np.abs(filters.correlate1d(db, [1, -1], axis=-2,
                                          mode=ymode, origin=-1))
    diffxmode = 'wrap' if xmode == 'wrap' else 'constant'
    diffymode = 'wrap' if ymode == 'wrap' else 'constant'
    diffx_sum1 = filters.correlate1d(db_diffx, [1, 1, 1],
                                     axis=-2, mode=diffymode)
    diffxsum = filters.correlate1d(diffx_sum1, [1, 1, 0],
                                   axis=-1, mode=diffxmode)
    diffy_sum1 = filters.correlate1d(db_diffy, [1, 1, 1],
                                     axis=-1, mode=diffxmode)
    diffysum = filters.correlate1d(diffy_sum1, [1, 1, 0],
                                   axis=-2, mode=diffymode)
github wradlib / wradlib / wradlib / zr.py View on Github external
e      | 7 | 8 | 9 |
    c      +---+---+---+
    t
    i      if 5 is the pixel in question, its shower index is calculated as
    o      ( |1-2| + |2-3| + |4-5| + |5-6| + |7-8| + |8-9| +
    n      + |1-4| + |4-7| + |2-5| + |5-8| + |3-6| + |6-9| ) / 12.
           then, the upper line of the sum would be diffx (DIFFerences in
           X-direction), the lower line would be diffy
           (DIFFerences in Y-direction) in the code below.
    """
    # get the shape of the input
    dimy = z.shape[0]
    dimx = z.shape[1]

    # calculate the decibel values from the input
    db = trafo.decibel(z)

    # set up our output arrays
    r = np.zeros(z.shape)
    si = np.zeros(z.shape)

    # calculate difference fields in x and y direction
    #  mainly for performance reasons, so that we can use numpy's efficient
    #  array operations and avoid calculating a difference more than once
    diffx = np.abs(db[:, :-1] - db[:, 1:])
    diffy = np.abs(db[:-1, :] - db[1:, :])

    # if the reflectivity is larger than 44dBZ, then there is no need to
    # calculate the shower index
    gt44 = np.where(db > 44.)
    r[gt44] = z_to_r(z[gt44], a=77., b=1.9)
    # the same is true for values between 36.5 and 44 dBZ
github wradlib / wradlib / wradlib / atten.py View on Github external
Returns
    -------
    k : :class:`numpy:numpy.ndarray`
        Array with the same shape as ``gateset`` containing the
        calculated two-way transmission loss [dB] for each range gate.
        In case the input array (gateset) contains NaNs the
        corresponding beams of the output array (k) will be set as NaN,
        too.
    """

    # Select rangebins inside the defined center-range n_r.
    center = gateset[..., :n_r].reshape(-1, n_r * gateset.shape[-2])
    center_m = np.ma.masked_array(center, np.isnan(center))
    # Calculate rainrate in the center-range based on statistical method stat
    # and with standard ZR-relation.
    rain_over_radome = zr.z_to_r(trafo.idecibel(stat(center_m, axis=-1)))
    # Estimate the empirical two-way transmission loss due to
    # radome-attenuation.
    k = 2 * hydrophobicity * rain_over_radome * np.tanh(frequency / 10.) ** 2
    # Reshape the result to gateset-shape.
    k = np.repeat(k, gateset.shape[-1] *
                  gateset.shape[-2]).reshape(gateset.shape)

    return k.filled(fill_value=np.nan)
github wradlib / wradlib / wradlib / atten.py View on Github external
Per default set to 1.67e-4.
    b : float
        exponent of the k-Z relation ( :math:`k=a \\cdot Z^{b}` ). Per default
        set to 0.7.
    gate_length : float
        length of a range gate [km]. Per default set to 1.0.

    Returns
    -------
    pia : :class:`numpy:numpy.ndarray`
        Array with the same shape as ``gateset`` containing the calculated path
        integrated attenuation [dB] for each range gate.
    """
    pia = np.zeros(gateset.shape)
    for gate in range(gateset.shape[-1] - 1):
        k = a * trafo.idecibel(gateset[..., gate] + pia[..., gate]) ** b \
            * 2.0 * gate_length
        pia[..., gate + 1] = pia[..., gate] + k
    return pia
github wradlib / wradlib / wradlib / dp.py View on Github external
:cite:`Melnikov2013`, :cite:`Ryzhkov2017`).

    Parameters
    ----------
    zdr : float or :class:`numpy:numpy.ndarray`
        differential reflectivity
    rho : float or :class:`numpy:numpy.ndarray`
        crosscorrelation coefficient

    Returns
    ------
    depolarization : :class:`numpy:numpy.ndarray`
        array of depolarization ratios with the same shape as input data,
        numpy broadcasting rules apply
    """
    zdr = trafo.idecibel(np.asanyarray(zdr))
    m = 2 * np.asanyarray(rho) * zdr ** 0.5

    return trafo.decibel((1 + zdr - m) / (1 + zdr + m))