Filtering on the sphere

The generalized convolution of vectors and tensors, its spin-weighted transforms and its analysis.

CoarseGrainingEnergyFluxes.Filtering.AbstractSpinTransforms — Type
AbstractSpinTransforms

Spin-weighted spherical harmonic transforms of spin 0, 1 and 2 over every cell of a spherical grid, built by spin_transforms, in the grid's element type. A subtype defines

  • spin_field(tr): a zeroed complex field array of the kind they read and write;
  • spin_field_size(tr): its size;
  • spin_position(tr): a callable taking a cell's linear index to its position in that array;
  • spin_coefficients(tr): a zeroed coefficient array;
  • spin_transfer_buffer(tr): a zeroed host vector of one entry per degree a coefficient array carries, from 0, for the transfer Ĝ;
  • spin_analyze!(C, F, tr, s): the coefficients of the spin-s field F into C;
  • spin_synthesize!(F, C, W, Ĝ, tr, s): into F, the spin-s field whose degree-n coefficients are Ĝ[n+1] times those of C, with W a coefficient array to scale in. C is left as it is;
  • spin_ladder_synthesize!(F, C, W, d, tr, s, t): into F, the spin-t field ð (t = s + 1) or ð̄ (t = s − 1) of the spin-s field whose coefficients are C, its degree-n coefficients scaled by d[n+1].

and may define spin_host(tr), whether its arrays are host memory, true unless it says otherwise; a device workspace stages its fields through host copies for transforms that run there. Transforms whose analysis is the quadrature Aᴴ W define spin_weights, which a LeastSquares analysis reads.

source
CoarseGrainingEnergyFluxes.Filtering.AutoAnalysis — Type
AutoAnalysis() <: AbstractAnalysis

Quadrature on Gauss–Legendre and reduced Gaussian samplings, where it is exact, and on grids whose sampling may be regional (none, latitude–longitude or scattered), where it is the zero-extended field's integral; LeastSquares on every other spherical sampling, whose quadrature is not exact at its band limit (Fejér, Driscoll–Healy, McEwen–Wiaux, HEALPix, cubed-sphere, icosahedral, Yin–Yang). A latitude–longitude grid over the whole sphere takes LeastSquares() by name.

source
CoarseGrainingEnergyFluxes.Filtering.CartesianComponents — Type
CartesianComponents <: AbstractVectorFilter

The scalar filter of each ambient Cartesian component of a vector, and of each Cartesian component of a tensor, rotated back to the local frame (Aluie 2019, eq. 41). On the surface of a sphere it equals GeneralizedConvolution for a tangent field with no divergence, whose Cartesian components of degree n are spherical harmonics of degree n; the components of a divergent field's degree-n part carry degrees n ± 1, which it filters with Ĝ(n ± 1), and it gives a tangent field a radial component, which a tangent diagnostic drops. It is how a vector is filtered under Deformable, which is no convolution, and on a spheroid.

source
CoarseGrainingEnergyFluxes.Filtering.GeneralizedConvolution — Type
GeneralizedConvolution(; lmax = nothing, analysis = AutoAnalysis()) <: AbstractVectorFilter

The convolution of vectors and rank-2 tensors on a sphere of Aluie (2019, eqs. 58 and 121): every degree-n vector or tensor spherical harmonic is multiplied by the kernel's Ĝ(n) (Kernels.spectral_transfer_degrees!), so filtering commutes with the surface gradient, divergence and curl (Propositions 1–3). It runs as spin-weighted transforms of the field extended by zero over the sphere (spin_transforms): FastSphericalHarmonics' on a Float64 Fejer1Sampling grid of 2N − 1 by N, NUFSHT's on every other spherical grid when a NUFFT library is loaded to run it, and otherwise the direct sums, RingSpinTransforms on a latitude–longitude StructuredGrid and DirectSpinTransforms elsewhere. The theory page derives the spin-weighted form.

lmax is the highest degree the NUFSHT and direct transforms carry, nothing the grid's spin_band_limit. FastSphericalHarmonics transforms at its grid's own band limit, so a given lmax selects another transform under transform = AutoSpectralBackend(). analysis is how the NUFSHT and direct transforms take coefficients (AbstractAnalysis); FastSphericalHarmonics' transform is exact on its grid.

source
CoarseGrainingEnergyFluxes.Filtering.LeastSquares — Type
LeastSquares(; rtol = nothing, maxiter = 100) <: AbstractAnalysis

The coefficients minimizing Σ_k w_k |F_k − Σ_ℓm C_ℓm ₛY_ℓm(x_k)|² over the grid's cells, by FlowTransformBindings' lsmr! in the inner product of the cells' measures, whose first iterate is the Quadrature. It recovers a field of degree at most lmax wherever the cells determine its coefficients, whatever the quadrature's accuracy. rtol bounds ‖Aᴴ W r‖ / ‖Aᴴ W F‖. nothing takes max(1e-12, 100 eps(T)) in the generalized convolution's transforms, and max(10 tol, √eps(T)) in a NUFSHT spectral plan, whose NUFFT tolerance tol bounds the fit's accuracy. A fit that stops at maxiter keeps its last iterate and reports through analysis_status.

source
CoarseGrainingEnergyFluxes.Filtering.Quadrature — Type
Quadrature() <: AbstractAnalysis

The coefficients by the quadrature over the grid's cells, C_ℓm = Σ_k w_k F_k conj(ₛY_ℓm(x_k)), w_k the cell's measure over R². It is exact for a field of degree at most lmax where the measure integrates degree 2lmax exactly, as Gauss–Legendre rows do to lmax = nrings − 1, and over a regional grid it is the integral of the field extended by zero over the sphere.

source
CoarseGrainingEnergyFluxes.Filtering._spin_nodes — Method
_spin_nodes(grid) -> (θ, φ, w)

Host vectors, in the grid's element type and its linear cell order, of every cell's colatitude, its longitude in [0, 2π) and its measure over R², the quadrature weight of a transform on the unit sphere.

source
CoarseGrainingEnergyFluxes.Filtering.resolve_vector_filter — Method
resolve_vector_filter(grid, mask_strategy, vector_filter) -> AbstractVectorFilter

The filter a diagnostic applies to a vector on grid under mask_strategy. On the surface of a sphere, nothing takes GeneralizedConvolution under ZeroFill and CartesianComponents under Deformable, and a given filter is taken as given. Everywhere else it is CartesianComponents(): on a plane and in a volume, whose kernel is a ball of the ambient space, the convolution of each Cartesian component is the generalized convolution there; on a spheroid it is the only one defined. A GeneralizedConvolution given under Deformable or on a spheroid raises an ArgumentError.

source
CoarseGrainingEnergyFluxes.Filtering.spin_band_limit — Method
spin_band_limit(grid) -> Int

The highest spherical-harmonic degree grid's cells resolve, at least 2: the band limit of a sampling that ties its ring count to one (SphericalSampling.has_bandlimit), and otherwise ⌈πR/√A⌉ − 1, the degree whose half wavelength is the side √A of the grid's largest cell.

source
CoarseGrainingEnergyFluxes.Filtering.spin_ladder_synthesize! — Function
spin_ladder_synthesize!(F, C, W, d, tr, s, t) -> F

Into F, the spin-t field ð (t = s + 1) or ð̄ (t = s − 1) of the spin-s field whose coefficients are C, ð and ð̄ the Newman–Penrose operators on the unit sphere, with its degree-n coefficients scaled by d[n + 1]. The caller folds the ladder factor √((n − s)(n + s + 1)) or −√((n + s)(n − s + 1)) into d; each transform applies the phases of its own harmonics. W is a coefficient array to scale in.

source
CoarseGrainingEnergyFluxes.Filtering.spin_transforms — Method
spin_transforms(transform, grid; lmax = nothing, nthreads = 1, nufft = AutoSpectralBackend(),
                execution = SerialBackend()) -> AbstractSpinTransforms

The spin transforms of GeneralizedConvolution over grid's cells, for a workspace whose loops run under the local backend execution, a library's on nthreads threads. transform = AutoSpectralBackend() takes FastSphericalHarmonics on its own grids when lmax is nothing, NUFSHT on every spherical grid where it is loaded with a NUFFT library (nufft, or under Auto NonuniformFFTs or FINUFFT), and the direct sum otherwise. DirectSumSpectralBackend() takes the direct sum: RingSpinTransforms on a latitude–longitude StructuredGrid, DirectSpinTransforms on any other grid. A library named that no loaded extension provides raises an ArgumentError.

source
CoarseGrainingEnergyFluxes.Filtering.DirectSpinTransforms — Type
DirectSpinTransforms(grid; lmax = nothing, execution = SerialBackend())

The spin-weighted transforms of GeneralizedConvolution by direct summation over the cells of a spherical grid, for any spin |s| ≤ 2, in the grid's element type and in the memory of the local backend execution, whose loops run them. With ₛY_ℓm(θ, φ) = N_ℓ d^ℓ_{m,−s}(θ) e^{imφ}, N_ℓ = √((2ℓ+1)/4π) and θ the colatitude, the analysis is the quadrature C_ℓm = Σ_k w_k F_k conj(ₛY_ℓm(x_k)) with w_k the cell's measure over R², one work item per order m, and the synthesis is F_k = Σ_ℓm Ĝ(ℓ) C_ℓm ₛY_ℓm(x_k), one work item per cell. The coefficients are C[ℓ+1, m+lmax+1].

The Wigner d^ℓ_{m,−s} run up FlowTransformBindings' recurrence in ℓ from ℓ₀ = max(|m|, |s|), a value below the floating-point range carried with its own scale, so an order whose start lies below the range keeps the values it reaches at higher degree. A transform costs O(M·lmax²) over M cells and fills its spin's step coefficients, O(lmax²). lmax = nothing takes spin_band_limit.

source
CoarseGrainingEnergyFluxes.Filtering._wigner_nodes — Method
_wigner_nodes(T, S, θ) -> (; x, xl, u, pos, lc, ls, cs)

Per colatitude θ_k: cos θ_k as x + xl to twice T's precision (the plain step's), pos = θ_k ≤ π/2 and u = 2sin²(θ_k/2) where pos, 2cos²(θ_k/2) elsewhere (Reinsch's), and log₂ cos(θ_k/2), log₂ sin(θ_k/2) and cos(θ_k/2) sin(θ_k/2) in S, which the starting values read.

source
CoarseGrainingEnergyFluxes.Filtering.RingSpinTransforms — Type
RingSpinTransforms(grid; lmax = nothing, execution = SerialBackend())

The sums of DirectSpinTransforms on a two-dimensional latitude–longitude grid, whose rows share a colatitude. The analysis is C_ℓm = Σ_j N_ℓ d^ℓ_{m,−s}(θ_j) Σ_i w_ij F_ij e^{−imφ_i}: the sums along every row are taken at once by the grid's DenseLongitudes, or with an FFT library loaded on a whole ring of uniform longitude by one FFT per row, and the Wigner recurrence runs once per row and order, one work item per order, two degrees a pass over the rows. The synthesis is its transpose with Ĝ(ℓ). A transform costs O(nlat·lmax²) for the recurrence and O(M·lmax) for the dense longitude sums, O(M log nlon) by FFT, over M cells. lmax = nothing takes spin_band_limit.

source
CoarseGrainingEnergyFluxes.Filtering.SpinFit — Type
SpinFit

What a LeastSquares analysis holds over a spin transforms' arrays: √w laid out as the field, a field and a coefficient array of scratch, the unit transfer, FlowTransformBindings' LSMR workspace, the stopping rule, the worst outcome of the fits it has run (converged == false with no iterations before the first), and whether it has run one.

source