Utilities#

Plotting, quadrature, and helper functions.

Quadrature#

torch-harmonics supports several quadrature rules for the latitudinal direction. Each corresponds to a grid keyword accepted by the SHT and convolution layers:

Grid string

Quadrature rule

Nodes

Key properties

"equiangular"

Clenshaw–Curtis

Equally spaced in \(\theta\) (including poles)

Default grid. Exact for polynomials up to degree \(N-1\). Simple, FFT-friendly.

"legendre-gauss"

Gauss–Legendre

Roots of \(P_N(\cos\theta)\)

Exact for polynomials up to degree \(2N-1\). Optimal accuracy per node, but nodes are non-uniform.

"lobatto"

Gauss–Lobatto

Roots of \(P'_{N-1}(\cos\theta)\), plus endpoints

Exact for polynomials up to degree \(2N-3\). Includes both poles, useful when pole values are needed.

"equiangular-trapezoidal"

Trapezoidal

Equally spaced

Supports periodic grids. Lower-order accuracy but simplest structure.

The longitudinal direction always uses equispaced nodes (see precompute_longitudes).

precompute_longitudes

precompute_latitudes

legendre_gauss_weights

Helper routine which returns the Legendre-Gauss nodes and weights on the interval [a, b]

lobatto_weights

Helper routine which returns the Legendre-Gauss-Lobatto nodes and weights on the interval [a, b]

clenshaw_curtiss_weights

Computation of the Clenshaw-Curtis quadrature nodes and weights.

trapezoidal_weights

Helper routine which returns equiangular-trapezoidal nodes with trapezoidal weights on the interval [a, b]

Plotting#

plot_sphere

Plots a function defined on the sphere using pcolormesh

imshow_sphere

Displays an image on the sphere

Truncation#

truncate_sht

Determine the maximum spherical harmonic degree and order for an SHT based on the spatial grid.

Debugging#

torch_harmonics.distributed.config#

Module-level configuration for torch_harmonics.distributed. Env vars are used as defaults but can be overridden programmatically, e.g.:

from torch_harmonics.distributed import config config.debug = True

The config object exposes a single boolean property, debug. When enabled, the distributed primitives perform extra shape-verification checks on every collective call, which is useful for diagnosing partitioning mismatches.

from torch_harmonics.distributed import config

# enable programmatically
config.debug = True

# or via environment variable (before importing)
# TORCH_HARMONICS_DISTRIBUTED_DEBUG=1