<commit_before>#-------------------------------------------------------------------------------
# Name:         clutter
# Purpose:
#
# Authors:      <NAME>, <NAME> and <NAME>
#
# Created:      26.10.2011
# Copyright:    (c) <NAME>, <NAME> and <NAME> 2011
# Licence:      The MIT License
#-------------------------------------------------------------------------------
#!/usr/bin/env python
"""
Clutter Identification
^^^^^^^^^^^^^^^^^^^^^^

.. autosummary::
   :nosignatures:
   :toctree: generated/

   filter_gabella
   filter_gabella_a
   filter_gabella_b
   histo_cut

"""
import numpy as np
import scipy.ndimage as ndi

def filter_gabella_a(img, wsize, tr1, cartesian=False, radial=False):
    r"""First part of the Gabella filter looking for large reflectivity
    gradients.

    This function checks for each pixel in `img` how many pixels surrounding
    it in a window of `wsize` are by `tr1` smaller than the central pixel.

    Parameters
    ----------
    img : array_like
        radar image to which the filter is to be applied
    wsize : int
        Size of the window surrounding the central pixel
    tr1 : float
        Threshold value
    cartesian : boolean
        Specify if the input grid is Cartesian or polar
    radial : boolean
        Specify if only radial information should be used 

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

    See Also
    --------
    filter_gabella_b : the second part of the filter
    filter_gabella : the complete filter

    Examples
    --------
    TODO: provide a correct example here

    >>> a=[1,2,3]
    >>> print [x + 3 for x in a]
    :w
[4, 5, 6]
    >>> print "a\n\nb"
    a
    b

    """
    nn = wsize // 2
    count = -np.ones(img.shape,dtype=int)
    range_shift = range(-nn,nn+1)
    azimuth_shift = range(-nn,nn+1)
    if radial:
        azimuth_shift = [0]
    for sa in azimuth_shift:
        ref = np.roll(img,sa,axis=0)
        for sr in range_shift:
            ref = np.roll(ref,sr,axis=1)
            count += ( img - ref < tr1 )
    count[:,0:nn] = wsize**2
    count[:,-nn:] = wsize**2
    if cartesian :
        count[0:nn,:] = wsize**2
        count[-nn:,:] = wsize**2
    return(count)

def filter_gabella_b(img, thrs=0.):
    r"""Second part of the Gabella filter comparing area to circumference of
    contiguous echo regions.



    Parameters
    ----------
    img : array_like
    thrs : float
        Threshold below which the field values will be considered as no rain

    Returns
    -------
    output : array_like<commit_msg>bug fix<commit_after>#-------------------------------------------------------------------------------
# Name:         clutter
# Purpose:
#
# Authors:      <NAME>, <NAME> and <NAME>
#
# Created:      26.10.2011
# Copyright:    (c) <NAME>, <NAME> and <NAME> 2011
# Licence:      The MIT License
#-------------------------------------------------------------------------------
#!/usr/bin/env python
"""
Clutter Identification
^^^^^^^^^^^^^^^^^^^^^^

.. autosummary::
   :nosignatures:
   :toctree: generated/

   filter_gabella
   filter_gabella_a
   filter_gabella_b
   histo_cut

"""
import numpy as np
import scipy.ndimage as ndi

def filter_gabella_a(img, wsize, tr1, cartesian=False, radial=False):
    r"""First part of the Gabella filter looking for large reflectivity
    gradients.

    This function checks for each pixel in `img` how many pixels surrounding
    it in a window of `wsize` are by `tr1` smaller than the central pixel.

    Parameters
    ----------
    img : array_like
        radar image to which the filter is to be applied
    wsize : int
        Size of the window surrounding the central pixel
    tr1 : float
        Threshold value
    cartesian : boolean
        Specify if the input grid is Cartesian or polar
    radial : boolean
        Specify if only radial information should be used 

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

    See Also
    --------
    filter_gabella_b : the second part of the filter
    filter_gabella : the complete filter

    Examples
    --------
    TODO: provide a correct example here

    >>> a=[1,2,3]
    >>> print [x + 3 for x in a]
    :w
[4, 5, 6]
    >>> print "a\n\nb"
    a
    b

    """
    nn = wsize // 2
    count = -np.ones(img.shape,dtype=int)
    range_shift = range(-nn,nn+1)
    azimuth_shift = range(-nn,nn+1)
    if radial:
        azimuth_shift = [0]
    for sa in azimuth_shift:
        refa = np.roll(img,sa,axis=0)
        for sr in range_shift:
            refr = np.roll(refa,sr,axis=1)
            count += ( img - refr < tr1 )
    count[:,0:nn] = wsize**2
    count[:,-nn:] = wsize**2
    if cartesian :
        count[0:nn,:] = wsize**2
        count[-nn:,:] = wsize**2
    return(count)

def filter_gabella_b(img, thrs=0.):
    r"""Second part of the Gabella filter comparing area to circumference of
    contiguous echo regions.



    Parameters
    ----------
    img : array_like
    thrs : float
        Threshold below which the field values will be considered as no rain

    Returns
    -------
    output : array_like
{'fraction_non_alphanumeric': 0.17221584385763491, 'fraction_numerical': 0.013777267508610792, 'mean_word_length': 1.8438520130576714, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1312159', 'n_tokens_mistral': 1628, 'n_tokens_neox': 1542, 'n_words': 522}