Пример #1
0
def check_S3_quadint_equals_numint(l=1, m=1, n=1, b=10):
    # Create grids on the sphere
    x = S3.meshgrid(b=b, grid_type='SOFT')
    x = np.c_[x[0][..., None], x[1][..., None], x[2][..., None]]

    # Compute quadrature weights
    w = S3.quadrature_weights(b=b, grid_type='SOFT')

    # Define a polynomial function, to be evaluated at one point or at an array of points
    def f1(alpha, beta, gamma):
        df = wigner_D_function(l=l, m=m, n=n, alpha=alpha, beta=beta, gamma=gamma)
        return df * df.conj()

    def f1a(xs):
        d = np.zeros(x.shape[:-1])
        for i in range(d.shape[0]):
            for j in range(d.shape[1]):
                for k in range(d.shape[2]):
                    d[i, j, k] = f1(xs[i, j, k, 0], xs[i, j, k, 1], xs[i, j, k, 2])
        return d

    # Obtain the "true" value of the integral of the function over the sphere, using scipy's numerical integration
    # routines
    i1 = S3.integrate(f1, normalize=True)

    # Compute the integral using the quadrature formulae
    i1_w = S3.integrate_quad(f1a(x), grid_type='SOFT', normalize=True, w=w)

    # Check error
    print(b, l, m, n, 'results:', i1_w, i1, 'diff:', np.abs(i1_w - i1))
    assert np.isclose(np.abs(i1_w - i1), 0.0)
Пример #2
0
def naive_conv(l1=1, m1=1, l2=1, m2=1, g_parameterization='EA313'):
    f1 = lambda t, p: sh(l=l1,
                         m=m1,
                         theta=t,
                         phi=p,
                         field='real',
                         normalization='quantum',
                         condon_shortley=True)
    f2 = lambda t, p: sh(l=l2,
                         m=m2,
                         theta=t,
                         phi=p,
                         field='real',
                         normalization='quantum',
                         condon_shortley=True)

    theta, phi = S2.meshgrid(b=3, grid_type='Gauss-Legendre')
    f1_grid = f1(theta, phi)
    f2_grid = f2(theta, phi)

    alpha, beta, gamma = S3.meshgrid(b=3,
                                     grid_type='SOFT')  # TODO check convention

    f12_grid = np.zeros_like(alpha)
    for i in range(alpha.shape[0]):
        for j in range(alpha.shape[1]):
            for k in range(alpha.shape[2]):
                f12_grid[i, j, k] = naive_S2_conv_v2(f1, f2, alpha[i, j, k],
                                                     beta[i, j, k], gamma[i, j,
                                                                          k],
                                                     g_parameterization)
                print(i, j, k, f12_grid[i, j, k])

    return f1_grid, f2_grid, f12_grid
Пример #3
0
def compare_naive_and_spectral_conv():

    f1 = lambda t, p: sh(l=2,
                         m=1,
                         theta=t,
                         phi=p,
                         field='real',
                         normalization='quantum',
                         condon_shortley=True)
    f2 = lambda t, p: sh(l=2,
                         m=1,
                         theta=t,
                         phi=p,
                         field='real',
                         normalization='quantum',
                         condon_shortley=True)

    theta, phi = S2.meshgrid(b=4, grid_type='Gauss-Legendre')
    f1_grid = f1(theta, phi)
    f2_grid = f2(theta, phi)

    alpha, beta, gamma = S3.meshgrid(b=4,
                                     grid_type='SOFT')  # TODO check convention

    f12_grid_spectral = spectral_S2_conv(f1_grid,
                                         f2_grid,
                                         s2_fft=None,
                                         so3_fft=None)

    f12_grid = np.zeros_like(alpha)
    for i in range(alpha.shape[0]):
        for j in range(alpha.shape[1]):
            for k in range(alpha.shape[2]):
                f12_grid[i, j, k] = naive_S2_conv(f1, f2, alpha[i, j, k],
                                                  beta[i, j, k], gamma[i, j,
                                                                       k])
                print(i, j, k, f12_grid[i, j, k])

    return f1_grid, f2_grid, f12_grid, f12_grid_spectral