예제 #1
0
def nrl(x, a=1, c=220):
    """
    Lin-log style remap.

    Parameters
    ----------
    x : numpy.ndarray
        data to remap
    a : float
        scale factor of 99th percentile for input "knee"
    c : float
        output "knee" in lin-log curve
    Returns
    -------
    numpy.ndarray
    """

    x = np.abs(x)
    xmin = np.min(x)
    p99 = prctile(x[np.isfinite(x)], 99)
    b = (255 - c) / np.log10((np.max(x) - xmin) / ((a * p99) - xmin))

    out = np.zeros_like(x, np.uint8)
    linear_region = (x <= a * p99)
    out[linear_region] = (x[linear_region] - xmin) * c / ((a * p99) - xmin)
    out[np.logical_not(linear_region)] = c + (b * np.log10(
        (x[np.logical_not(linear_region)] - xmin) / ((a * p99) - xmin)))
    return out
예제 #2
0
def nrl(x, a=1., c=220.):
    """
    Lin-log style remap.

    Parameters
    ----------
    x : numpy.ndarray
        data to remap
    a : float
        scale factor of 99th percentile for input "knee"
    c : float
        output "knee" in lin-log curve

    Returns
    -------
    numpy.ndarray
    """

    x = numpy.abs(x)
    xmax = numpy.max(x)
    xmin = numpy.min(x)
    p99 = prctile(x[numpy.isfinite(x)], 99)
    b = (255 - c) / (numpy.log10(xmax - xmin) * (a * p99 - xmin))

    out = numpy.zeros_like(x, numpy.uint8)
    linear_region = (x <= a * p99)
    out[linear_region] = c * (x[linear_region] - xmin) / (a * p99 - xmin)
    out[~linear_region] = c + b * numpy.log10(
        (x[~linear_region] - xmin) / (a * p99 - xmin))
    return out
예제 #3
0
파일: remap.py 프로젝트: gkchen/sarpy
def nrl(x, a=1, c=220):
    """Lin-log style remap.

    Input parameters
    x : data to remap
    a : scale factor of 99th percentile for input "knee"
    c : output "knee" in lin-log curve

    """

    # We include this import inside the function since it is only used here, and
    # since we don't want importing of this module to fail if the user does not
    # have scipy.
    from scipy.stats import scoreatpercentile as prctile

    x = abs(x)
    xmin = np.min(x)
    p99 = prctile(x[np.isfinite(x)], 99)
    b = (255 - c) / np.log10((np.max(x) - xmin) / ((a * p99) - xmin))

    out = np.zeros_like(x, np.uint8)
    linear_region = (x <= a * p99)
    out[linear_region] = (x[linear_region] - xmin) * c / ((a * p99) - xmin)
    out[np.logical_not(linear_region)] = c + (b * np.log10(
        (x[np.logical_not(linear_region)] - xmin) / ((a * p99) - xmin)))
    return out
예제 #4
0
def _nrl_stats(amplitude):
    """
    Calculate the statistiucs for input into the nrl remap.

    Parameters
    ----------
    amplitude : numpy.ndarray
        The amplitude array, assumed real valued.

    Returns
    -------
    tuple
        Of the form `(minimum, maximum, 99th percentile)
    """

    finite_mask = numpy.isfinite(amplitude)
    if numpy.any(finite_mask):
        return numpy.min(amplitude[finite_mask]), numpy.max(
            amplitude[finite_mask]), prctile(amplitude[finite_mask], 99)
    else:
        return 0, 0, 0