示例#1
0
def test_find_center_no_star():
    # No star anywhere near the original guess
    image = make_gaussian_sources_image(SHAPE, STARS)
    # Offset the mean from zero to avoid nan center
    noise = make_noise_image(SHAPE, distribution='gaussian',
                             mean=1000, stddev=5, random_state=RANDOM_SEED)
    cen = spf.find_center(image + noise, [50, 200], max_iters=10)
    assert (np.abs(cen[0] - 50) > 1) and (np.abs(cen[1] - 200) > 1)
示例#2
0
def test_find_center_noise_good_guess():
    image = make_gaussian_sources_image(SHAPE, STARS)
    noise = make_noise_image(SHAPE, distribution='gaussian', mean=0, stddev=5,
                             random_state=RANDOM_SEED)
    # Trying again with several iterations should work
    cen3 = spf.find_center(image + noise, [31, 41], max_iters=10)
    # Tolerance chosen based on some trial and error
    np.testing.assert_allclose(cen3, [30, 40], atol=0.02)
示例#3
0
def test_find_center_noise_bad_guess():
    image = make_gaussian_sources_image(SHAPE, STARS)
    noise = make_noise_image(SHAPE, distribution='gaussian', mean=0, stddev=5,
                             random_state=RANDOM_SEED)
    cen2 = spf.find_center(image + noise, [40, 50], max_iters=1)
    # Bad initial guess, noise, should take more than one try...
    with pytest.raises(AssertionError):
        np.testing.assert_allclose(cen2, [30, 40])
示例#4
0
def test_radial_profile():
    image = make_gaussian_sources_image(SHAPE, STARS)
    for row in STARS:
        cen = spf.find_center(image, (row['x_mean'], row['y_mean']),
                              max_iters=10)
        print(row)
        r_ex, r_a, radprof = spf.radial_profile(image, cen)
        r_exs, r_as, radprofs = spf.radial_profile(image, cen,
                                                   return_scaled=False)

        # Numerical value below is integral of input 2D gaussian, 2pi A sigma^2
        expected_integral = 2 * np.pi * row['amplitude'] * row['x_stddev']**2
        print(expected_integral, radprofs.sum())
        np.testing.assert_allclose(radprofs.sum(), expected_integral, atol=50)
示例#5
0
def test_find_center_no_noise_star_at_edge():
    # Trying to put the star at the edge of the initial guess
    image = make_gaussian_sources_image(SHAPE, STARS)
    cen = spf.find_center(image, [45, 65], max_iters=10)
    np.testing.assert_allclose(cen, [30, 40])
示例#6
0
def test_find_center_no_noise_good_guess():
    image = make_gaussian_sources_image(SHAPE, STARS)
    # Good initial guess, no noise, should converge in one try
    cen1 = spf.find_center(image, (31, 41), max_iters=1)
    np.testing.assert_allclose(cen1, [30, 40])