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
def test_saveable_dataset(): """ Test the HCIDataset.save() and .load() methods """ # build HCIDataset cube = np.zeros((5, 10, 10)) angles = np.linspace(1, 2, 5) fwhm = 4 # test non-numpy type saving/loading ds = HCIDataset(cube=cube, angles=angles, fwhm=fwhm) # save fd, fn = tempfile.mkstemp(prefix="vip_") ds.save(fn) # restore ds2 = HCIDataset.load(fn) # compare aarc(ds2.cube, cube) aarc(ds2.angles, angles) assert ds2.fwhm == fwhm # cleanup os.remove(fn)
def test_fit2d(psf_model, fit_fkt, y, x, framesize, psfsize): frame = np.zeros((framesize, framesize)) psf = create_synth_psf(psf_model, shape=(psfsize, psfsize)) inj_frame = put_center(frame, psf, y, x) y_out, x_out = fit_fkt(inj_frame) # correct "half-pixel centering", to make output of fit_2d* comparable # with `put`. if ( (framesize % 2 == 0 and psfsize % 2 == 0) or (framesize % 2 == 1 and psfsize % 2 == 0) ): y_exp = y - 0.5 x_exp = x - 0.5 else: y_exp = y x_exp = x yx_real = np.unravel_index(inj_frame.argmax(), inj_frame.shape) print("demanded injection: {}".format((y, x))) print("brightes pixel: {}".format(yx_real)) print("fit should return: {}".format((y_exp, x_exp))) print("fitted injection: {}".format((y_out, x_out))) aarc((y_out, x_out), (y_exp, x_exp), atol=0.05)
def test_fit2d(psf_model, fit_fkt, y, x, framesize, psfsize): frame = np.zeros((framesize, framesize)) psf = create_synth_psf(psf_model, shape=(psfsize, psfsize)) inj_frame = put_center(frame, psf, y, x) y_out, x_out = fit_fkt(inj_frame) # correct "half-pixel centering", to make output of fit_2d* comparable # with `put`. if ((framesize % 2 == 0 and psfsize % 2 == 0) or (framesize % 2 == 1 and psfsize % 2 == 0)): y_exp = y - 0.5 x_exp = x - 0.5 else: y_exp = y x_exp = x yx_real = np.unravel_index(inj_frame.argmax(), inj_frame.shape) print("demanded injection: {}".format((y, x))) print("brightes pixel: {}".format(yx_real)) print("fit should return: {}".format((y_exp, x_exp))) print("fitted injection: {}".format((y_out, x_out))) aarc((y_out, x_out), (y_exp, x_exp), atol=0.05)
def test_frame_center(): frames = 39 nlambda = 2 res44 = (1.5, 1.5) res55 = (2.0, 2.0) # 2D assert frame_center(np.zeros((4, 4))) == res44 assert frame_center(np.zeros((5, 5))) == res55 # 3D assert frame_center(np.zeros((frames, 4, 4))) == res44 assert frame_center(np.zeros((frames, 5, 5))) == res55 # 4D assert frame_center(np.zeros((nlambda, frames, 4, 4))) == res44 assert frame_center(np.zeros((nlambda, frames, 5, 5))) == res55
""" 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)
""" 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)