Example #1
0
def run():    
    # Here should go some meaningful data sample to test the transform.
    # Can you write one?
    n = 512
    data = numx.zeros((n,))
    x = numx.arange(n) * (2 * numx.pi / n)
    y = numx.cos(x*5)
    #result = transform(y)

    wavefreq, resampled = compress(y)

    pylab.figure(1)
    pylab.hold(0)
    pylab.plot(x,y,x,resampled)
    pylab.grid(1)
    
    pylab.figure(2)
    pylab.hold(0)
    pylab.plot(wavefreq[:30], '.-')
    pylab.grid(1)

    pylab.figure(3)
    pylab.hold(0)
    pylab.plot(wavefreq[:50], '.-')
    pylab.grid(1)
Example #2
0
def func(t, y, mu):
    #print "--> func", t, y
    f = numx.zeros((2, ), Float) * 1.0
    f[0] = y[1]
    f[1] = -y[0] - mu * y[1] * (y[0]**2 - 1)
    #print f
    return f
Example #3
0
def func(t, y, mu):
    #print "--> func", t, y
    f = numx.zeros((2,), Float) * 1.0
    f[0] = y[1]
    f[1] = -y[0] - mu * y[1] * (y[0] ** 2 -1);
    #print f
    return f
Example #4
0
def singlefreq():
    n = 4096
    data = numx.zeros((n,))
    w = wavelet.bspline_centered(208)
    #w = wavelet.bspline_centered(309)
    #w = wavelet.haar(2)
    #w = wavelet.daubechies_centered(20)
    #w = wavelet.daubechies_centered(4)
    #w = wavelet.daubechies_centered(20)
    
    plots = []
    labels = []
    m = 8
    for i in range(m):
        data[i] = 1

        #fw = w.transform_forward(data)
        iv = w.transform_inverse(data)
        labels.append( "%d" % (i,))
        plots.extend([iv, '-'])
        
    #pylab.figure(1)
    #pylab.hold(0)
    #pylab.plot(data, '.-')

    pylab.figure(2)
    pylab.hold(0)
    pylab.plot(*plots)
    pylab.legend(labels)
Example #5
0
def singlefreq():
    n = 4096
    data = numx.zeros((n, ))
    w = wavelet.bspline_centered(208)
    #w = wavelet.bspline_centered(309)
    #w = wavelet.haar(2)
    #w = wavelet.daubechies_centered(20)
    #w = wavelet.daubechies_centered(4)
    #w = wavelet.daubechies_centered(20)

    plots = []
    labels = []
    m = 8
    for i in range(m):
        data[i] = 1

        #fw = w.transform_forward(data)
        iv = w.transform_inverse(data)
        labels.append("%d" % (i, ))
        plots.extend([iv, '-'])

    #pylab.figure(1)
    #pylab.hold(0)
    #pylab.plot(data, '.-')

    pylab.figure(2)
    pylab.hold(0)
    pylab.plot(*plots)
    pylab.legend(labels)
Example #6
0
def run():
    # Here should go some meaningful data sample to test the transform.
    # Can you write one?
    n = 512
    data = numx.zeros((n, ))
    x = numx.arange(n) * (2 * numx.pi / n)
    y = numx.cos(x * 5)
    #result = transform(y)

    wavefreq, resampled = compress(y)

    pylab.figure(1)
    pylab.hold(0)
    pylab.plot(x, y, x, resampled)
    pylab.grid(1)

    pylab.figure(2)
    pylab.hold(0)
    pylab.plot(wavefreq[:30], '.-')
    pylab.grid(1)

    pylab.figure(3)
    pylab.hold(0)
    pylab.plot(wavefreq[:50], '.-')
    pylab.grid(1)
Example #7
0
def func(t, y, mu):
    f = Numeric.zeros((2, ), Numeric.Float) * 1.0
    f[0] = y[1]
    f[1] = -y[0] - mu * y[1] * (y[0]**2 - 1)
    #f[0] = y[1]
    #f[1] = y[0] * mu
    #print "y", y, "f", f
    return f
Example #8
0
def run():
    # Here should go some meaningful data sample to test the transform.
    # Can you write one?
    n = 512
    data = numx.zeros((n, ))

    result = transform(data)
    print result
Example #9
0
def run():    
    # Here should go some meaningful data sample to test the transform.
    # Can you write one?
    n = 512
    data = numx.zeros((n,))

    result = transform(data)
    print result
Example #10
0
File: odeiv.py Project: pygsl/pygsl
def jac(t, y, mu):
    dfdy = numx.ones((2, 2), ) * 1.
    dfdy[0, 0] = 0.0
    dfdy[0, 1] = 1.0
    dfdy[1, 0] = -2.0 * mu * y[0] * y[1] - 1.0
    dfdy[1, 1] = -mu * (y[0]**2 - 1.0)
    dfdt = numx.zeros((2, ))
    return dfdy, dfdt
Example #11
0
def func(t, y, mu):
    f = Numeric.zeros((2,), Numeric.Float) * 1.0
    f[0] = y[1]
    f[1] = -y[0] - mu * y[1] * (y[0] ** 2 -1);
    #f[0] = y[1]
    #f[1] = y[0] * mu
    #print "y", y, "f", f
    return f
Example #12
0
File: fft.py Project: pygsl/pygsl
def halfcomplex_radix2_unpack():
    n = 32
    a = numx.arange(n)
    c = numx.zeros((n, ))
    c[1:n / 2 + 1] = a[1::2]
    c[n / 2 + 1:] = a[-2:1:-2]
    print(c)
    print(fft.halfcomplex_radix2_unpack(c))
Example #13
0
def halfcomplex_radix2_unpack():
    n = 32   
    a = numx.arange(n)
    c = numx.zeros((n,))
    c[1:n/2+1]=a[1::2]
    c[n/2+1:]=a[-2:1:-2]    
    print c
    print fft.halfcomplex_radix2_unpack(c)
Example #14
0
def jac(t, y, mu):
    dfdy = numx.ones((2,2),) * 1. 
    dfdy[0, 0] = 0.0
    dfdy[0, 1] = 1.0
    dfdy[1, 0] = -2.0 * mu * y[0] * y[1] - 1.0
    dfdy[1, 1] = -mu * (y[0]**2 - 1.0)
    dfdt = numx.zeros((2,))
    return dfdy, dfdt
Example #15
0
def func(t, y, args):
    mu = args
    f = numx.zeros(y.shape, numx.float_)
    y0 = y[0]
    y1 = y[1]
    f[0] = y1;
    f[1] = -y0 - mu*y1*(y0**2 - 1);
    return f
Example #16
0
def my_df(v, params):
    x = v[0]
    y = v[1]
    df = numx.zeros(v.shape, ) * 1.
    dp = params
    df[0] = 20. * (x - dp[0])
    df[1] = 40. * (y - dp[1])
    return df
Example #17
0
def rosenbrock_df(x, params):
    a = params[0]
    b = params[1]
    df = Numeric.zeros((x.shape[0], x.shape[0]), Float)
    df[0, 0] = -a
    df[0, 1] = 0
    df[1, 0] = -2 * b * x[0]
    df[1, 1] = b
    return df
Example #18
0
def jac(t, y, mu):
    dfdy = Numeric.ones((2, 2), Numeric.Float)
    dfdy[0, 0] = 0.0
    dfdy[0, 1] = 1.0
    dfdy[1, 0] = -2.0 * mu * y[0] * y[1] - 1.0
    dfdy[1, 1] = -mu * (y[0]**2 - 1.0)
    dfdt = Numeric.zeros((2, ))

    return dfdy, dfdt
Example #19
0
def my_df(v, params):
    x = v[0]
    y = v[1]
    df = numx.zeros(v.shape, ) * 1.
    dp = params
    df[0] = 20. * (x - dp[0])
    df[1] = 40. * (y - dp[1])
    #print "\t\tx,y ->df", x,y, df
    return df
Example #20
0
def my_df(v, params):
    x = v[0]
    y = v[1]
    df = Numeric.zeros(v.shape, Float)
    dp = params
    df[0] = 20. * (x - dp[0])
    df[1] = 40. * (y - dp[1])
    #print "\t\tx,y ->df", x,y, df
    return df
Example #21
0
def my_df(v, params):
    x = v[0]
    y = v[1]
    df = numx.zeros(v.shape, ) * 1.
    dp = params
    df[0] = 20. * (x - dp[0])
    df[1] = 40. * (y - dp[1])
    #print( "\t\tx,y ->df", x,y, df)
    return df
Example #22
0
def jac(t, y, args):
    mu = args

    y0 = y[0]
    y1 = y[1]

    l = len(y)
    dfdy = numx.zeros((l,l), numx.float_)
    dfdy[0,0] = 0.0
    dfdy[0,1] = 1.0 
    dfdy[1,0] =  - 2.0 * mu * y0 * y1 - 1.0
    dfdy[1,1] =  - mu * (y0**2 - 1.0)
    
    dfdt = numx.zeros((l,), numx.float_)
    dfdt[0] = 0
    dfdt[1] = 0

    return dfdy, dfdt
Example #23
0
def rosenbrock_df(x, params):
    a = params[0]
    b = params[1]
    df = numx.zeros((x.shape[0], x.shape[0])) * 1.
    df[0,0] = -a
    df[0,1] = 0
    df[1,0] = -2 * b * x[0]
    df[1,1] = b
    return df
Example #24
0
def rosenbrock_df(x, params):
    a = params[0]
    b = params[1]
    df = Numeric.zeros((x.shape[0], x.shape[0]), Float)
    df[0,0] = -a
    df[0,1] = 0
    df[1,0] = -2 * b * x[0]
    df[1,1] = b
    return df
Example #25
0
def rosenbrock_df(x, params):
    a = params[0]
    b = params[1]
    df = numx.zeros((x.shape[0], x.shape[0])) * 1.
    df[0, 0] = -a
    df[0, 1] = 0
    df[1, 0] = -2 * b * x[0]
    df[1, 1] = b
    return df
Example #26
0
def jac(t, y, mu):
    dfdy = Numeric.ones((2,2), Numeric.Float) 
    dfdy[0, 0] = 0.0
    dfdy[0, 1] = 1.0
    dfdy[1, 0] = -2.0 * mu * y[0] * y[1] - 1.0
    dfdy[1, 1] = -mu * (y[0]**2 - 1.0)
    dfdt = Numeric.zeros((2,))
    
    return dfdy, dfdt
Example #27
0
def jac(t, y, mu):
    dfdy = Numeric.ones((2,2), Numeric.Float) 
    dfdy[0, 0] = 0.0
    dfdy[0, 1] = 0.0
    dfdy[1, 0] = 0.0
    dfdy[1, 1] = 0.0
    dfdt = Numeric.zeros((2,))
    dfdt[0] = 2
    dfdt[1] = 3 * 2 * t
    return dfdy, dfdt
Example #28
0
File: poly.py Project: pygsl/pygsl
    def taylor(self, xp):
        """
        This method converts the internal divided-difference representation of a
        polynomial to a Taylor expansion.

        input : xp
             xp ... point to expand about
        """
        w = Numeric.zeros(self.dd.shape, get_typecode(self.dd))
        return _poly.gsl_poly_dd_taylor(xp, self.dd, self.xa, w)
Example #29
0
File: fft.py Project: pygsl/pygsl
def real_example_simple():
    n = 1024 * 1024
    data = numx.zeros((n, ), numx.Int)
    data[n / 3:2 * n / 3] = 1
    result = fft.real_transform(data)
    #print "Nyqusit ->", result[0]
    result[11:] = 0
    final = fft.halfcomplex_inverse(result, n)
    #print final
    return
Example #30
0
    def taylor(self, xp):
        """
        This method converts the internal divided-difference representation of a
        polynomial to a Taylor expansion.

        input : xp
             xp ... point to expand about
        """
        w = Numeric.zeros(self.dd.shape, get_typecode(self.dd))
        return _poly.gsl_poly_dd_taylor(xp, self.dd, self.xa, w)
Example #31
0
def jac(t, y, mu):
    dfdy = Numeric.ones((2, 2), Numeric.Float)
    dfdy[0, 0] = 0.0
    dfdy[0, 1] = 0.0
    dfdy[1, 0] = 0.0
    dfdy[1, 1] = 0.0
    dfdt = Numeric.zeros((2, ))
    dfdt[0] = 2
    dfdt[1] = 3 * 2 * t
    return dfdy, dfdt
Example #32
0
def run():
    r = rng.rng()

    # slope
    a = 1.45
    # intercept
    b = 3.88

    # Generate the data
    n = 20
    i = numx.arange(n - 3)
    dx = 10.0 / (n - 1.0)
    e = r.uniform(n)
    x = -5.0 + i * dx
    y = a * x + b

    #outliers
    xo = numx.array([4.1, 3.5, 4.7])
    yo = numx.array([-6.0, -6.7, -8.3])

    x = numx.concatenate((x, xo))
    y = numx.concatenate((y, yo))

    X = numx.array([x * 0 + 1, x]).transpose()
    ws = fr.workspace(*((fr.ols, ) + X.shape))
    c_ols, cov_ols = ws.fit(X, y)
    ws = fr.workspace(*((fr.bisquare, ) + X.shape))
    c, cov = ws.fit(X, y)

    y_rob = numx.zeros(n, numx.float_)
    y_ols = numx.zeros(n, numx.float_)

    yerr_rob = numx.zeros(n, numx.float_)
    yerr_ols = numx.zeros(n, numx.float_)

    pygsl.set_debug_level(0)
    fr.est(X[0, :], c, cov)
    y_rob, yerr_rob = fr.est_vector(X, c, cov)
    pygsl.set_debug_level(0)
    y_ols, yerr_ols = fr.est_vector(X, c_ols, cov_ols)

    return x, y, (y_rob, yerr_rob), (y_ols, yerr_ols)
Example #33
0
def Heigenvectors(a, ws=None):
    """Heigenvectors(a, ws=None) -> (eval, evec)

    This function computes the eigenvalues and eigenvectors of the complex
    hermitian matrix A.The imaginary parts of the diagonal are assumed to be
    zero and are not referenced. The eigenvalues are stored in the vector
    eval and are unordered. The corresponding complex eigenvectors are
    stored in the columns of the matrix evec. For example, the eigenvector
    in the first column corresponds to the first eigenvalue. The
    eigenvectors are guaranteed to be mutually orthogonal and normalised to
    unit magnitude.  
    """
    n = a.shape[0]
    an = a.astype(_complex)
    eval = numx.zeros((n,), _float)
    evec = numx.zeros((n,n), _complex)
    if ws == None:
        ws = gslwrap.gsl_eigen_hermv_workspace(n)
    _gslwrap.gsl_eigen_hermv(an, eval, evec, ws)
    return (eval, evec)
Example #34
0
def eigenvectors(a, ws=None):
    """eigenvectors(a, ws=None) -> (eval, evec)

    This function computes the eigenvalues and eigenvectors of the real
    symmetric matrix a. The eigenvalues are stored in the vector eval
    and are unordered. The corresponding eigenvectors are stored in the
    columns of the matrix evec. For example, the eigenvector in the first
    column corresponds to the first eigenvalue. The eigenvectors are

    guaranteed to be mutually orthogonal and normalised to unit magnitude. 
    """
    n = a.shape[1]
    code = get_typecode(a)
    an = array_typed_copy(a, code)
    eval = numx.zeros((n,), code)
    evec = numx.zeros((n,n), code)
    if ws == None:
        ws = gslwrap.gsl_eigen_symmv_workspace(n)
    _gslwrap.gsl_eigen_symmv(an, eval, evec, ws)
    return (eval, evec)
Example #35
0
File: eigen.py Project: pygsl/pygsl
def Heigenvectors(a, ws=None):
    """Heigenvectors(a, ws=None) -> (eval, evec)

    This function computes the eigenvalues and eigenvectors of the complex
    hermitian matrix A.The imaginary parts of the diagonal are assumed to be
    zero and are not referenced. The eigenvalues are stored in the vector
    eval and are unordered. The corresponding complex eigenvectors are
    stored in the columns of the matrix evec. For example, the eigenvector
    in the first column corresponds to the first eigenvalue. The
    eigenvectors are guaranteed to be mutually orthogonal and normalised to
    unit magnitude.  
    """
    n = a.shape[0]
    an = a.astype(_complex)
    eval = numx.zeros((n, ), _float)
    evec = numx.zeros((n, n), _complex)
    if ws == None:
        ws = gslwrap.gsl_eigen_hermv_workspace(n)
    _gslwrap.gsl_eigen_hermv(an, eval, evec, ws)
    return (eval, evec)
Example #36
0
File: eigen.py Project: pygsl/pygsl
def eigenvectors(a, ws=None):
    """eigenvectors(a, ws=None) -> (eval, evec)

    This function computes the eigenvalues and eigenvectors of the real
    symmetric matrix a. The eigenvalues are stored in the vector eval
    and are unordered. The corresponding eigenvectors are stored in the
    columns of the matrix evec. For example, the eigenvector in the first
    column corresponds to the first eigenvalue. The eigenvectors are

    guaranteed to be mutually orthogonal and normalised to unit magnitude. 
    """
    n = a.shape[1]
    code = get_typecode(a)
    an = array_typed_copy(a, code)
    eval = numx.zeros((n, ), code)
    evec = numx.zeros((n, n), code)
    if ws == None:
        ws = gslwrap.gsl_eigen_symmv_workspace(n)
    _gslwrap.gsl_eigen_symmv(an, eval, evec, ws)
    return (eval, evec)
Example #37
0
def complex_example():
    n = 630
    space = fft.complex_workspace(n)
    wavetable = fft.complex_wavetable(n)
    print space.get_type()
    print wavetable.get_type()
    print wavetable.get_factors()
    data = numx.zeros((630,), numx.Complex)
    data[:11] = 1.0
    data[11:] = 1.0
    d = data[:]
    fft.complex_forward(data, space, wavetable)
Example #38
0
File: fft.py Project: pygsl/pygsl
def complex_example():
    n = 630
    space = fft.complex_workspace(n)
    wavetable = fft.complex_wavetable(n)
    print(space.get_type())
    print(wavetable.get_type())
    print(wavetable.get_factors())
    data = numx.zeros((630, ), numx.Complex)
    data[:11] = 1.0
    data[11:] = 1.0
    d = data[:]
    fft.complex_forward(data, space, wavetable)
Example #39
0
def jac(t, y, mu):
    #print "--> jac", t, y
    dfdy = numx.ones((2, 2), Float)
    dfdy[0, 0] = 0.0
    dfdy[0, 1] = 1.0
    dfdy[1, 0] = -2.0 * mu * y[0] * y[1] - 1.0
    dfdy[1, 1] = -mu * (y[0]**2 - 1.0)
    #print "dfdy[0, 0]", dfdy[0, 0]
    #print "dfdy[0, 1]", dfdy[0, 1]
    #print "dfdy[1, 0]", dfdy[1, 0]
    #print "dfdy[1, 1]", dfdy[1, 1]
    dfdt = numx.zeros((2, ))
    return dfdy, dfdt
Example #40
0
def jac(t, y, mu):
    #print "--> jac", t, y
    dfdy = numx.ones((2,2), Float) 
    dfdy[0, 0] = 0.0
    dfdy[0, 1] = 1.0
    dfdy[1, 0] = -2.0 * mu * y[0] * y[1] - 1.0
    dfdy[1, 1] = -mu * (y[0]**2 - 1.0)
    #print "dfdy[0, 0]", dfdy[0, 0]
    #print "dfdy[0, 1]", dfdy[0, 1]
    #print "dfdy[1, 0]", dfdy[1, 0]
    #print "dfdy[1, 1]", dfdy[1, 1] 
    dfdt = numx.zeros((2,))
    return dfdy, dfdt
Example #41
0
def eigenvalues(a, ws=None):
    """eigenvalues(a, ws=None) -> array
    
    This function computes the eigenvalues of the real symmetric matrix a.
    The eigenvalues are returned as NumPy array and are unordered. 
    """
    n = a.shape[1]
    code = get_typecode(a)
    an = array_typed_copy(a, code)
    eval = numx.zeros((n,), code)
    if ws == None:
        ws = gslwrap.gsl_eigen_symm_workspace(n)
    _gslwrap.gsl_eigen_symm(an, eval, ws)
    return eval
Example #42
0
File: eigen.py Project: pygsl/pygsl
def eigenvalues(a, ws=None):
    """eigenvalues(a, ws=None) -> array
    
    This function computes the eigenvalues of the real symmetric matrix a.
    The eigenvalues are returned as NumPy array and are unordered. 
    """
    n = a.shape[1]
    code = get_typecode(a)
    an = array_typed_copy(a, code)
    eval = numx.zeros((n, ), code)
    if ws == None:
        ws = gslwrap.gsl_eigen_symm_workspace(n)
    _gslwrap.gsl_eigen_symm(an, eval, ws)
    return eval
Example #43
0
def Heigenvalues(a, ws=None):
    """Heigenvalues(a, ws=None) -> eval

    This function computes the eigenvalues of the complex hermitian matrix a.
    The imaginary parts of the diagonal are assumed to be zero and are not
    referenced. The eigenvalues are stored in the vector eval and are
    unordered. 
    """
    n = a.shape[1]
    an = a.astype(_complex)
    eval = numx.zeros((n,), _float)
    if ws == None:
        ws = gslwrap.gsl_eigen_herm_workspace(n)
    _gslwrap.gsl_eigen_herm(an, eval, ws)
    return eval
Example #44
0
File: eigen.py Project: pygsl/pygsl
def Heigenvalues(a, ws=None):
    """Heigenvalues(a, ws=None) -> eval

    This function computes the eigenvalues of the complex hermitian matrix a.
    The imaginary parts of the diagonal are assumed to be zero and are not
    referenced. The eigenvalues are stored in the vector eval and are
    unordered. 
    """
    n = a.shape[1]
    an = a.astype(_complex)
    eval = numx.zeros((n, ), _float)
    if ws == None:
        ws = gslwrap.gsl_eigen_herm_workspace(n)
    _gslwrap.gsl_eigen_herm(an, eval, ws)
    return eval
Example #45
0
def run():
    N = 1024
    x = numx.arange(N) * (numx.pi * 2 / N)
    y = numx.sin(x)

    b = bspline(10, nbreak)
    b.knots_uniform(x[0], x[-1])
    X = numx.zeros((N, ncoeffs))
    X = b.eval_vector(x)
    c, cov, chisq = multifit.linear(X, y)

    res_x = x[::N / 64]
    X = b.eval_vector(res_x)
    res_y, res_y_err = multifit.linear_est_matrix(X, c, cov)

    pylab.plot(x, y, '-')
    pylab.errorbar(res_x, res_y, fmt='g-', xerr=res_y_err)
Example #46
0
def run(array):
    # Initalise the wavelet and the workspace
    w = wavelet.daubechies(4)
    ws = wavelet.workspace(len(array))

    # Transform forward
    result = w.transform_forward(array, ws)

    # Select the largest 20 coefficients
    abscoeff = numx.absolute(result)
    indices = numx.argsort(abscoeff)  # ascending order

    tmp = numx.zeros(result.shape, numx.float_)
    for i in indices[-20:]:
        tmp[i] = result[i]  # Set all others to zero

    # And back
    result2 = w.transform_inverse(tmp, ws)
Example #47
0
def run(array):
    # Initalise the wavelet and the workspace
    w = wavelet.daubechies(4)
    ws = wavelet.workspace(len(array))
    
    # Transform forward
    result = w.transform_forward(array, ws)

    # Select the largest 20 coefficients
    abscoeff = numx.absolute(result)
    indices  = numx.argsort(abscoeff) # ascending order

    tmp = numx.zeros(result.shape, numx.float_)
    for i in indices[-20:]:
        tmp[i] = result[i] # Set all others to zero

    # And back
    result2 = w.transform_inverse(tmp, ws)
Example #48
0
def run():
    N = 1024
    x = numx.arange(N) * (numx.pi * 2 / N)
    y = numx.sin(x)


    b = bspline(10, nbreak)
    b.knots_uniform(x[0], x[-1])
    X = numx.zeros((N, ncoeffs))
    X = b.eval_vector(x)
    c, cov, chisq = multifit.linear(X, y)


    res_x = x[::N/64]
    X = b.eval_vector(res_x)
    res_y, res_y_err = multifit.linear_est_matrix(X, c, cov)

    pylab.plot(x,y, '-')
    pylab.errorbar(res_x, res_y, fmt='g-', xerr=res_y_err)    
Example #49
0
def compress(data):
    n = len(data)
    #w = wavelet.daubechies(4)
    #w = wavelet.daubechies(6)
    #w = wavelet.daubechies(8)
    #w = wavelet.daubechies(10)
    #w = wavelet.daubechies(12)
    #w = wavelet.daubechies(14)
    #w = wavelet.daubechies(16)
    #w = wavelet.daubechies(18)
    #w = wavelet.daubechies_centered(20)
    #w = wavelet.haar(2)
    w = wavelet.bspline(103)
    w = wavelet.bspline(309)
    wavefreq = w.transform_forward(data)
    wavefreqred = numx.zeros(wavefreq.shape, wavefreq.dtype)
    cutfreq = 16
    wavefreqred[:cutfreq] = wavefreq[:cutfreq]
    resampled = w.transform_inverse(wavefreqred)
    return wavefreq, resampled
Example #50
0
def compress(data):
    n = len(data)
    #w = wavelet.daubechies(4)
    #w = wavelet.daubechies(6)
    #w = wavelet.daubechies(8)
    #w = wavelet.daubechies(10)
    #w = wavelet.daubechies(12)
    #w = wavelet.daubechies(14)
    #w = wavelet.daubechies(16)
    #w = wavelet.daubechies(18)
    #w = wavelet.daubechies_centered(20)
    #w = wavelet.haar(2)
    w = wavelet.bspline(103)
    w = wavelet.bspline(309)
    wavefreq = w.transform_forward(data);
    wavefreqred = numx.zeros(wavefreq.shape, wavefreq.dtype)
    cutfreq = 16
    wavefreqred[:cutfreq] = wavefreq[:cutfreq]
    resampled = w.transform_inverse(wavefreqred)
    return wavefreq, resampled
Example #51
0
def run():
    r = rng.rng()
    bw = bspline(4, nbreak)

    # Data to be fitted
    x = 15. / (N - 1) * numx.arange(N)
    y = numx.cos(x) * numx.exp(0.1 * x)
    sigma = .1
    w = 1.0 / sigma**2 * numx.ones(N)
    dy = r.gaussian(sigma, N)
    y = y + dy

    # use uniform breakpoints on [0, 15]
    bw.knots_uniform(0.0, 15.0)

    X = numx.zeros((N, ncoeffs))
    for i in range(N):
        B = bw.eval(x[i])
        X[i, :] = B

    # do the fit
    c, cov, chisq = multifit.wlinear(X, w, y,
                                     multifit.linear_workspace(N, ncoeffs))

    # output the smoothed curve
    res_y = []
    res_y_err = []
    for i in range(N):
        B = bw.eval(x[i])
        yi, yi_err = multifit.linear_est(B, c, cov)
        res_y.append(yi)
        res_y_err.append(yi_err)
        #print yi, yerr
    res_y = numx.array(res_y)
    res_y_err = numx.array(res_y_err)
    return (
        x,
        y,
    ), (x, res_y), res_y_err
Example #52
0
def run():
    r = rng.rng()
    bw = bspline(4, nbreak)


    # Data to be fitted
    x = 15. / (N-1) * numx.arange(N)
    y = numx.cos(x) * numx.exp(0.1 * x)    
    sigma = .1
    w = 1.0 / sigma**2 * numx.ones(N) 
    dy = r.gaussian(sigma, N)
    y  = y + dy

    # use uniform breakpoints on [0, 15] 
    bw.knots_uniform(0.0, 15.0)

    X = numx.zeros((N, ncoeffs))
    for i in range(N):
        B = bw.eval(x[i])
        X[i,:] = B
        
    # do the fit
    c, cov, chisq = multifit.wlinear(X, w, y, multifit.linear_workspace(N, ncoeffs))

    # output the smoothed curve
    res_y = []
    res_y_err = []
    for i in range(N):
        B = bw.eval(x[i])
        yi, yi_err = multifit.linear_est(B, c, cov)
        res_y.append(yi)
        res_y_err.append(yi_err)
        #print yi, yerr
    res_y = numx.array(res_y)
    res_y_err = numx.array(res_y_err)    
    return (x, y,), (x, res_y),  res_y_err
Example #53
0
def real_example_simple():
    n = 1024*1024
    data = numx.zeros((n,), numx.Int)
    data[n/3:2*n/3] = 1
    result =  fft.real_transform(data)
    #print "Nyqusit ->", result[0]
    result[11:] = 0
    final = fft.halfcomplex_inverse(result, n)    
    #print final
    return
    import Gnuplot
    g = Gnuplot.Gnuplot()
    g.plot(Gnuplot.Data(data, with='line'),
           Gnuplot.Data(final, with='linespoints'),)
    raw_input()

def halfcomplex_radix2_unpack():
    n = 32   
    a = numx.arange(n)
    c = numx.zeros((n,))
    c[1:n/2+1]=a[1::2]
    c[n/2+1:]=a[-2:1:-2]    
    print c
    print fft.halfcomplex_radix2_unpack(c)
    
def doc():
    help(fft)
    
if __name__ == '__main__':
    import pygsl
    pygsl.set_debug_level(0)
    complex_example_simple()
    complex_example()
    real_example_simple()
    real_example_simple1()
    halfcomplex_radix2_unpack()
Example #54
0
def func(t, y, mu):
    f = Numeric.zeros((2,), Numeric.Float) * 1.0
    f[0] = 2 * t
    f[1] = 3 * t**2
    return f
Example #55
0
#   Census Bureau, at http://www.census.gov/cgi-bin/gazetteer */
cities =(City("Santa Fe",       -105.95, 35.68,),
         City("Phoenix",        -112.07, 33.54,),
         City("Albuquerque",    -106.62, 35.12,),
         City("Clovis",         -103.20, 34.41,),
         City("Durango",        -107.87, 37.29,),
         City("Dallas",          -96.77, 32.79,),
         City("Tesuque",        -105.92, 35.77,),
         City("Grants",         -107.84, 35.15,),
         City("Los Alamos",     -106.28, 35.89,),
         City("Las Cruces",     -106.76, 32.34,),
         City("Cortez",         -108.58, 37.35,),
         City("Gallup",         -108.74, 35.52,))

n_cities = len(cities)
distance_matrix = numx.zeros((n_cities, n_cities))

cities_vec = numx.array(map(lambda x: x.GetData(), cities))
for i in range(len(cities)):
    cities[i].SetNumber(i)
    
earth_radius = 6375.000
#n_cities = 6

# distance between two cities
def city_distance(c):
    la = c[:,0]
    lo = c[:,1]
    sla = sin(la*pi/180)
    cla = cos(la*pi/180)
    slo = sin(lo*pi/180)
Example #56
0
def func(t, y, mu):
    f = numx.zeros((2,), ) * 1.0
    f[0] = y[1]
    f[1] = -y[0] - mu * y[1] * (y[0] ** 2 -1);
    return f