def test_rotate_zonal_harmonics_random(self): """Tests the outputs of test_rotate_zonal_harmonics.""" dtype = tf.float64 max_band = 2 zonal_coeffs = tf.constant(np.random.uniform(-1.0, 1.0, size=[3]), dtype=dtype) tensor_size = np.random.randint(3) tensor_shape = np.random.randint(1, 10, size=(tensor_size)).tolist() theta = tf.constant(np.random.uniform(0.0, np.pi, size=tensor_shape + [1]), dtype=dtype) phi = tf.constant(np.random.uniform(0.0, 2.0 * np.pi, size=tensor_shape + [1]), dtype=dtype) rotated_zonal_coeffs = spherical_harmonics.rotate_zonal_harmonics( zonal_coeffs, theta, phi) zonal_coeffs = spherical_harmonics.tile_zonal_coefficients( zonal_coeffs) l, m = spherical_harmonics.generate_l_m_permutations(max_band) l = tf.broadcast_to(l, tensor_shape + l.shape.as_list()) m = tf.broadcast_to(m, tensor_shape + m.shape.as_list()) theta_zero = tf.constant(0.0, shape=tensor_shape + [1], dtype=dtype) phi_zero = tf.constant(0.0, shape=tensor_shape + [1], dtype=dtype) gt = zonal_coeffs * spherical_harmonics.evaluate_spherical_harmonics( l, m, theta_zero, phi_zero) gt = tf.reduce_sum(input_tensor=gt, axis=-1) pred = rotated_zonal_coeffs * spherical_harmonics.evaluate_spherical_harmonics( l, m, theta + theta_zero, phi + phi_zero) pred = tf.reduce_sum(input_tensor=pred, axis=-1) self.assertAllClose(gt, pred)
def test_tile_zonal_coefficients_jacobian_random(self): """Tests the jacobian of tile_zonal_coefficients.""" zonal_coeffs_init = np.random.uniform(size=(1, )) zonal_coeffs = tf.convert_to_tensor(value=zonal_coeffs_init) y = spherical_harmonics.tile_zonal_coefficients(zonal_coeffs) self.assert_jacobian_is_correct(zonal_coeffs, zonal_coeffs_init, y)
def test_tile_zonal_coefficients_preset(self): """Tests that tile_zonal_coefficients produces the expected results.""" self.assertAllEqual( spherical_harmonics.tile_zonal_coefficients((0, 1, 2)), (0, 1, 1, 1, 2, 2, 2, 2, 2))