Ejemplo n.º 1
0
def minimize(args):
    f_index, g_index = args
    pol_f_index = f_index[-2:]
    pol_g_index = g_index[-2:]
    data = dataFromShared()
    f = data[f_index]
    g = data[g_index]
    df, dg = dArraysFromShared()
    df = df[pol_f_index]
    dg = dg[pol_g_index]    
    fmin = lambda tau: -correlate(tau, f, g, df, dg) 
    appr = -f.argmax() + g.argmax()
    halfwidth = np.sum(f < f.max() / 2) / 2
    try: 
        return brent(fmin, brack=(appr - halfwidth, appr, appr + halfwidth))
    except ValueError:
        return -123.4
Ejemplo n.º 2
0
    import time
    chan = 180
   
    f = np.loadtxt("/home/gleb/code/C/fit_spectra/sp.dat")
    pos = np.unravel_index(np.argmax(f), f.shape)
    print pos, f.shape
    findex = 123
    gindex = 13
    shift = 13
    g = np.roll(f[gindex], shift)
    f = f[findex] 
    print f.shape
    df = np.diff(f)
    dg = np.diff(g)
    
    fmin = lambda tau: -correlate(tau, f, g, df, dg) 
    halfwidth = np.sum(f < f.max() / 2) / 2
    appr = -f.argmax() + g.argmax()
    t = time.time()
    res = brent(fmin, brack=(appr-halfwidth,appr,appr+halfwidth))
    t2 = time.time()
    print t2 - t
    res2 = leastsq(fmin, x0=[appr], disp=0)
    print time.time() - t2
#    res = pool.map(minimize, TASKS, chunksize=340)
    
    print res, res2
#    fit = np.poly1d(np.polyfit(np.arange(len(f[0])), f[0], 12))
    plt.plot(f, label='f')
    plt.plot(g, label='g')
    plt.plot(np.roll(g, int(-res)), label='res')