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_find_indices_sdi(dist, index_ref, truth): wl = np.arange(10) + 1 fwhm = 4 indices = _find_indices_sdi(wl, dist, index_ref, fwhm, debug=True) aarc(indices, truth)
def test_matrix_scaling(): """ The "truth" values were verified by hand. """ m = np.array([[6, 12, 18], [0, 0, 12]], dtype=float) res = matrix_scaling(m, None) truth = m aarc(res, truth) res = matrix_scaling(m, "temp-mean") truth = np.array([[ 3, 6, 3], [-3, -6, -3]]) aarc(res, truth) res = matrix_scaling(m, "spat-mean") truth = np.array([[-6, 0, 6], [-4, -4, 8]]) aarc(res, truth) res = matrix_scaling(m, "temp-standard") truth = np.array([[ 1, 1, 1], [-1, -1, -1]]) aarc(res, truth) res = matrix_scaling(m, "spat-standard") truth = np.array([[-np.sqrt(3/2), 0, np.sqrt(3/2)], [-np.sqrt(1/2), -np.sqrt(1/2), np.sqrt(2)]]) aarc(res, truth)
def test_matrix_scaling(): """ The "truth" values were verified by hand. """ m = np.array([[6, 12, 18], [0, 0, 12]], dtype=float) res = matrix_scaling(m, None) truth = m aarc(res, truth) res = matrix_scaling(m, "temp-mean") truth = np.array([[3, 6, 3], [-3, -6, -3]]) aarc(res, truth) res = matrix_scaling(m, "spat-mean") truth = np.array([[-6, 0, 6], [-4, -4, 8]]) aarc(res, truth) res = matrix_scaling(m, "temp-standard") truth = np.array([[1, 1, 1], [-1, -1, -1]]) aarc(res, truth) res = matrix_scaling(m, "spat-standard") truth = np.array([[-np.sqrt(3 / 2), 0, np.sqrt(3 / 2)], [-np.sqrt(1 / 2), -np.sqrt(1 / 2), np.sqrt(2)]]) aarc(res, truth)
def test_find_indices_sdi(dist, index_ref, truth): wl = np.arange(10) + 1 fwhm = 4 indices = _find_indices_sdi(wl, dist, index_ref, fwhm, debug=True) aarc(indices, truth)
def test_cube_rescaling_wavelengths(imlib, interpolation): scal_list = np.arange(10) + 1 # no zero # === basic function === res1 = cube_rescaling_wavelengths(CUBE, scal_list, imlib=imlib, interpolation=interpolation) cube1, med1, y1, x1, cy1, cx1 = res1 assert cube1.shape == (10, 1000, 1000) # frame size x10 x10 for i in range(cube1.shape[0]): aarc(cube1[i].mean() * scal_list[i]**2, 1) # === undo === res2 = cube_rescaling_wavelengths(cube1, scal_list, imlib=imlib, interpolation=interpolation, inverse=True, x_in=100, y_in=100) cube2, med2, y2, x2, cy2, cx2 = res2 aarc(cube2, CUBE)
def test_cube_inject_companions(dataset, branches, dists): """ Verify position of injected companions, for 3D and 4D cases. """ def _expected(branches, dists): """ Expected positions. """ if branches == 1 and dists == 2: return [(2, 4)] elif branches == 2 and dists == 2: return [(2, 4), (2, 0)] elif branches == 2 and dists == [1, 2]: return [(2, 3), (2, 4), (2, 1), (2, 0)] else: raise ValueError("no expected result defined") cube, psf, angles = dataset c, yx = cube_inject_companions(cube, psf_template=psf, angle_list=angles, rad_dists=dists, n_branches=branches, flevel=3, full_output=True, plsc=1, verbose=True) yx_expected = _expected(branches, dists) aarc(yx, yx_expected)
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_cube_inject_companions(dataset, branches, dists): """ Verify position of injected companions, for 3D and 4D cases. """ def _expected(branches, dists): """ Expected positions. """ if branches == 1 and dists == 2: return [(2, 4)] elif branches == 2 and dists == 2: return [(2, 4), (2, 0)] elif branches == 2 and dists == [1, 2]: return [(2, 3), (2, 4), (2, 1), (2, 0)] else: raise ValueError("no expected result defined") cube, psf, angles = dataset c, yx = cube_inject_companions(cube, psf_template=psf, angle_list=angles, rad_dists=dists, n_branches=branches, flevel=3, full_output=True, plsc=1, verbose=True) yx_expected = _expected(branches, dists) aarc(yx, yx_expected)
def test_reshape_matrix(): vectorized_frames = np.array([[1, 1, 1, 2, 2, 2], [1, 2, 3, 4, 5, 6]]) cube = reshape_matrix(vectorized_frames, 2, 3) assert cube.shape == (2, 2, 3) # 2 frames of 2x3 cube_truth = np.array([[[1, 1, 1], [2, 2, 2]], [[1, 2, 3], [4, 5, 6]]]) aarc(cube, cube_truth)
def test_reshape_matrix(): vectorized_frames = np.array([[1, 1, 1, 2, 2, 2], [1, 2, 3, 4, 5, 6]]) cube = reshape_matrix(vectorized_frames, 2, 3) assert cube.shape == (2, 2, 3) # 2 frames of 2x3 cube_truth = np.array([[[1, 1, 1], [2, 2, 2]], [[1, 2, 3], [4, 5, 6]]]) aarc(cube, cube_truth)
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)
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)
def test_check_scal_vector(): scal_vec = np.array([2, 8, 4]) # === basic function === res = check_scal_vector(scal_vec) truth = np.array([4, 1, 2]) aarc(res, truth) # === do nothing if min factor is already 1 === res2 = check_scal_vector(res) aarc(res2, res) # === wrong input value === with raises(TypeError): check_scal_vector(42)
def test_check_scal_vector(): scal_vec = np.array([2, 8, 4]) # === basic function === res = check_scal_vector(scal_vec) truth = np.array([4, 1, 2]) aarc(res, truth) # === do nothing if min factor is already 1 === res2 = check_scal_vector(res) aarc(res2, res) # === wrong input value === with raises(TypeError): check_scal_vector(42)
def test_get_circle(): ar = np.ones((10, 10), dtype=int) aarc( vip.var.get_circle(ar, radius=4, output_values=False), 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( vip.var.get_circle(pretty_odd, radius=4, output_values=True), 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( vip.var.get_circle(pretty_even, radius=4, output_values=True), 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 ]))
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 ]))
def test_cube_rescaling_wavelengths(imlib, interpolation): scal_list = np.arange(10) + 1 # no zero # === basic function === res1 = cube_rescaling_wavelengths(CUBE, scal_list, imlib=imlib, interpolation=interpolation) cube1, med1, y1, x1, cy1, cx1 = res1 assert cube1.shape == (10, 1000, 1000) # frame size x10 x10 for i in range(cube1.shape[0]): aarc(cube1[i].mean() * scal_list[i]**2, 1) # === undo === res2 = cube_rescaling_wavelengths(cube1, scal_list, imlib=imlib, interpolation=interpolation, inverse=True, x_in=100, y_in=100) cube2, med2, y2, x2, cy2, cx2 = res2 aarc(cube2, CUBE)
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]))
def test_andromeda(example_dataset): # TODO: test `fast` # TODO: test `nsnmooth_snr` # TODO: test `homogeneous_variance` # TODO: test `filtering_fraction` # TODO: test `oversampling_fact` # TODO: test `min_sep` # TODO: test `opt_method` global IDL_DATA out = andromeda( example_dataset.cube, angles=-example_dataset.angles, # VIP uses other PA convention than IDL version. # the IDL_DATA was created with the IDL version, so we need # to match its PA convention. psf=example_dataset.psf, oversampling_fact=1, filtering_fraction=1, # turn off high pass min_sep=0.3, opt_method="no", nsmooth_snr=0, # turn off smoothing homogeneous_variance=True, ) contrast, snr, snr_norm, stdcontrast, stdcontrast_norm, likelihood, _ = out aarc(contrast, IDL_DATA["andromeda_contrast_1"], atol=1e-2) aarc(snr, IDL_DATA["andromeda_snr_1"], atol=1e-4) aarc(snr_norm, IDL_DATA["andromeda_snr_norm_1"], atol=1e-4) aarc(stdcontrast, IDL_DATA["andromeda_stdcontrast_1"]) aarc(stdcontrast_norm, IDL_DATA["andromeda_stdcontrast_norm_1"]) aarc(likelihood, IDL_DATA["andromeda_likelihood_1"], atol=1e-4)
def test_fft_ifft(): global FRAME FRAME = np.arange(100).reshape((10, 10)) res = ifft(fft(FRAME)) aarc(res, FRAME)
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
def test_idl_where(): a = np.arange(3*3, dtype=int).reshape((3, 3)) aarc(idl_where(a <= 3), [0, 1, 2, 3]) # WHERE(a LE 3) aarc(idl_where(a == 5), [5]) # WHERE(a EQ 5) aarc(idl_where(a > 20), []) # WHERE(a GT 20) -> returns [-1]
def test_get_annulus_segments(): arr = np.ones((10, 10)) # single segment, like the old get_annulus. Note the ``[0]``. res = vip.var.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 = vip.var.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 = vip.var.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 = vip.var.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! # masked arr res = vip.var.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)
def test_andromeda(example_dataset): # TODO: test `fast` # TODO: test `nsnmooth_snr` # TODO: test `homogeneous_variance` # TODO: test `filtering_fraction` # TODO: test `oversampling_fact` # TODO: test `min_sep` # TODO: test `opt_method` global IDL_DATA out = andromeda(example_dataset.cube, angles=-example_dataset.angles, # VIP uses other PA convention than IDL version. # the IDL_DATA was created with the IDL version, so we need # to match its PA convention. psf=example_dataset.psf, oversampling_fact=1, filtering_fraction=1, # turn off high pass min_sep=0.3, opt_method="no", nsmooth_snr=0, # turn off smoothing homogeneous_variance=True, ) contrast, snr, snr_norm, stdcontrast, stdcontrast_norm, likelihood, _ = out aarc(contrast, IDL_DATA["andromeda_contrast_1"], atol=1e-2) aarc(snr, IDL_DATA["andromeda_snr_1"], atol=1e-4) aarc(snr_norm, IDL_DATA["andromeda_snr_norm_1"], atol=1e-4) aarc(stdcontrast, IDL_DATA["andromeda_stdcontrast_1"]) aarc(stdcontrast_norm, IDL_DATA["andromeda_stdcontrast_norm_1"]) aarc(likelihood, IDL_DATA["andromeda_likelihood_1"], atol=1e-4)
def test_get_square(): aarc(vip.var.get_square(pretty_odd, size=3, x=2, y=2), np.array([[2, 2, 2], [2, 3, 2], [2, 2, 2]])) aarc(vip.var.get_square(pretty_odd, size=2, x=2, y=2), np.array([[2, 2, 2], [2, 3, 2], [2, 2, 2]])) # -> prints warning aarc(vip.var.get_square(pretty_odd, size=2, x=2, y=2, force=True), np.array([[2, 2], [2, 3]])) aarc(vip.var.get_square(pretty_even, size=2, x=3, y=3), np.array([[3, 3], [3, 3]])) aarc(vip.var.get_square(pretty_even, size=3, x=3, y=3), np.array([[2, 2, 2, 2], [2, 3, 3, 2], [2, 3, 3, 2], [2, 2, 2, 2]])) # -> prints warning aarc(vip.var.get_square(pretty_even, size=2, x=4, y=2, force=True), np.array([[2, 2], [3, 2]]))
def test_get_square(): aarc(get_square(PRETTY_ODD, size=3, x=2, y=2), np.array([[2, 2, 2], [2, 3, 2], [2, 2, 2]])) aarc(get_square(PRETTY_ODD, size=2, x=2, y=2), np.array([[2, 2, 2], [2, 3, 2], [2, 2, 2]])) # -> prints warning aarc(get_square(PRETTY_ODD, size=2, x=2, y=2, force=True), np.array([[2, 2], [2, 3]])) aarc(get_square(PRETTY_EVEN, size=2, x=3, y=3), np.array([[3, 3], [3, 3]])) aarc(get_square(PRETTY_EVEN, size=3, x=3, y=3), np.array([[2, 2, 2, 2], [2, 3, 3, 2], [2, 3, 3, 2], [2, 2, 2, 2]])) # -> prints warning aarc(get_square(PRETTY_EVEN, size=2, x=4, y=2, force=True), np.array([[2, 2], [3, 2]]))
def test_fft_ifft(): global FRAME FRAME = np.arange(100).reshape((10, 10)) res = ifft(fft(FRAME)) aarc(res, FRAME)
def test_idl_where(): a = np.arange(3 * 3, dtype=int).reshape((3, 3)) aarc(idl_where(a <= 3), [0, 1, 2, 3]) # WHERE(a LE 3) aarc(idl_where(a == 5), [5]) # WHERE(a EQ 5) aarc(idl_where(a > 20), []) # WHERE(a GT 20) -> returns [-1]
def test_get_square(): aarc(get_square(PRETTY_ODD, size=3, x=2, y=2), np.array([[2, 2, 2], [2, 3, 2], [2, 2, 2]])) aarc(get_square(PRETTY_ODD, size=2, x=2, y=2), np.array([[2, 2, 2], [2, 3, 2], [2, 2, 2]])) # -> prints warning aarc(get_square(PRETTY_ODD, size=2, x=2, y=2, force=True), np.array([[2, 2], [2, 3]])) aarc(get_square(PRETTY_EVEN, size=2, x=3, y=3), np.array([[3, 3], [3, 3]])) aarc(get_square(PRETTY_EVEN, size=3, x=3, y=3), np.array([[2, 2, 2, 2], [2, 3, 3, 2], [2, 3, 3, 2], [2, 2, 2, 2]])) # -> prints warning aarc(get_square(PRETTY_EVEN, size=2, x=4, y=2, force=True), np.array([[2, 2], [3, 2]]))
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