def test_bad_images(): setup() g2, lag_steps = multi_tau_auto_corr(4, num_bufs, rois, img_stack) # introduce bad images bad_img_list = [3, 21, 35, 48] # convert each bad image to np.nan array images = bad_to_nan_gen(img_stack, bad_img_list) # then use new images (including bad images) g2_n, lag_steps_n = multi_tau_auto_corr(4, num_bufs, rois, images) assert_array_almost_equal(g2[:, 0], g2_n[:, 0], decimal=3) assert_array_almost_equal(g2[:, 1], g2_n[:, 1], decimal=3)
def test_bad_to_nan_gen(): xdim = 2 ydim = 2 stack_size = 5 img_stack = np.random.randint(1, 3, (stack_size, xdim, ydim)) bad_list = [1, 3] img = mask.bad_to_nan_gen(img_stack, bad_list) y = [] for im in img: y.append(im) assert np.isnan(np.asarray(y)[1]).all() assert np.isnan(np.asarray(y)[3]).all() assert not np.isnan(np.asarray(y)[4]).all()
def test_xsvs(): images = [] for i in range(5): int_array = np.tril((i + 2) * np.ones(10)) int_array[int_array == 0] = (i + 1) images.append(int_array) images_sets = [ np.asarray(images), ] roi_data = np.array(([4, 2, 2, 2], [0, 5, 4, 4]), dtype=np.int64) label_array = roi.rectangles(roi_data, shape=images[0].shape) prob_k_all, std = xsvs.xsvs(images_sets, label_array, timebin_num=2, number_of_img=5, max_cts=6) assert_array_almost_equal(prob_k_all[0, 0], np.array([0., 0., 0.2, 0.2, 0.4])) assert_array_almost_equal(prob_k_all[0, 1], np.array([0., 0.2, 0.2, 0.2, 0.4])) imgs = [] for i in range(6): int_array = np.tril((i + 2) * np.ones(10)) int_array[int_array == 0] = (i + 1) imgs.append(int_array) # testing for bad images bad_list = [5] # convert each bad image to np.nan array images1 = mask.bad_to_nan_gen(imgs, bad_list) new_prob_k, new_std = xsvs.xsvs((images1, ), label_array, timebin_num=2, number_of_img=5, max_cts=6) assert_array_almost_equal(new_prob_k[0, 0], np.array([0., 0., 0.2, 0.2, 0.4])) assert_array_almost_equal(new_prob_k[0, 1], np.array([0., 0.2, 0.2, 0.2, 0.4]))
def test_xsvs(): images = [] for i in range(5): int_array = np.tril((i + 2) * np.ones(10)) int_array[int_array == 0] = (i + 1) images.append(int_array) images_sets = [np.asarray(images), ] roi_data = np.array(([4, 2, 2, 2], [0, 5, 4, 4]), dtype=np.int64) label_array = roi.rectangles(roi_data, shape=images[0].shape) prob_k_all, std = xsvs.xsvs(images_sets, label_array, timebin_num=2, number_of_img=5, max_cts=6) assert_array_almost_equal(prob_k_all[0, 0], np.array([0., 0., 0.2, 0.2, 0.4])) assert_array_almost_equal(prob_k_all[0, 1], np.array([0., 0.2, 0.2, 0.2, 0.4])) imgs = [] for i in range(6): int_array = np.tril((i + 2) * np.ones(10)) int_array[int_array == 0] = (i + 1) imgs.append(int_array) # testing for bad images bad_list = [5] # convert each bad image to np.nan array images1 = mask.bad_to_nan_gen(imgs, bad_list) new_prob_k, new_std = xsvs.xsvs((images1, ), label_array, timebin_num=2, number_of_img=5, max_cts=6) assert_array_almost_equal(new_prob_k[0, 0], np.array([0., 0., 0.2, 0.2, 0.4])) assert_array_almost_equal(new_prob_k[0, 1], np.array([0., 0.2, 0.2, 0.2, 0.4]))