示例#1
0
def test_nothing():
    n = 128
    data = np.random.randn(n)
    Gf = fit_gaussian.fit_gaussian(data)

    assert Gf.amplitude() < 4
    assert np.std(Gf.histogram(n)-data)<4
示例#2
0
 def rate_profile(self,hdr,candidate,profile,std,cache):
     if "gaussian" in cache:
         G = cache["gaussian"]
     else:
         G = fit_gaussian.fit_gaussian(profile)
         cache["gaussian"] = G
     return self.rate_gaussian_profile(hdr,candidate,profile,std,G,cache)
示例#3
0
def check_fit_quality(G,noise_amp,n):
    true = G.histogram(n)
    noise = np.random.randn(n)*noise_amp*G.amplitude()
    data = true + noise
    Gf = fit_gaussian.fit_gaussian(data)

    assert np.abs(Gf.amplitude()-G.amplitude())/G.amplitude()<0.01
示例#4
0
def plot_residuals(data):

    n = len(data)
    xs = np.arange(n)/float(n)

    test_ks = np.exp(np.linspace(np.log(0.1),np.log(1000),1000))
    G = fit_gaussian.fit_gaussian(data)

    plt.figure()
    resids = [fit_gaussian.rms_residual(k,data) for k in test_ks]
    plt.loglog(test_ks,resids,color="green")
    best_k = test_ks[np.argmin(resids)]
    plt.axvline(best_k,color="green")
    plt.axvline(G.k,color="cyan")

    plt.figure()
    mue, ae, be = fit_gaussian.fit_all_but_k(best_k, data)
    plt.plot(xs, data, color="black", label="data")
    plt.plot(xs, (ae*fit_gaussian.vonmises_histogram(best_k,mue,n)+be),
            color="green", label="exhaustive best fit")
    plt.plot(xs, G.histogram(n), color="cyan", label="best fit")
    plt.plot([G.mu,G.mu],[G.b,G.b+G.amplitude(n)], color="red", label="height")

    print "Amplitude over RMS:", G.amplitude(n)/np.std(data-G.histogram(n))

    plt.legend(loc="best")

    return data