示例#1
0
def test_clean_data_bmap_add_bad_3d():
    # Test combination of 3d bad pixels with add_bad 3d as well
    n_im = 5
    img_dim = 80
    data = np.random.random((n_im, img_dim, img_dim))

    # N-dim list or arbitrary (len == 1 here) lists of 2-tuples
    new_bad_inds = [
        tuple(np.random.randint(0, high=img_dim, size=2)) for _ in range(n_im)
    ]
    add_bad = [[ind[::-1]] for ind in new_bad_inds]

    bad_cube = np.zeros((n_im, img_dim, img_dim), dtype=bool)
    for i in range(n_im):
        bad_cube[(i, *np.random.randint(0, high=img_dim, size=2))] = 1
        data[(i, *new_bad_inds[i])] = 1e5

    # Put value out of data bounds (0, 1) to make sure corrected != original
    data[bad_cube] = 1e5

    cleaned = clean_data(data, sky=False, apod=False, bad_map=bad_cube, add_bad=add_bad)
    nobpix_list = [
        fix_bad_pixels(data[i], bad_map=bad_cube[i], add_bad=add_bad[i])
        for i in range(n_im)
    ]

    full_bad_cube = bad_cube.copy()
    for i in range(n_im):
        full_bad_cube[(i, *new_bad_inds[i])] = True

    assert np.all([cleaned[i] == nobpix_list[i] for i in range(data.shape[0])])
    assert np.all(cleaned[full_bad_cube] != data[full_bad_cube])
    assert np.all(cleaned[~full_bad_cube] == data[~full_bad_cube])
示例#2
0
def test_clean_data_bmap_add_bad_2d():
    # Test combination of bad_map and add_bad in 2d
    n_im = 5
    img_dim = 80
    data = np.random.random((n_im, img_dim, img_dim))

    new_bad_ind = tuple(np.random.randint(0, high=img_dim, size=2))
    new_bad_ind_3d = (slice(None),) + new_bad_ind
    add_bad = [new_bad_ind[::-1]]

    bad_map = np.zeros((img_dim, img_dim), dtype=bool)
    bad_map[tuple(np.random.randint(0, high=img_dim, size=2))] = 1

    # Set values out of random range to test that they did change later
    data[:, bad_map] = 1e5
    data[new_bad_ind_3d] = 1e5

    cleaned = clean_data(data, sky=False, apod=False, bad_map=bad_map, add_bad=add_bad)
    nobpix_list = [
        fix_bad_pixels(img, bad_map=bad_map, add_bad=add_bad) for img in data
    ]

    full_bad_map = bad_map.copy()
    full_bad_map[new_bad_ind] = True

    assert np.all([cleaned[i] == nobpix_list[i] for i in range(data.shape[0])])
    assert np.all(cleaned[:, full_bad_map] != data[:, full_bad_map])
    assert np.all(cleaned[:, ~full_bad_map] == data[:, ~full_bad_map])
示例#3
0
def test_clean_data_bmap_3d_add_bad_2d():
    # Test combination of 3d bad pixels with add_bad common for all dimensions
    n_im = 5
    img_dim = 80
    data = np.random.random((n_im, img_dim, img_dim))

    new_bad_ind = tuple(np.random.randint(0, high=img_dim, size=2))
    new_bad_ind_3d = (slice(None),) + new_bad_ind
    add_bad = [new_bad_ind[::-1]]

    bad_cube = np.zeros((n_im, img_dim, img_dim), dtype=bool)
    for i in range(n_im):
        bad_cube[(i, *np.random.randint(0, high=img_dim, size=2))] = 1

    # Put value out of data bounds (0, 1) to make sure corrected != original
    data[bad_cube] = 1e5
    data[new_bad_ind_3d] = 1e5

    cleaned = clean_data(data, sky=False, apod=False, bad_map=bad_cube, add_bad=add_bad)
    nobpix_list = [
        fix_bad_pixels(img, bad_map=bmap, add_bad=add_bad)
        for img, bmap in zip(data, bad_cube)
    ]

    full_bad_cube = bad_cube.copy()
    full_bad_cube[new_bad_ind_3d] = True

    assert np.all([cleaned[i] == nobpix_list[i] for i in range(data.shape[0])])
    assert np.all(cleaned[full_bad_cube] != data[full_bad_cube])
    assert np.all(cleaned[~full_bad_cube] == data[~full_bad_cube])
示例#4
0
def test_fix_bad_pixel_no_bad():
    img_dim = 80
    data = np.random.random((img_dim, img_dim))

    no_bpix = fix_bad_pixels(data, np.zeros_like(data, dtype=bool))

    assert np.all(data == no_bpix)
示例#5
0
def test_fix_one_bad_pixel():

    img_dim = 80
    data = np.random.random((img_dim, img_dim))

    bad_ind = tuple(np.random.randint(0, high=img_dim, size=2))
    data[bad_ind] = 1e5

    bad_map = np.zeros_like(data, dtype=bool)
    bad_map[bad_ind] = 1

    no_bpix = fix_bad_pixels(data, bad_map)

    assert no_bpix[bad_map] != data[bad_map]
    assert np.all(no_bpix[~bad_map] == data[~bad_map])
    assert 0.0 <= no_bpix[bad_ind] <= 1.0  # Because test data is random U(0, 1)
示例#6
0
def test_clean_data_bmap_2d():
    n_im = 5
    img_dim = 80
    data = np.random.random((n_im, img_dim, img_dim))

    bad_map = np.zeros((img_dim, img_dim), dtype=bool)
    bad_map[tuple(np.random.randint(0, high=img_dim, size=2))] = 1

    data[:, bad_map] = 1e5

    # Test case with non-emtpy add_bad but empty add_bad
    cleaned = clean_data(data, sky=False, apod=False, bad_map=bad_map)
    nobpix_list = [fix_bad_pixels(img, bad_map=bad_map) for img in data]

    assert np.all([cleaned[i] == nobpix_list[i] for i in range(data.shape[0])])
    assert np.all(cleaned[:, bad_map] != data[:, bad_map])
    assert np.all(cleaned[:, ~bad_map] == data[:, ~bad_map])
示例#7
0
def test_clean_data_bmap_3d():
    # Test regular bad pixel map per-frame
    n_im = 5
    img_dim = 80
    data = np.random.random((n_im, img_dim, img_dim))

    bad_cube = np.zeros((n_im, img_dim, img_dim), dtype=bool)
    for i in range(n_im):
        bad_cube[(i, *np.random.randint(0, high=img_dim, size=2))] = 1

    # Put value out of data bounds (0, 1) to make sure corrected != original
    data[bad_cube] = 1e5

    cleaned = clean_data(data, sky=False, apod=False, bad_map=bad_cube)
    nobpix_list = [
        fix_bad_pixels(img, bad_map=bmap) for img, bmap in zip(data, bad_cube)
    ]

    assert np.all([cleaned[i] == nobpix_list[i] for i in range(data.shape[0])])
    assert np.all(cleaned[bad_cube] != data[bad_cube])
    assert np.all(cleaned[~bad_cube] == data[~bad_cube])
示例#8
0
def test_clean_data_no_bmap_add_bad():
    # Test add_data kwarg when no bad_map
    n_im = 5
    img_dim = 80
    data = np.random.random((n_im, img_dim, img_dim))

    bad_ind = tuple(np.random.randint(0, high=img_dim, size=2))
    bad_ind_3d = (slice(None),) + bad_ind
    add_bad = [bad_ind[::-1]]

    # Set values out of random range to test that they did change later
    data[bad_ind_3d] = 1e5

    cleaned = clean_data(data, sky=False, apod=False, add_bad=add_bad)
    nobpix_list = [
        fix_bad_pixels(img, bad_map=np.zeros((img_dim, img_dim)), add_bad=add_bad)
        for img in data
    ]

    assert np.all([cleaned[i] == nobpix_list[i] for i in range(data.shape[0])])
    assert np.all(cleaned[bad_ind_3d] != data[bad_ind_3d])