コード例 #1
0
ファイル: test_util.py プロジェクト: viniciusgcjr/wradlib
    def test_roll2d_polar(self):
        filename = util.get_wradlib_data_file("misc/polar_dBZ_tur.gz")
        data = np.loadtxt(filename)
        result1 = util.roll2d_polar(data, 1, axis=0)
        result2 = util.roll2d_polar(data, -1, axis=0)
        result3 = util.roll2d_polar(data, 1, axis=1)
        result4 = util.roll2d_polar(data, -1, axis=1)

        np.testing.assert_equal(result1, np.roll(data, 1, axis=0))
        np.testing.assert_equal(result2, np.roll(data, -1, axis=0))
        np.testing.assert_equal(result3[:, 1:],
                                np.roll(data, 1, axis=1)[:, 1:])
        np.testing.assert_equal(result4[:, :-1],
                                np.roll(data, -1, axis=1)[:, :-1])
コード例 #2
0
ファイル: test_util.py プロジェクト: heistermann/wradlib
    def test_roll2d_polar(self):
        filename = util.get_wradlib_data_file('misc/polar_dBZ_tur.gz')
        data = np.loadtxt(filename)
        result1 = util.roll2d_polar(data, 1, axis=0)
        result2 = util.roll2d_polar(data, -1, axis=0)
        result3 = util.roll2d_polar(data, 1, axis=1)
        result4 = util.roll2d_polar(data, -1, axis=1)

        np.testing.assert_equal(result1, np.roll(data, 1, axis=0))
        np.testing.assert_equal(result2, np.roll(data, -1, axis=0))
        np.testing.assert_equal(result3[:, 1:],
                                np.roll(data, 1, axis=1)[:, 1:])
        np.testing.assert_equal(result4[:, :-1],
                                np.roll(data, -1, axis=1)[:, :-1])
コード例 #3
0
ファイル: clutter.py プロジェクト: tooowzh/wradlib
def filter_window_distance(img, rscale, fsize=1500, tr1=7):
    """2d filter looking for large reflectivity gradients.

    This function counts for each bin in ``img`` the percentage of surrounding
    bins in a window of half size ``fsize`` which are not ``tr1`` smaller than
    the central bin. The window is defined using geometrical distance.

    Parameters
    ----------
    img : array_like
        2d polar data to which the filter is to be applied
    rscale : float
        range [m] scale of the polar grid
    fsize : int
        Half-size [m] of the square window surrounding the central pixel
    tr1 : float
        Threshold value

    Returns
    -------
    output : array_like
        an array with the same shape as ``img``, containing the
        filter's results.

    See Also
    --------
    :func:`~wradlib.clutter.filter_gabella_a` - Original version of the filter

    :func:`~wradlib.clutter.filter_gabella_b` - filter using a echo area
    """
    ascale = 2 * np.pi / img.shape[0]
    count = np.ones(img.shape, dtype=int)
    similar = np.zeros(img.shape, dtype=float)
    good = np.ones(img.shape, dtype=float)
    valid = (~np.isnan(img))
    hole = np.sum(~valid) > 0
    nr = int(round(fsize / rscale))
    range_shift = range(-nr, nr + 1)
    r = np.arange(img.shape[1]) * rscale + rscale / 2
    adist = r * ascale
    na = np.around(fsize / adist).astype(int)
    max_na = img.shape[0] / 10
    sa = 0
    while sa < max_na:
        imax = np.where(na >= sa)[0][-1] + 1
        refa1 = util.roll2d_polar(img, sa, axis=0)
        refa2 = util.roll2d_polar(img, -sa, axis=0)
        for sr in range_shift:
            refr1 = util.roll2d_polar(refa1, sr, axis=1)
            similar[:, 0: imax] += (img[:, 0: imax] - refr1[:, 0: imax] < tr1)
            if sa > 0:
                refr2 = util.roll2d_polar(refa2, sr, axis=1)
                similar[:, 0: imax] += (img[:, 0: imax] -
                                        refr2[:, 0: imax] < tr1)
        count[:, 0:imax] = 2 * sa + 1
        sa += 1
    similar[~valid] = np.nan
    count[~valid] = -1
    count[:, nr:-nr] = count[:, nr:-nr] * (2 * nr + 1)
    for i in range(0, nr):
        count[:, i] = count[:, i] * (nr + 1 + i)
        count[:, -i - 1] = count[:, -i - 1] * (nr + 1 + i)
    if hole:
        good = util.filter_window_polar(valid.astype(float),
                                        fsize, "uniform", rscale)
        count = count * good
        count[count == 0] = 1
    similar -= 1
    count -= 1
    similar = similar / count
    return similar