def test_k_trafo_cont(): def inner_of_box_1(x, y, z): if (-1 < x < 1) and (-1 < y < 1) and (-1 < z < 1): return 4.5 return 0 def inner_of_box_2(x, y, z): rad_pos = (x**2 + y**2 + z**2)**0.5 if rad_pos <= 0.2: return 1 if rad_pos <= 0.5: return 0.5 if rad_pos <= 0.8: return 0.1 return 0 cuboid_coordinates = { 'x1': -1, 'x2': 1, 'y1': -1, 'y2': 1, 'z1': -1, 'z2': 1 } number_rays = {'dim_1': 2, 'dim_2': 2} source_point = np.array([5, 0, 0]) middle = middle_of_cuboid(cuboid_coordinates) diag = length_main_diagonal(cuboid_coordinates) pv, nv = shadow_plane_maker(source_point, cuboid_coordinates) vx, vy = get_parameter_plane_vectors(nv) factor_x = length_vector_for_diag(vx, diag) factor_y = length_vector_for_diag(vy, diag) factor_array_x = divide_the_factor(factor_x, number_rays['dim_1']) factor_array_y = divide_the_factor(factor_y, number_rays['dim_2']) points = create_ray_points(factor_array_x, factor_array_y, vx, vy, middle) rays = create_rays(source_point, points) k_trafo_cont_value_1 = k_trafo_cont(rays, inner_of_box_1) k_trafo_cont_value_2 = k_trafo_cont(rays, inner_of_box_2) # for comparison l1 = line_integral_cont(rays[0], inner_of_box_1) l2 = line_integral_cont(rays[0], inner_of_box_2) # since the functions are symmetric for the 4 rays we can just take exp(-l1) # since we would sum up 4 times the same value and divide it by 4 afterwards np.testing.assert_almost_equal(k_trafo_cont_value_1, np.exp(-l1), decimal=2) np.testing.assert_almost_equal(k_trafo_cont_value_2, np.exp(-l2), decimal=2)
cuboid_coordinates = { 'x1': -1, 'x2': 1, 'y1': -1, 'y2': 1, 'z1': -1, 'z2': 1 } fineness = 10**3 number_rays = {'dim_1': i, 'dim_2': i} source_point = np.array([3, 0, 0]) diag = length_main_diagonal(cuboid_coordinates) middle = middle_of_cuboid(cuboid_coordinates) pv, nv = shadow_plane_maker(source_point, cuboid_coordinates) vx, vy = get_parameter_plane_vectors(nv) factor_x = length_vector_for_diag(vx, diag) factor_y = length_vector_for_diag(vy, diag) factor_array_x = divide_the_factor(factor_x, number_rays['dim_1']) factor_array_y = divide_the_factor(factor_y, number_rays['dim_2']) points = create_ray_points(factor_array_x, factor_array_y, vx, vy, middle) rays = create_rays(source_point, points) k_transform_result = k_trafo_cont(rays, inner_of_box, fineness) results += [k_transform_result] results = np.asarray(results) np.save("results_different_number_arrays", results)
def test_divide_the_factor(): factor_array = divide_the_factor(10, 3) np.testing.assert_equal(np.array([-5, 0, 5]), factor_array) factor_array = divide_the_factor(1, 1) np.testing.assert_equal(np.array([0]), factor_array)
def generate_everything(number_ktrans, cuboid_coordinates, number_rays, steps, inner_of_box): """ Generates the source points and k-tra values by simply moving the source around them. we firmly assume here that the k-transforms lie at the same distance in a circle (with radius 2) around the box """ source_point_d = {} pv_d = {} nv_d = {} vx_d = {} vy_d = {} factor_x_d = {} factor_y_d = {} factor_x_array_d = {} factor_y_array_d = {} points_d = {} rays_d = {} ktra_v = np.zeros(number_ktrans) middle = middle_of_cuboid(cuboid_coordinates) diag = length_main_diagonal(cuboid_coordinates) for i in np.arange(number_ktrans): source_point = 2 * np.array([ np.sin(2 * np.pi * i / number_ktrans), np.cos(2 * np.pi * i / number_ktrans), 0 ]) source_point_d[i] = source_point pv, nv = shadow_plane_maker(source_point, cuboid_coordinates) pv_d[i] = pv nv_d[i] = nv vx, vy = get_parameter_plane_vectors(nv) vx_d[i] = vx vy_d[i] = vy factor_x = length_vector_for_diag(vx, diag) factor_y = length_vector_for_diag(vy, diag) factor_x_d[i] = factor_x factor_y_d[i] = factor_y factor_array_x = divide_the_factor(factor_x, number_rays['dim_1']) factor_array_y = divide_the_factor(factor_y, number_rays['dim_2']) factor_x_array_d[i] = factor_array_x factor_y_array_d[i] = factor_array_y points = create_ray_points(factor_array_x, factor_array_y, vx, vy, middle) points_d[i] = points rays = create_rays(source_point, points) rays_d[i] = rays x_cor, y_cor, z_cor = coordinate_discretization( cuboid_coordinates, steps) values = discretization_of_model(x_cor, y_cor, z_cor, inner_of_box, steps) line_matrices_d = lineintegral_matrices_maker(rays_d, steps, x_cor, y_cor, z_cor) big_line_matrix_array = np.array([ np.array(list(line_matrices_d[i].values())) for i in range(number_ktrans) ]) ktra_v = k_transform(values, big_line_matrix_array) touched = important_mini_cuboids(x_cor, y_cor, z_cor, steps, rays_d, values) return big_line_matrix_array, ktra_v, touched, values, x_cor, y_cor, z_cor, rays_d