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 |
|---|---|---|---|
|
Clenshaw–Curtis |
Equally spaced in \(\theta\) (including poles) |
Default grid. Exact for polynomials up to degree \(N-1\). Simple, FFT-friendly. |
|
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. |
|
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. |
|
Trapezoidal |
Equally spaced |
Supports periodic grids. Lower-order accuracy but simplest structure. |
The longitudinal direction always uses equispaced nodes (see
precompute_longitudes).
Helper routine which returns the Legendre-Gauss nodes and weights on the interval [a, b] |
|
Helper routine which returns the Legendre-Gauss-Lobatto nodes and weights on the interval [a, b] |
|
Computation of the Clenshaw-Curtis quadrature nodes and weights. |
|
Helper routine which returns equiangular-trapezoidal nodes with trapezoidal weights on the interval [a, b] |
Plotting#
Plots a function defined on the sphere using pcolormesh |
|
Displays an image on the sphere |
Truncation#
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