Exemplo n.º 1
0
def test_find_peak_success():
    data = np.zeros((21, 21))
    y, x = np.indices(data.shape)
    data = 100 * np.exp(-0.5 * ((x - 8)**2 + (y - 11)**2))
    coord, fit_status, fit_box = _find_peak(data, peak_fit_box=3)
    assert fit_status == 'SUCCESS'
    assert np.allclose(coord, (8, 11), rtol=0, atol=1e-6)
Exemplo n.º 2
0
def test_find_peak_fail_lstsq():
    data = np.zeros((11, 21))
    data[6, 7] = 10
    data[8, 7] = np.nan
    coord, fit_status, fit_box = _find_peak(data, peak_fit_box=7)
    assert fit_status == 'WARNING:CENTER-OF-MASS'
    assert np.allclose(coord, (7, 6), rtol=0, atol=1e-6)
Exemplo n.º 3
0
def test_find_peak_fit_over_edge():
    data = np.zeros((21, 21))
    y, x = np.indices(data.shape)
    data = 100 * np.exp(-0.5 * (x**2 + (y - 11)**2))
    data[:, 0] = 0.0
    coord, fit_status, fit_box = _find_peak(data, peak_fit_box=7)
    assert fit_status == 'WARNING:EDGE'
    assert np.allclose(coord, (1, 11), rtol=0, atol=1e-6)
Exemplo n.º 4
0
def test_find_peak_badfit():
    data = np.zeros((21, 21))
    y, x = np.indices(data.shape)
    data = x + y
    data[(x < 5) | (x > 11) | (y < 8) | (y > 14)] = 0
    coord, fit_status, fit_box = _find_peak(data, peak_fit_box=7)
    assert fit_status == 'WARNING:BADFIT'
    assert np.allclose(coord, (11, 14), rtol=0, atol=1e-6)
Exemplo n.º 5
0
def test_find_peak_negative_peak():
    data = np.zeros((11, 11))
    i = random.choice(range(2, 9))
    j = random.choice(range(2, 9))
    data[i, j] = -1.0
    coord, fit_status, fit_box = _find_peak(data, peak_fit_box=2)
    assert fit_status == 'ERROR:NODATA'
    assert np.allclose(coord, (5, 5), rtol=0, atol=_ATOL)
Exemplo n.º 6
0
def test_find_peak_nodata_after_fail():
    data = np.zeros((21, 21))
    i = random.choice(range(6, 14))
    j = random.choice(range(6, 14))
    data[i, j] = 1.0
    data[i - 1, j - 1] = -1.0
    data[i + 1, j + 1] = np.nan
    coord, fit_status, fit_box = _find_peak(data, peak_fit_box=5)
    assert fit_status == 'ERROR:NODATA'
    assert np.allclose(coord, (10, 10), rtol=0, atol=_ATOL)
Exemplo n.º 7
0
def test_find_peak_tiny_box_1pix():
    data = np.zeros((4, 4))
    mask = np.zeros((4, 4), dtype=np.bool_)

    mask[2, 2] = True
    data[2, 2] = 1.0
    coord0 = (2, 2)

    coord, fit_status, fit_box = _find_peak(data, peak_fit_box=5, mask=mask)
    assert np.allclose(coord, coord0, rtol=0, atol=_ATOL)
    assert fit_status == 'WARNING:CENTER-OF-MASS'
Exemplo n.º 8
0
def test_find_peak_nodata_after_fail():
    data = np.zeros((21, 21))
    i = random.choice(range(6, 14))
    j = random.choice(range(6, 14))
    data[i, j] = 1.0
    data[i - 1, j - 1] = -1.0
    data[i + 1, j + 1] = np.nan
    coord, fit_status, fit_box = _find_peak(data, peak_fit_box=5)
    assert fit_status == 'SUCCESS'
    shift = 0.53583061889252015
    assert np.allclose(coord, (j + shift, i + shift), rtol=0, atol=20 * _ATOL)
Exemplo n.º 9
0
def test_find_peak_few_data_center_of_mass():
    data = np.zeros((20, 20))
    mask = np.zeros((20, 20), dtype=np.bool_)

    col = random.choice(range(5, 16))
    data[9, col] = 1.0
    mask[9, col] = True
    coord0 = (col, 9)

    coord, fit_status, fit_box = _find_peak(data, mask=mask)
    assert fit_status == 'WARNING:CENTER-OF-MASS'
    assert np.allclose(coord, coord0, rtol=0, atol=_ATOL)
Exemplo n.º 10
0
def test_find_peak_few_data_for_center_of_mass():
    data = np.zeros((21, 21))
    mask = np.zeros((21, 21), dtype=np.bool_)
    i = random.choice(range(5, 16))
    j = random.choice(range(5, 16))
    data[i, j] = 1.0
    data[i - 1, j - 1] = -1.0
    mask[i, j] = True
    mask[i - 1, j - 1] = True
    coord, fit_status, fit_box = _find_peak(data, peak_fit_box=3, mask=mask)
    assert fit_status == 'ERROR:NODATA'
    assert np.allclose(coord, (10, 10), rtol=0, atol=_ATOL)
Exemplo n.º 11
0
def test_find_peak_nodata_peak_is_invalid():
    data = np.zeros((14, 17))
    mask = np.zeros((14, 17), dtype=np.bool_)

    col = random.choice(range(17))
    mask[9, col] = True
    data[9, 4] = 1.0
    mask[9, 4] = False
    coord0 = (8, 6.5)

    coord, fit_status, fit_box = _find_peak(data, peak_fit_box=5, mask=mask)
    assert fit_status == 'ERROR:NODATA'
    assert np.allclose(coord, coord0, rtol=0, atol=_ATOL)
Exemplo n.º 12
0
def test_find_peak_nodata_all_zeros(shape, mask):
    data = np.zeros(shape)
    if mask is not None:
        if mask:
            mask = np.random.choice([True, False], shape)
            mask[0, 0] = True  # make sure at least one element is non-zero
        else:
            mask = np.zeros(shape, dtype=np.bool_)

    coord, fit_status, fit_box = _find_peak(data, peak_fit_box=5, mask=mask)
    assert data[fit_box].shape == shape
    assert np.allclose(coord, [0.5 * (x - 1) for x in shape[::-1]],
                       rtol=0, atol=_ATOL)
    assert fit_status == 'ERROR:NODATA'
Exemplo n.º 13
0
def test_find_peak_edge_1pix_valid_strip(along_row):
    data = np.zeros((10, 20))
    mask = np.zeros((10, 20), dtype=np.bool_)
    if along_row:
        row = random.choice(range(10))
        data[row, :] = 1.0
        mask[row, :] = True
        coord0 = (0, row)
    else:
        col = random.choice(range(20))
        data[:, col] = 1.0
        mask[:, col] = True
        coord0 = (col, 0)

    coord, fit_status, fit_box = _find_peak(data, peak_fit_box=5, mask=mask)
    assert fit_status == 'WARNING:EDGE'
    assert np.allclose(coord, coord0, rtol=0, atol=_ATOL)
Exemplo n.º 14
0
def test_find_peak_negative_box_size():
    with pytest.raises(ValueError):
        _find_peak(np.zeros((2, 2)), peak_fit_box=-1)
Exemplo n.º 15
0
def test_find_peak_sparse_2dhist():
    data = fits.getdata(get_pkg_data_filename('data/sparse-2dhist.fits'))
    coord, fit_status, fit_box = _find_peak(data, mask=data > 0)
    assert fit_status == 'WARNING:CENTER-OF-MASS'
    assert np.allclose(coord, (35.046728971962615, 35.02803738317757),
                       rtol=0, atol=1e-14)