Пример #1
0
def test_trim_array_one_origin():
    y, x = np.indices((100, 100))
    a = x*y
    ta, tx, ty = trim_array(a, 21, (50, 95), origin=1)
    npt.assert_array_equal(ta, a[85:, 40:62])
    check.equal(tx, 11)
    check.equal(ty, 11)
Пример #2
0
def test_trim_array_even():
    y, x = np.indices((100, 100))
    a = x*y
    ta, tx, ty = trim_array(a, 20, (50, 95))
    npt.assert_array_equal(ta, a[85:, 40:61])
    check.equal(tx, 10)
    check.equal(ty, 10)
Пример #3
0
 def test_trim_array_even(self):
     y, x = np.indices((100, 100))
     a = x*y
     ta, tx, ty = trim_array(a, 20, (50, 95))
     assert_equal(ta, a[85:, 40:61])
     assert_equal(tx, 10)
     assert_equal(ty, 10)
Пример #4
0
def test_trim_array_no_indices():
    y, x = np.indices((100, 100))
    a = x*y
    ta, tx, ty = trim_array(a, 21, (50, 95))
    npt.assert_array_equal(ta, a[84:, 39:61])
    check.equal(tx, 11)
    check.equal(ty, 11)
Пример #5
0
 def test_trim_array_no_indices(self):
     y, x = np.indices((100, 100))
     a = x*y
     ta, tx, ty = trim_array(a, 21, (50, 95))
     assert_equal(ta, a[84:, 39:61])
     assert_equal(tx, 11)
     assert_equal(ty, 11)
Пример #6
0
def gen_stars_gaussian(size, x, y, flux, sigma, theta):
    """Generate stars image to add to background."""
    im = np.zeros(size)
    grid_y, grid_x = np.indices(size)

    try:
        sigma_x, sigma_y = sigma
    except (TypeError, ValueError):
        sigma_x = sigma_y = sigma

    if check_number(sigma_x):
        sigma_x = [sigma_x] * len(x)

    if check_number(sigma_y):
        sigma_y = [sigma_y] * len(x)

    if check_number(theta):
        theta = [theta] * len(x)

    for xi, yi, fi, sxi, syi, ti in zip(x, y, flux, sigma_x, sigma_y, theta):
        imi, gxi, gyi = trim_array(np.zeros_like(im),
                                   box_size=10 * sxi,
                                   position=(xi, yi),
                                   indices=(grid_y, grid_x))
        imi += gaussian_2d(gxi, gyi, xi, yi, sxi, syi, ti, fi, 0)
        im[gyi.min():gyi.max() + 1, gxi.min():gxi.max() + 1] += imi

    return im
Пример #7
0
def test_trim_array_left():
    y, x = np.indices((100, 100))
    a = x*y
    ta, tx, ty = trim_array(a, 21, (5, 50), (y, x))
    npt.assert_array_equal(ta, a[39:61, :16])
    npt.assert_array_equal(tx, x[39:61, :16])
    npt.assert_array_equal(ty, y[39:61, :16])
    check.equal(np.min(tx), 0)
    check.equal(np.max(tx), 15)
    check.equal(np.min(ty), 39)
    check.equal(np.max(ty), 60)
    check.equal(np.min(ta), 0*39)
    check.equal(np.max(ta), 15*60)
Пример #8
0
def test_trim_array_right():
    y, x = np.indices((100, 100))
    a = x*y
    ta, tx, ty = trim_array(a, 21, (95, 50), (y, x))
    npt.assert_array_equal(ta, a[39:61, 84:])
    npt.assert_array_equal(tx, x[39:61, 84:])
    npt.assert_array_equal(ty, y[39:61, 84:])
    check.equal(np.min(tx), 84)
    check.equal(np.max(tx), 99)
    check.equal(np.min(ty), 39)
    check.equal(np.max(ty), 60)
    check.equal(np.min(ta), 84*39)
    check.equal(np.max(ta), 99*60)
Пример #9
0
def test_trim_array_centered():
    y, x = np.indices((100, 100))
    a = x*y
    ta, tx, ty = trim_array(a, 21, (50, 50), (y, x))
    npt.assert_array_equal(ta, a[39:61, 39:61])
    npt.assert_array_equal(tx, x[39:61, 39:61])
    npt.assert_array_equal(ty, y[39:61, 39:61])
    check.equal(np.min(tx), 39)
    check.equal(np.max(tx), 60)
    check.equal(np.min(ty), 39)
    check.equal(np.max(ty), 60)
    check.equal(np.min(ta), 39*39)
    check.equal(np.max(ta), 60*60)
Пример #10
0
def test_trim_array_top():
    y, x = np.indices((100, 100))
    a = x*y
    ta, tx, ty = trim_array(a, 21, (50, 95), (y, x))
    npt.assert_array_equal(ta, a[84:, 39:61])
    npt.assert_array_equal(tx, x[84:, 39:61])
    npt.assert_array_equal(ty, y[84:, 39:61])
    check.equal(np.min(ty), 84)
    check.equal(np.max(ty), 99)
    check.equal(np.min(tx), 39)
    check.equal(np.max(tx), 60)
    check.equal(np.min(ta), 84*39)
    check.equal(np.max(ta), 99*60)
Пример #11
0
def test_trim_array_bottom():
    y, x = np.indices((100, 100))
    a = x*y
    ta, tx, ty = trim_array(a, 21, (50, 5), (y, x))
    npt.assert_array_equal(ta, a[:16, 39:61])
    npt.assert_array_equal(tx, x[:16, 39:61])
    npt.assert_array_equal(ty, y[:16, 39:61])
    check.equal(np.min(ty), 0)
    check.equal(np.max(ty), 15)
    check.equal(np.min(tx), 39)
    check.equal(np.max(tx), 60)
    check.equal(np.min(ta), 0*39)
    check.equal(np.max(ta), 15*60)
Пример #12
0
def gen_stars_moffat(size, x, y, flux, fwhm):
    """Generate stars image to add to background."""
    beta = 1.5
    alpha = fwhm / np.sqrt(2**(1 / beta) - 1)
    im = np.zeros(size)
    grid_y, grid_x = np.indices(size)
    for xi, yi, fi in zip(x, y, flux):
        imi, gxi, gyi = trim_array(np.zeros_like(im),
                                   box_size=5 * fwhm,
                                   position=(xi, yi),
                                   indices=(grid_y, grid_x))
        imi += moffat_2d(gxi, gyi, xi, yi, alpha, beta, fi, 0)
        im[gyi.min():gyi.max() + 1, gxi.min():gxi.max() + 1] += imi

    return im