GET_SLOPE
    :summary: This function returns the spectral slope of a spectrum using a least-square regression 
    
    :parameter fq: frequency
    :parameter spec: spectrum data
    
    :keyword degree: Degree of the least-square regression model 
    
    :return:
      * slope : spectral slope (or model coefficients for a higher order model)
      * intercept : Energy at unit frequency (1 cpkm)
    
    :author: Renaud DUSSURGET (RD) - LER/PAC, Ifremer
    :change: Created by RD, August 2012

def get_slope(fq,spec,degree=1,frange=None,threshold=0.):
    """
    
    GET_SLOPE
    :summary: This function returns the spectral slope of a spectrum using a least-square regression 
    
    :parameter fq: frequency
    :parameter spec: spectrum data
    
    :keyword degree: Degree of the least-square regression model 
    
    :return:
      * slope : spectral slope (or model coefficients for a higher order model)
      * intercept : Energy at unit frequency (1 cpkm)
    
    :author: Renaud DUSSURGET (RD) - LER/PAC, Ifremer
    :change: Created by RD, August 2012
    """
    
    sh=spec.shape
    ndims=len(sh)
    
    if ndims == 1 :
        
        x = np.log10(fq).flatten()
        y = np.log10(spec).flatten()
        
        
        #1) Linear least-square regression
        if degree == 1 :
            (slope, intercept, rval, pval, err) = stats.linregress(x,y)
    
        #2) Least-square regression using a higher-order spectral model
        # -> Gives the same results as 
        #cf. http://pingswept.org/2009/01/24/least-squares-polynomial-fitting-in-python/                                                    
        else :
            A = np.vander(x, degree+1) # form the Vandermonde matrix 
            (coeffs, residuals, rank, sing_vals) = np.linalg.lstsq(A,y) # find the x that minimizes the norm of Ax-y
            (slope[:-1], intercept) = coeffs
        
        return slope,intercept
    else :
        
        x = np.log10(fq[(fq > np.min(frange)) & (fq <= np.max(frange))]).flatten()
        y = np.log10(spec[(fq > np.min(frange)) & (fq <= np.max(frange)),:])
        nx = len(x)
        nt = sh[1]
        degree = 1
        
        out = []
        for i in np.arange(nt):
            (slope, intercept, rval, pval, err) = stats.linregress(x,y[:,i])
            flag = (y.mask[:,i].sum(dtype=float)/nx) <= threshold
            if i == 0 : out.append((slope,intercept,flag))
            else : out.append((slope,intercept,flag))

        return out