# Path: PyFVCOM/utilities/general.py
# def fix_range(a, nmin, nmax):
#     """
#     Given an array of values `a', scale the values within in to the range
#     specified by `nmin' and `nmax'.
# 
#     In the case where all the values are identical, the values are returned unchanged.
# 
#     Parameters
#     ----------
#     a : ndarray
#         Array of values to scale.
#     nmin, nmax : float
#         New minimum and maximum values for the new range.
# 
#     Returns
#     -------
#     b : ndarray
#         Scaled array.
# 
#     """
# 
#     A = a.min()
#     B = a.max()
#     C = nmin
#     D = nmax
# 
#     # In the case where all the values are the same, just return the original values.
#     if A != B:
#         b = (((D - C) * (a - A)) / (B - A)) + C
#     else:
#         b = a
# 
#     return b


import numpy as np
from scipy import stats, polyfit, polyval
from PyFVCOM.utilities.general import fix_range
        m, c, r, p, std_err = stats.linregress(np.log10(x), y)
        xf = np.log10(x)
    elif type is 'exp':
        m, c, r, p, std_err = stats.linregress(x, np.log10(y))
        xf = x
    else:
        raise ValueError('Unknown regression type')

    yf = (m * xf) + c

    return xf, yf, m, c, r


def calculate_polyfit(x, y):
    """ Calculate a linear regression using polyfit instead """

    # FIXME(pica) This doesn't work for large ranges (tens of orders of
    # magnitude). No idea why as the fixRange() function above should make
    # all values greater than one. The trouble mainly seems to happen when
    # log10(min(x)) negative.

    # Check the smallest value in x or y isn't below 2x10-7 otherwise
    # we hit numerical instabilities.
    xFactorFix, xFactor = False, 0
    yFactorFix, yFactor = False, 0
    minX = min(x)
    minY = min(y)
    if minX < 2e-7:
        x, xFactor, xFactorFix = fix_range(x)
    if minY < 2e-7:

# Path: PyFVCOM/utilities/general.py
# def fix_range(a, nmin, nmax):
#     """
#     Given an array of values `a', scale the values within in to the range
#     specified by `nmin' and `nmax'.
# 
#     In the case where all the values are identical, the values are returned unchanged.
# 
#     Parameters
#     ----------
#     a : ndarray
#         Array of values to scale.
#     nmin, nmax : float
#         New minimum and maximum values for the new range.
# 
#     Returns
#     -------
#     b : ndarray
#         Scaled array.
# 
#     """
# 
#     A = a.min()
#     B = a.max()
#     C = nmin
#     D = nmax
# 
#     # In the case where all the values are the same, just return the original values.
#     if A != B:
#         b = (((D - C) * (a - A)) / (B - A)) + C
#     else:
#         b = a
# 
#     return b


# Path: PyFVCOM/stats.py
import numpy as np
from scipy import stats, polyfit, polyval
from PyFVCOM.utilities.general import fix_range

        m, c, r, p, std_err = stats.linregress(np.log10(x), y)
        xf = np.log10(x)
    elif type is 'exp':
        m, c, r, p, std_err = stats.linregress(x, np.log10(y))
        xf = x
    else:
        raise ValueError('Unknown regression type')

    yf = (m * xf) + c

    return xf, yf, m, c, r


def calculate_polyfit(x, y):
    """ Calculate a linear regression using polyfit instead """

    # FIXME(pica) This doesn't work for large ranges (tens of orders of
    # magnitude). No idea why as the fixRange() function above should make
    # all values greater than one. The trouble mainly seems to happen when
    # log10(min(x)) negative.

    # Check the smallest value in x or y isn't below 2x10-7 otherwise
    # we hit numerical instabilities.
    xFactorFix, xFactor = False, 0
    yFactorFix, yFactor = False, 0
    minX = min(x)
    minY = min(y)
    if minX < 2e-7:
        x, xFactor, xFactorFix = fix_range(x)
    if minY < 2e-7:

        y, yFactor, yFactorFix = fix_range(y)