예제 #1
0
def dataset(request):
    """
    Create 3D and 4D datasets for use with ``test_cube_inject_companions``.

    """
    if request.param == "3D":
        cube = np.zeros((3, 5, 5))
        psf = np.ones((1, 1))
    elif request.param == "4D":
        cube = np.zeros((2, 3, 5, 5))  # lambda, frames, width, height
        psf = np.ones((2, 1, 1))

    angles = np.array([0, 90, 180])

    return cube, psf, angles
예제 #2
0
def dataset(request):
    """
    Create 3D and 4D datasets for use with ``test_cube_inject_companions``.

    """
    if request.param == "3D":
        cube = np.zeros((3, 5, 5))
        psf = np.ones((1, 1))
    elif request.param == "4D":
        cube = np.zeros((2, 3, 5, 5))  # lambda, frames, width, height
        psf = np.ones((2, 1, 1))

    angles = np.array([0, 90, 180])

    return cube, psf, angles
예제 #3
0
def test_get_circle():

    ar = np.ones((10, 10), dtype=int)
    aarc(
        get_circle(ar, radius=4),
        np.array([[0, 0, 0, 0, 0, 0, 0, 0, 0,
                   0], [0, 0, 0, 1, 1, 1, 1, 0, 0, 0],
                  [0, 0, 1, 1, 1, 1, 1, 1, 0,
                   0], [0, 1, 1, 1, 1, 1, 1, 1, 1, 0],
                  [0, 1, 1, 1, 1, 1, 1, 1, 1,
                   0], [0, 1, 1, 1, 1, 1, 1, 1, 1, 0],
                  [0, 1, 1, 1, 1, 1, 1, 1, 1,
                   0], [0, 0, 1, 1, 1, 1, 1, 1, 0, 0],
                  [0, 0, 0, 1, 1, 1, 1, 0, 0, 0],
                  [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]))

    aarc(
        get_circle(PRETTY_ODD, radius=4, mode="val"),
        np.array([
            1, 1, 1, 1, 1, 1, 2, 2, 2, 1, 1, 2, 3, 2, 1, 1, 2, 2, 2, 1, 1, 1,
            1, 1, 1
        ]))

    aarc(
        get_circle(PRETTY_EVEN, radius=4, mode="val"),
        np.array([
            1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 1, 1, 2, 3, 3, 2, 1, 1, 2, 3, 3,
            2, 1, 1, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1
        ]))
예제 #4
0
def test_get_ellipse():
    f = np.ones((6, 10))

    # masked array:
    fem = get_ellipse(f, 4, 2, 90, mode="mask")
    assert fem.sum() == 28  # outer region masked, 28 pixels kept

    # values:
    fev = get_ellipse(f, 4, 2, 90, mode="val")
    assert fev.sum() == 28

    # indices:
    fei = get_ellipse(f, 4, 2, 90, mode="ind")
    assert fei[0].shape == fei[1].shape == (28, )
예제 #5
0
def test_mask_circle():

    size = 5
    radius = 2

    ones = np.ones((size, size))

    # "in" and "out" should be complementary
    res_in = mask_circle(ones, radius=radius, mode="in")
    res_out = mask_circle(ones, radius=radius, mode="out")
    aarc(res_in+res_out, ones)

    # radius=2 -> central region should be 3x3 pixels = 9 pixels
    aarc(res_out.sum(), 9)
예제 #6
0
def test_mask_circle():

    size = 5
    radius = 2

    ones = np.ones((size, size))

    # "in" and "out" should be complementary
    res_in = mask_circle(ones, radius=radius, mode="in")
    res_out = mask_circle(ones, radius=radius, mode="out")
    aarc(res_in + res_out, ones)

    # radius=2 -> central region should be 3x3 pixels = 9 pixels
    aarc(res_out.sum(), 9)
예제 #7
0
def test_get_ellipse():
    f = np.ones((6, 10))

    # masked array:
    fem = get_ellipse(f, 4, 2, 90, mode="mask")
    assert fem.sum() == 28  # outer region masked, 28 pixels kept

    # values:
    fev = get_ellipse(f, 4, 2, 90, mode="val")
    assert fev.sum() == 28

    # indices:
    fei = get_ellipse(f, 4, 2, 90, mode="ind")
    assert fei[0].shape == fei[1].shape == (28,)
예제 #8
0
def test_normalize_psf_shapes():
    """
    Test if normalize_psf produces the expected shapes.
    """
    # `Force_odd` is True therefore `size` was set to 19
    res_even = normalize_psf(np.ones((20, 20)), size=18)
    res_odd = normalize_psf(np.ones((21, 21)), size=18)
    assert res_even.shape == res_odd.shape == (19, 19)

    res_even = normalize_psf(np.ones((20, 20)), size=18, force_odd=False)
    res_odd = normalize_psf(np.ones((21, 21)), size=18, force_odd=False)
    assert res_even.shape == res_odd.shape == (18, 18)

    # set to odd size
    res_even = normalize_psf(np.ones((20, 20)), size=19)
    res_odd = normalize_psf(np.ones((21, 21)), size=19)
    assert res_even.shape == res_odd.shape == (19, 19)

    res_even = normalize_psf(np.ones((20, 20)), size=19, force_odd=False)
    res_odd = normalize_psf(np.ones((21, 21)), size=19, force_odd=False)
    assert res_even.shape == res_odd.shape == (19, 19)
예제 #9
0
def test_normalize_psf_shapes():
    """
    Test if normalize_psf produces the expected shapes.
    """
    # `Force_odd` is True therefore `size` was set to 19
    res_even = normalize_psf(np.ones((20, 20)), size=18)
    res_odd = normalize_psf(np.ones((21, 21)), size=18)
    assert res_even.shape == res_odd.shape == (19, 19)

    res_even = normalize_psf(np.ones((20, 20)), size=18, force_odd=False)
    res_odd = normalize_psf(np.ones((21, 21)), size=18, force_odd=False)
    assert res_even.shape == res_odd.shape == (18, 18)

    # set to odd size
    res_even = normalize_psf(np.ones((20, 20)), size=19)
    res_odd = normalize_psf(np.ones((21, 21)), size=19)
    assert res_even.shape == res_odd.shape == (19, 19)

    res_even = normalize_psf(np.ones((20, 20)), size=19, force_odd=False)
    res_odd = normalize_psf(np.ones((21, 21)), size=19, force_odd=False)
    assert res_even.shape == res_odd.shape == (19, 19)
예제 #10
0
def test_get_circle():

    ar = np.ones((10, 10), dtype=int)
    aarc(get_circle(ar, radius=4),
         np.array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                   [0, 0, 0, 1, 1, 1, 1, 0, 0, 0],
                   [0, 0, 1, 1, 1, 1, 1, 1, 0, 0],
                   [0, 1, 1, 1, 1, 1, 1, 1, 1, 0],
                   [0, 1, 1, 1, 1, 1, 1, 1, 1, 0],
                   [0, 1, 1, 1, 1, 1, 1, 1, 1, 0],
                   [0, 1, 1, 1, 1, 1, 1, 1, 1, 0],
                   [0, 0, 1, 1, 1, 1, 1, 1, 0, 0],
                   [0, 0, 0, 1, 1, 1, 1, 0, 0, 0],
                   [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]))

    aarc(get_circle(PRETTY_ODD, radius=4, mode="val"),
         np.array([1, 1, 1, 1, 1, 1, 2, 2, 2, 1, 1, 2, 3, 2, 1, 1, 2, 2,
                   2, 1, 1, 1, 1, 1, 1]))

    aarc(get_circle(PRETTY_EVEN, radius=4, mode="val"),
         np.array([1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 1, 1, 2, 3, 3, 2, 1,
                   1, 2, 3, 3, 2, 1, 1, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1]))
예제 #11
0
"""

from __future__ import division, print_function

__author__ = "Ralf Farkas"

from helpers import np, aarc, raises, parametrize
from vip_hci.preproc.rescaling import (cube_px_resampling,
                                       frame_px_resampling,
                                       cube_rescaling_wavelengths,
                                       check_scal_vector,
                                       _find_indices_sdi)


CUBE = np.ones((10, 100, 100))
FRAME = np.zeros((100, 100))


@parametrize("imlib", ["ndimage", "opencv"])
def test_cube_px_resampling(imlib):

    # === enlargen ===

    res = cube_px_resampling(CUBE, scale=2, imlib=imlib)
    assert res.shape == (10, 200, 200)

    # === shrink ===

    res = cube_px_resampling(CUBE, scale=0.5, imlib=imlib)
    assert res.shape == (10, 50, 50)
예제 #12
0
def test_get_ell_annulus():

    f = np.ones((15, 30))

    fa = get_ell_annulus(f, 8, 3, 90, 6, mode="mask")
    assert fa.sum() == 124
예제 #13
0
def test_get_annulus_segments():
    arr = np.ones((10, 10))

    # single segment, like the old get_annulus. Note the ``[0]``.

    res = get_annulus_segments(arr, 2, 3)[0]

    truth = (np.array([0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3,
                       3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6,
                       6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9,
                       9, 9]),
             np.array([3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8, 0, 1,
                       2, 3, 6, 7, 8, 9, 0, 1, 2, 7, 8, 9, 0, 1, 2, 7, 8, 9, 0, 1, 2, 3,
                       6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8, 3, 4,
                       5, 6]))

    aarc(res, truth)

    res = get_annulus_segments(arr, 2, 3, mode="val")[0]
    truth = np.array([1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
                      1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
                      1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
                      1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.])

    aarc(res, truth)

    # multiple segments:

    res = get_annulus_segments(PRETTY_EVEN, 2, 3, nsegm=2)
    truth = [(np.array([0, 0, 0, 1, 1, 2, 3, 4, 4, 5, 5, 5]),
              np.array([3, 4, 5, 4, 5, 5, 5, 4, 5, 3, 4, 5])),
             (np.array([0, 0, 0, 1, 1, 2, 3, 4, 4, 5, 5, 5]),
              np.array([0, 1, 2, 0, 1, 0, 0, 0, 1, 0, 1, 2]))]

    aarc(res, truth)

    res = get_annulus_segments(PRETTY_EVEN, 2, 3, nsegm=3)
    truth = [(np.array([2, 3, 4, 4, 5, 5, 5]),
              np.array([5, 5, 4, 5, 3, 4, 5])),
             (np.array([0, 0, 0, 0, 0, 0, 1, 1, 1, 1]),
              np.array([0, 1, 2, 3, 4, 5, 0, 1, 4, 5])),
             (np.array([2, 3, 4, 4, 5, 5, 5]),
              np.array([0, 0, 0, 1, 0, 1, 2]))]

    assert repr(res) == repr(truth)
    # TODO: cannot compare using `allclose`, as elements have variable length!

    # tuple as input:

    res = get_annulus_segments((6, 6), 2, 3, nsegm=3)
    assert repr(res) == repr(truth)

    # masked arr:

    res = get_annulus_segments(arr, 2, 3, mode="mask")[0]
    truth = np.array([[0., 0., 0., 1., 1., 1., 1., 0., 0., 0.],
                      [0., 1., 1., 1., 1., 1., 1., 1., 1., 0.],
                      [0., 1., 1., 1., 1., 1., 1., 1., 1., 0.],
                      [1., 1., 1., 1., 0., 0., 1., 1., 1., 1.],
                      [1., 1., 1., 0., 0., 0., 0., 1., 1., 1.],
                      [1., 1., 1., 0., 0., 0., 0., 1., 1., 1.],
                      [1., 1., 1., 1., 0., 0., 1., 1., 1., 1.],
                      [0., 1., 1., 1., 1., 1., 1., 1., 1., 0.],
                      [0., 1., 1., 1., 1., 1., 1., 1., 1., 0.],
                      [0., 0., 0., 1., 1., 1., 1., 0., 0., 0.]])
    aarc(res, truth)

    # tuple as input:

    res = get_annulus_segments((10, 10), 2, 3, mode="mask")[0]
    # masking a zeros array -> only zeros left!
    assert res.sum() == 0
예제 #14
0
def test_get_ell_annulus():

    f = np.ones((15, 30))

    fa = get_ell_annulus(f, 8, 3, 90, 6, mode="mask")
    assert fa.sum() == 124
예제 #15
0
"""

from __future__ import division, print_function, absolute_import

__author__ = "Ralf Farkas"

from helpers import aarc, np, param, parametrize
from vip_hci.var.filters import (fft, ifft,
                                 cube_filter_iuwt,
                                 cube_filter_highpass,
                                 cube_filter_lowpass,
                                 frame_filter_highpass,
                                 frame_filter_lowpass)


CUBE = np.ones((5, 10, 10), dtype=float)
FRAME = np.arange(100, dtype=float).reshape((10, 10))


@parametrize("filter_mode",
             [
                 "laplacian",
                 "laplacian-conv",
                 "median-subt",
                 "gauss-subt",
                 "fourier-butter",
                 "hann"
             ]
             )
@parametrize("data, fkt",
             [
예제 #16
0
def test_get_annulus_segments():
    arr = np.ones((10, 10))

    # single segment, like the old get_annulus. Note the ``[0]``.

    res = get_annulus_segments(arr, 2, 3)[0]

    truth = (np.array([
        0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3,
        3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6,
        7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9
    ]),
             np.array([
                 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8, 0,
                 1, 2, 3, 6, 7, 8, 9, 0, 1, 2, 7, 8, 9, 0, 1, 2, 7, 8, 9, 0, 1,
                 2, 3, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7,
                 8, 3, 4, 5, 6
             ]))

    aarc(res, truth)

    res = get_annulus_segments(arr, 2, 3, mode="val")[0]
    truth = np.array([
        1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
        1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
        1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
        1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.
    ])

    aarc(res, truth)

    # multiple segments:

    res = get_annulus_segments(PRETTY_EVEN, 2, 3, nsegm=2)
    truth = [(np.array([0, 0, 0, 1, 1, 2, 3, 4, 4, 5, 5,
                        5]), np.array([3, 4, 5, 4, 5, 5, 5, 4, 5, 3, 4, 5])),
             (np.array([0, 0, 0, 1, 1, 2, 3, 4, 4, 5, 5,
                        5]), np.array([0, 1, 2, 0, 1, 0, 0, 0, 1, 0, 1, 2]))]

    aarc(res, truth)

    res = get_annulus_segments(PRETTY_EVEN, 2, 3, nsegm=3)
    truth = [(np.array([2, 3, 4, 4, 5, 5, 5]), np.array([5, 5, 4, 5, 3, 4,
                                                         5])),
             (np.array([0, 0, 0, 0, 0, 0, 1, 1, 1,
                        1]), np.array([0, 1, 2, 3, 4, 5, 0, 1, 4, 5])),
             (np.array([2, 3, 4, 4, 5, 5, 5]), np.array([0, 0, 0, 1, 0, 1,
                                                         2]))]

    assert repr(res) == repr(truth)
    # TODO: cannot compare using `allclose`, as elements have variable length!

    # tuple as input:

    res = get_annulus_segments((6, 6), 2, 3, nsegm=3)
    assert repr(res) == repr(truth)

    # masked arr:

    res = get_annulus_segments(arr, 2, 3, mode="mask")[0]
    truth = np.array([[0., 0., 0., 1., 1., 1., 1., 0., 0., 0.],
                      [0., 1., 1., 1., 1., 1., 1., 1., 1., 0.],
                      [0., 1., 1., 1., 1., 1., 1., 1., 1., 0.],
                      [1., 1., 1., 1., 0., 0., 1., 1., 1., 1.],
                      [1., 1., 1., 0., 0., 0., 0., 1., 1., 1.],
                      [1., 1., 1., 0., 0., 0., 0., 1., 1., 1.],
                      [1., 1., 1., 1., 0., 0., 1., 1., 1., 1.],
                      [0., 1., 1., 1., 1., 1., 1., 1., 1., 0.],
                      [0., 1., 1., 1., 1., 1., 1., 1., 1., 0.],
                      [0., 0., 0., 1., 1., 1., 1., 0., 0., 0.]])
    aarc(res, truth)

    # tuple as input:

    res = get_annulus_segments((10, 10), 2, 3, mode="mask")[0]
    # masking a zeros array -> only zeros left!
    assert res.sum() == 0
예제 #17
0
"""
Tests for preproc/rescaling.py

"""

from __future__ import division, print_function

__author__ = "Ralf Farkas"

from helpers import np, aarc, raises, parametrize
from vip_hci.preproc.rescaling import (cube_px_resampling, frame_px_resampling,
                                       cube_rescaling_wavelengths,
                                       check_scal_vector, _find_indices_sdi)

CUBE = np.ones((10, 100, 100))
FRAME = np.zeros((100, 100))


@parametrize("imlib", ["ndimage", "opencv"])
def test_cube_px_resampling(imlib):

    # === enlargen ===

    res = cube_px_resampling(CUBE, scale=2, imlib=imlib)
    assert res.shape == (10, 200, 200)

    # === shrink ===

    res = cube_px_resampling(CUBE, scale=0.5, imlib=imlib)
    assert res.shape == (10, 50, 50)
예제 #18
0
test_iuwt) do NOT verify the actual filtering, as the results produced by the
various filtering algorithms are very diverse. Instead, it is ONLY tested IF the
algorithms actually run.

"""

from __future__ import division, print_function, absolute_import

__author__ = "Ralf Farkas"

from helpers import aarc, np, param, parametrize
from vip_hci.var.filters import (fft, ifft, cube_filter_iuwt,
                                 cube_filter_highpass, cube_filter_lowpass,
                                 frame_filter_highpass, frame_filter_lowpass)

CUBE = np.ones((5, 10, 10), dtype=float)
FRAME = np.arange(100, dtype=float).reshape((10, 10))


@parametrize("filter_mode", [
    "laplacian", "laplacian-conv", "median-subt", "gauss-subt",
    "fourier-butter", "hann"
])
@parametrize("data, fkt", [
    param(CUBE, cube_filter_highpass, id="cube"),
    param(FRAME, frame_filter_highpass, id="frame")
],
             ids=lambda x: (x.__name__ if callable(x) else None))
def test_highpass(data, fkt, filter_mode):
    res = fkt(data, mode=filter_mode)
    assert res.shape == data.shape