Ejemplo n.º 1
0
def createPreWhiteningFilter(**kwargs):
    '''
	Creates a pre-whitening filter in 3D. Fits a polynomial to the spectrum
	beyond the "elbowAngstrom" frequency. Returns a whitening filter that
	can be adjusted using the "rampWeight." (Alp Kucukelbir, 2013)

	'''
    epsilon = 1e-10

    spectrum = kwargs.get('spectrum', 0)
    elbowAngstrom = kwargs.get('elbowAngstrom', 0)
    rampWeight = kwargs.get('rampWeight', 1.0)
    vxSize = kwargs.get('vxSize', 0)
    n = kwargs.get('n', 0)

    # Create radius matrix
    R = createRmatrix(n)

    # Create the x and y variables for the polynomial regression
    xpoly = np.array(range(1, spectrum.size + 1))
    ypoly = np.log(np.sqrt(spectrum))

    # Create the index of frequencies (depends on vxSize)
    Fs = 1 / vxSize
    Findex = 1 / (Fs / 2 * np.linspace(epsilon, 1, xpoly.size))

    # Find the points of interest
    indexElbow = np.argmin((Findex - elbowAngstrom)**2)
    indexStart = np.argmin((Findex - (1.05 * elbowAngstrom))**2)
    indexNyquist = xpoly[-1]

    # Create the weighting function to do a weighted fit
    wpoly = np.array(np.bitwise_and(xpoly > indexElbow, xpoly < indexNyquist),
                     dtype='float32')
    wpoly += 0.5 * np.array(np.bitwise_and(xpoly > indexStart,
                                           xpoly <= indexElbow),
                            dtype='float32')

    # Do the polynomial fit
    pcoef = np.polynomial.polynomial.polyfit(xpoly, ypoly, 2, w=wpoly)
    peval = np.polynomial.polynomial.polyval(xpoly, pcoef)

    # Don't change any frequencies outside of indexStart to indexNyquist
    R[R < indexStart] = indexStart
    R[R > indexNyquist] = indexNyquist

    # Create the pre-whitening filter
    pWfilter = np.exp(
        np.polynomial.polynomial.polyval(R, -1.0 * rampWeight * pcoef))

    del R

    return {'peval': peval, 'pcoef': pcoef, 'pWfilter': pWfilter}
Ejemplo n.º 2
0
def createPreWhiteningFilter(**kwargs):
	'''
	Creates a pre-whitening filter in 3D. Fits a polynomial to the spectrum
	beyond the "elbowAngstrom" frequency. Returns a whitening filter that
	can be adjusted using the "rampWeight." (Alp Kucukelbir, 2013)

	'''
	epsilon = 1e-10

	spectrum      = kwargs.get('spectrum', 0)
	elbowAngstrom = kwargs.get('elbowAngstrom', 0)
	rampWeight    = kwargs.get('rampWeight',1.0)
	vxSize        = kwargs.get('vxSize', 0)
	n             = kwargs.get('n', 0)

	# Create radius matrix
	R = createRmatrix(n)

	# Create the x and y variables for the polynomial regression
	xpoly = np.array(range(1,spectrum.size + 1))
	ypoly = np.log(np.sqrt(spectrum))

	# Create the index of frequencies (depends on vxSize)
	Fs     = 1/vxSize
	Findex = 1/( Fs/2 * np.linspace(epsilon, 1, xpoly.size) )

	# Find the points of interest
	indexElbow    = np.argmin((Findex-elbowAngstrom)**2)
	indexStart    = np.argmin((Findex-(1.05*elbowAngstrom))**2)
	indexNyquist  = xpoly[-1]

	# Create the weighting function to do a weighted fit
	wpoly =  np.array(np.bitwise_and(xpoly>indexElbow, xpoly<indexNyquist),    dtype='float32')
	wpoly += 0.5*np.array(np.bitwise_and(xpoly>indexStart, xpoly<=indexElbow), dtype='float32')

	# Do the polynomial fit
	pcoef = np.polynomial.polynomial.polyfit(xpoly, ypoly, 2, w=wpoly)
	peval = np.polynomial.polynomial.polyval(xpoly, pcoef)

	# Don't change any frequencies outside of indexStart to indexNyquist
	R[R<indexStart]   = indexStart
	R[R>indexNyquist] = indexNyquist

	# Create the pre-whitening filter
	pWfilter  = np.exp(np.polynomial.polynomial.polyval(R,-1.0*rampWeight*pcoef))

	del R

	return {'peval':peval, 'pcoef':pcoef, 'pWfilter': pWfilter}
Ejemplo n.º 3
0
def createPreWhiteningFilterFinal(**kwargs):
    '''
	Creates a pre-whitening filter in 3D. Expects a fitted polynomial
	defined by its "pcoef". Returns a whitening filter that
	can be adjusted using the "rampWeight." (Alp Kucukelbir, 2013)

	'''
    epsilon = 1e-10

    spectrum = kwargs.get('spectrum', 0)
    pcoef = kwargs.get('pcoef', 0)
    elbowAngstrom = kwargs.get('elbowAngstrom', 0)
    rampWeight = kwargs.get('rampWeight', 1.0)
    vxSize = kwargs.get('vxSize', 0)
    n = kwargs.get('n', 0)
    cubeSize = kwargs.get('cubeSize', 0)

    # Create radius matrix
    R = createRmatrix(n)

    # Create the x and y variables for the polynomial regression
    xpoly = np.array(range(1, spectrum.size + 1))

    # Create the index of frequencies (depends on vxSize)
    Fs = 1 / vxSize
    Findex = 1 / (Fs / 2 * np.linspace(epsilon, 1, xpoly.size))

    # Find the points of interest
    indexStart = np.argmin((Findex - (1.05 * elbowAngstrom))**2)
    indexNyquist = xpoly[-1]

    # Don't change any frequencies outside of indexStart to indexNyquist
    R[R < indexStart] = indexStart
    R[R > indexNyquist] = indexNyquist

    # Rescale R such that the polynomial from the cube fit makes sense
    R = R / (float(n) / (cubeSize - 1))

    # Create the pre-whitening filter
    pWfilter = np.exp(
        np.polynomial.polynomial.polyval(R, -1.0 * rampWeight * pcoef))

    del R

    return {'pWfilter': pWfilter}
Ejemplo n.º 4
0
def createPreWhiteningFilterFinal(**kwargs):
	'''
	Creates a pre-whitening filter in 3D. Expects a fitted polynomial
	defined by its "pcoef". Returns a whitening filter that
	can be adjusted using the "rampWeight." (Alp Kucukelbir, 2013)

	'''
	epsilon = 1e-10

	spectrum      = kwargs.get('spectrum', 0)
	pcoef         = kwargs.get('pcoef', 0)
	elbowAngstrom = kwargs.get('elbowAngstrom', 0)
	rampWeight    = kwargs.get('rampWeight',1.0)
	vxSize        = kwargs.get('vxSize', 0)
	n             = kwargs.get('n', 0)
	cubeSize      = kwargs.get('cubeSize', 0)

	# Create radius matrix
	R = createRmatrix(n)

	# Create the x and y variables for the polynomial regression
	xpoly = np.array(range(1,spectrum.size + 1))

	# Create the index of frequencies (depends on vxSize)
	Fs     = 1/vxSize
	Findex = 1/( Fs/2 * np.linspace(epsilon, 1, xpoly.size) )

	# Find the points of interest
	indexStart    = np.argmin((Findex-(1.05*elbowAngstrom))**2)
	indexNyquist  = xpoly[-1]

	# Don't change any frequencies outside of indexStart to indexNyquist
	R[R<indexStart]   = indexStart
	R[R>indexNyquist] = indexNyquist

	# Rescale R such that the polynomial from the cube fit makes sense
	R = R/(float(n)/(cubeSize-1))

	# Create the pre-whitening filter
	pWfilter  = np.exp(np.polynomial.polynomial.polyval(R,-1.0*rampWeight*pcoef))

	del R

	return {'pWfilter': pWfilter}