Esempio n. 1
0
def _sample_sh_cube(size, J, version=3):  # pylint: disable=W0613
    '''
    Sample spherical harmonics in a cube.
    No bandlimiting considered, aliased regions need to be cut by windowing!
    :param size: side length of the kernel
    :param J: order of the spherical harmonics
    '''
    with torch_default_dtype(torch.float64):
        rng = torch.linspace(-((size - 1) / 2), (size - 1) / 2, steps=size)

        Y_J = torch.zeros(2 * J + 1, size, size, size, dtype=torch.float64)
        for idx_x, x in enumerate(rng):
            for idx_y, y in enumerate(rng):
                for idx_z, z in enumerate(rng):
                    if x == y == z == 0:  # angles at origin are nan, special treatment
                        if J == 0:  # Y^0 is angularly independent, choose any angle
                            Y_J[:, idx_x, idx_y,
                                idx_z] = spherical_harmonics(0, 123,
                                                             321)  # [m]
                        else:  # insert zeros for Y^J with J!=0
                            Y_J[:, idx_x, idx_y, idx_z] = 0
                    else:  # not at the origin, sample spherical harmonic
                        alpha, beta = x_to_alpha_beta([x, y, z])
                        Y_J[:, idx_x, idx_y,
                            idx_z] = spherical_harmonics(J, alpha, beta)  # [m]

    assert Y_J.dtype == torch.float64
    return Y_J  # [m, x, y, z]
Esempio n. 2
0
def _sample_Y(n, J, alpha, beta, gamma, version=2):  # pylint: disable=W0613
    grid_beta, grid_alpha = beta_alpha(n)

    Y_J = np.zeros((2 * J + 1, len(grid_beta.flatten())))
    for idx, (b, a) in enumerate(zip(grid_beta.flatten(), grid_alpha.flatten())):
        ra, rb, _ = compose(-gamma, -beta, -alpha, a, b, 0)
        Y_J[:, idx] = spherical_harmonics(J, ra, rb)

    return Y_J