예제 #1
0
def test_gaussian_bounds():
    x = np.linspace(-5., 5., 200)
    y = 2 * np.exp(-0.5 * (x - 1.3)**2 / 0.7**2)
    y += np.random.normal(0., 0.1, x.shape)

    gs = fit_gaussian(x, y,
                      bounds={"mean": [1., 1.6], "amplitude": [1.7, 2.3]})
예제 #2
0
파일: efsearch.py 프로젝트: InesPM/HENDRICS
def fit(frequencies,
        stats,
        center_freq,
        width=None,
        obs_length=None,
        baseline=0):
    estimated_amp = stats[np.argmin(np.abs(frequencies - center_freq))]

    if obs_length is not None:
        s = fit_sinc(frequencies,
                     stats - baseline,
                     obs_length=obs_length,
                     amp=estimated_amp,
                     mean=center_freq)
    else:
        df = frequencies[1] - frequencies[0]
        if width is None:
            width = 2 * df
        s = fit_gaussian(frequencies,
                         stats - baseline,
                         stddev=width,
                         amplitude=estimated_amp,
                         mean=center_freq)

    return s
예제 #3
0
def test_gaussian_bounds():
    x = np.linspace(-5., 5., 200)
    y = 2 * np.exp(-0.5 * (x - 1.3)**2 / 0.7**2)
    y += np.random.normal(0., 0.1, x.shape)

    gs = fit_gaussian(x, y,
                      bounds={"mean": [1., 1.6], "amplitude": [1.7, 2.3]})
예제 #4
0
def test_gaussian_fixed():
    x = np.linspace(-5., 5., 200)
    y = 2 * np.exp(-0.5 * (x - 1.3)**2 / 0.7**2)
    y += np.random.normal(0., 0.1, x.shape)

    gs = fit_gaussian(x, y, mean=1.3, fixed={"mean": True, "amplitude": False})
    assert gs.mean.fixed
    assert not gs.amplitude.fixed
예제 #5
0
def test_gaussian_fixed():
    x = np.linspace(-5., 5., 200)
    y = 2 * np.exp(-0.5 * (x - 1.3)**2 / 0.7**2)
    y += np.random.normal(0., 0.1, x.shape)

    gs = fit_gaussian(x, y, mean=1.3, fixed={"mean": True, "amplitude": False})
    assert gs.mean.fixed
    assert not gs.amplitude.fixed
예제 #6
0
def test_gaussian_function():
    x = np.linspace(-5., 5., 200)
    y = 2 * np.exp(-0.5 * (x - 1.3)**2 / 0.7**2)
    y += np.random.normal(0., 0.1, x.shape)

    gs = fit_gaussian(x, y)

    assert np.abs(gs.mean - 1.3) < 0.1
    assert np.abs(gs.amplitude - 2) < 0.1
    assert np.abs(gs.stddev - 0.7) < 0.1
예제 #7
0
def test_gaussian_function():
    x = np.linspace(-5., 5., 200)
    y = 2 * np.exp(-0.5 * (x - 1.3)**2 / 0.7**2)
    y += np.random.normal(0., 0.1, x.shape)

    gs = fit_gaussian(x, y)

    assert np.abs(gs.mean - 1.3) < 0.1
    assert np.abs(gs.amplitude - 2) < 0.1
    assert np.abs(gs.stddev - 0.7) < 0.1
예제 #8
0
def test_gaussian_tied():
    x = np.linspace(-5., 5., 200)
    y = 2 * np.exp(-0.5 * (x - 1.3)**2 / 0.7**2)
    y += np.random.normal(0., 0.1, x.shape)

    def tiedgaussian(model):
        mean = model.amplitude / 2
        return mean

    gs = fit_gaussian(x, y, tied={"mean": tiedgaussian})

    assert np.abs(gs.mean/gs.amplitude - 0.5) < 0.1
예제 #9
0
def test_gaussian_tied():
    x = np.linspace(-5., 5., 200)
    y = 2 * np.exp(-0.5 * (x - 1.3)**2 / 0.7**2)
    y += np.random.normal(0., 0.1, x.shape)

    def tiedgaussian(model):
        mean = model.amplitude / 2
        return mean

    gs = fit_gaussian(x, y, tied={"mean": tiedgaussian})

    assert np.abs(gs.mean/gs.amplitude - 0.5) < 0.1