NUFSHT.jl

Non-Uniform Fast Spherical Harmonic Transforms — native Julia implementation of the Double Fourier Sphere (DFS) + NUFFT algorithm for spherical harmonic transforms at arbitrary scattered (colatitude, longitude) points.

Results

Synthesis + Round-Trip Accuracy (10⁻¹¹ relative error)

Synthesis and Accuracy

Inversion at Arbitrary Scattered Points

Inversion

Spectral Filtering

Spectral Filtering

Ocean Mask + Renormalization

Mask Renorm

What it does

Given a field sampled at M arbitrary points on the sphere, NUFSHT.jl can:

  • Synthesise (Type 2): Evaluate a bandlimited field (given as SH coefficients) at any scattered point set in O(K log K + M) time.
  • Adjoint (Type 1): Apply A†, the transpose of the synthesis, to scattered values. It carries no quadrature weights.
  • Analyze: The coefficients of a sampled field, nusht_analyze!: with quadrature weights the weighted adjoint Σⱼ wⱼ fⱼ conj(Y_lm(xⱼ)), one transform; without them the least-squares fit.
  • Solve (LSMR): Exactly invert the synthesis operator at any scattered point set.
  • Filter: Apply isotropic spectral filters (Gaussian, top-hat, custom) entirely in harmonic space.

Quick start

using Pkg
Pkg.add(url="https://github.com/jbphyswx/NUFSHT.jl")
using NUFSHT, FastSphericalHarmonics

lmax = 30
θ = rand(5000) .* π       # colatitudes ∈ (0,π)
φ = rand(5000) .* 2π      # longitudes ∈ [0,2π)
plan = make_plan(θ, φ, lmax; tol=1e-8)

# Synthesise at scattered points
C = zeros(lmax+1, 2lmax+1)
C[sph_mode(2, 0)] = 1.0
f = zeros(length(θ))
nusht_type2!(f, C, plan)

# Exact inversion at the scattered points
C_rec = allocate_coefficients(plan)
C_rec, iters, rel_res, converged = nusht_solve!(C_rec, f, plan; rtol=1e-6)

Which function should I use?

ScenarioFunction
Evaluate SH expansion at scattered pointsnusht_type2!
Apply the adjoint A†nusht_type1!
Coefficients from points with quadrature weightsnusht_analyze!(C, f, plan; weights)
Invert at arbitrary scattered pointsnusht_solve!
Convert scalar coefficients to spin-0 ones and backscalar_to_spin0!, spin0_to_scalar!
Apply spectral filter at scattered pointsnusht_filter!
Filter with land/ocean masknusht_filter! + nusht_filter_renorm!

Contents

Module

NUFSHT.NUFSHT — Module
NUFSHT.jl — Non-Uniform Fast Spherical Harmonic Transform (native Julia)

Double Fourier Sphere (DFS) + nuFFT spherical harmonic transforms at arbitrary scattered (colatitude, longitude) points. The synthesis operator factors as A = N·F·S:

  • S (plan_sph2fourier): the Legendre step, taking SH coefficients to the Double-Fourier-Sphere bivariate Fourier series. No equiangular grid is formed.
  • F (_assemble_modes!): the cos/sin bivariate Fourier basis S produces, rewritten as the complex exponentials a NUFFT evaluates. The φ axis carries wavenumbers -lmax…lmax, the θ axis -(lmax+1)…lmax+1 — one further out, because the coefficient array's supernumerary slots hold degrees up to lmax+|m| and an odd-order column reaches θ-frequency lmax+1.
  • N (NUFFT type 2 / type 1): non-uniform FFT evaluating the 2D Fourier series at the scattered points. A real-eltype plan on a backend with a real-data transform stores only kθ ≥ 0 and lets that backend supply the Hermitian half, halving both the mode array and the spreading.

A NUSHTplan owns persistent NUFFT plans (built once over the nodes) and every work buffer, so repeated transforms — filtering, or the hundreds of matvecs in nusht_solve! — allocate nothing and never re-plan. On device nodes the scalar plan is a RingNUSHTplan, whose S is the ring S-step of a spin-0 plan, as every spin plan's is. All calls transform a batch of B = plan.B co-located fields (ntrans); B = 1 methods accept plain vectors/matrices. The NUFFT is FlowTransformBindings' (NonuniformFFTs or FINUFFT), or the in-core direct sum.

References

  • Merilees (1973); Townsend & Olver (2015); Reinecke & Seljebotn (2013, A&A 554 A112); Keiner, Kunis & Potts (2009); Belkner et al. (2024, arXiv:2406.14542).
  • FastSphericalHarmonics.jl, FastTransforms.jl, FINUFFT.jl, NonuniformFFTs.jl.
source