API Reference
This page is generated from the docstrings of the public SHTnsKit module. Optional extension methods appear when their dependencies are loaded in the calling environment.
Calling conventions
- Allocating transforms use
operation(cfg, input...). - In-place transforms place outputs before inputs, for example
analysis!(plan, alm_out, field)andsynthesis!(plan, field_out, alm). analysis(CPU(), ...)andanalysis(GPU(), ...)request strict typed device dispatch; ordinary calls infer the backend from array storage.- Dense coefficients have shape
(cfg.lmax + 1, cfg.mmax + 1). Entries withl < mare unused. - Batch APIs add a third, field-index dimension.
- A configuration's
norm,cs_phase,real_norm, androbert_formoptions apply at every public transform boundary.
See Migrating to v2.0 for removed compatibility signatures and numerical changes.
Extension activation
| Extension | Load these packages |
|---|---|
| CUDA | CUDA, GPUArrays, GPUArraysCore, KernelAbstractions |
| AMDGPU | AMDGPU, GPUArrays, GPUArraysCore, KernelAbstractions |
| MPI | MPI, PencilArrays, PencilFFTs |
| LoopVectorization | LoopVectorization |
| ForwardDiff | ForwardDiff |
| Zygote | Zygote |
| Advanced AD | ChainRulesCore |
Hardware-specific types such as the CUDA extension's CuFFTPlan live in their extension module and are documented in GPU Acceleration.
Public API
SHTnsKit.BackendUnavailableError — Type
Raised when a requested compute backend cannot perform an operation.
SHTnsKit.CPU — Type
CPU compute device.
SHTnsKit.ComputeDevice — Type
Abstract supertype for compute devices supported by SHTnsKit.
SHTnsKit.GPU — Type
GPU compute device.
GPU() is vendor-neutral. A concrete CUDA or AMDGPU backend is inferred from an existing device array/prototype, or selected when exactly one loaded GPU adapter is functional.
SHTnsKit.SHTConfig — Method
SHTConfig(; lmax, mmax, mres, nlat, nlon, θ, φ, x, w, Nlm, cphi, st,
norm, cs_phase, real_norm, robert_form,
nlm, li, mi, nspat,
grid_type=:gauss, phi_scale=:auto, on_the_fly=false,
use_plm_tables=false, plm_tables=[], dplm_tables=[],
NP_tables=[], NdP_tables=[], norm_scale_matrix=Matrix{Float64}(undef,0,0),
_otf_scratch_P=[], _otf_scratch_dP=[], _otf_scratch_Ps=[], _otf_scratch_Pb=[], _m_order=[],
howmany=1, spec_dist=0, south_pole_first=false,
allow_padding=false, nlat_padded=0, spat_dist=0) -> SHTConfigFlat-kwargs constructor that packages the grid/normalization/tables/scratch kwargs into their respective sub-structs. Keeps the call-site syntax used by create_gauss_config, create_regular_config, copy(::SHTConfig), etc. identical to the pre-restructure behaviour.
SHTnsKit.SHTPlan — Type
SHTPlanPre-allocated working buffers and FFTW plans for zero-allocation transforms.
Thread Safety
WARNING: A single SHTPlan instance must NOT be used from multiple threads simultaneously. The internal buffers (P, dPdtheta, G, Fθk, etc.) are shared mutable state — concurrent calls to analysis! or synthesis! on the same plan will produce data races and incorrect results.
For multi-threaded use, create one SHTPlan per thread:
plans = [SHTPlan(cfg) for _ in 1:Threads.nthreads()]
Threads.@threads for i in 1:n
plan = plans[Threads.threadid()]
analysis!(plan, alm_out[i], fields[i])
endSHTnsKit.SHTPlan — Method
SHTPlan(cfg::SHTConfig; use_rfft=false)Create an optimized transform plan with pre-allocated buffers and FFT plans.
This constructor performs the "planning" phase: it allocates all working memory and optimizes FFTW plans for the specific grid configuration. The resulting plan can then be reused for many transforms without additional allocations.
Parameters:
- cfg: SHTConfig defining the grid and spectral resolution
- use_rfft: if true, use real-FFT along φ for scalar
analysis!/synthesis!(halves the Fourier buffer size). Vector (sphtor) transforms on the plan still use the complex buffer. Requirescfg.mmax ≤ cfg.nlon÷2.
SHTnsKit.SHTRotation — Type
struct SHTRotationHolds Euler angles and target sizes for rotation.
lmax, mmax: degrees/orders supported by the rotation.α, β, γ: Euler angles (ZYZ by default) in radians.conv::ZYZor:ZXZconvention.
SHTnsKit.SHTns37Capability — Type
SHTns37CapabilityOne required SHTns 3.7 mathematical capability on one execution backend. status is one of :required, :verified, or :unverified_hardware.
SHTnsKit.CI — Method
CI(a...)Shorthand constructor for CartesianIndex.
SHTnsKit.DistQstPlan — Method
Construct the parallel extension's concrete distributed QST plan.
SHTnsKit.DistSphtorPlan — Method
Construct the parallel extension's concrete distributed vector plan.
SHTnsKit.LM_cplx — Method
LM_cplx(cfg::SHTConfig, l::Integer, m::Integer) -> IntCompatibility helper that mirrors the C macro LM_cplx for mres == 1, returning the zero-based packed complex index for coefficient (l,m).
SHTnsKit.LM_cplx_index — Method
LM_cplx_index(lmax::Int, mmax::Int, l::Int, m::Int) -> IntPacked complex index for coefficient (l,m) where -min(l,mmax) ≤ m ≤ min(l,mmax). Matches SHTns LM_cplx macro (assumes mres == 1).
SHTnsKit.LM_index — Method
LM_index(lmax::Int, mres::Int, l::Int, m::Int) -> IntConvert 2D spherical harmonic indices (l,m) to a 1D packed array index. This implements the SHTns packing convention for efficient memory layout.
The packing scheme groups coefficients by m-order blocks, with each block containing all valid l-degrees for that m. This enables vectorized operations on modes with the same azimuthal symmetry.
Matches SHTns C macro: LM(shtns, l, m)
SHTnsKit.LiM_index — Method
LiM_index(lmax::Int, mres::Int, l::Int, im::Int) -> IntConvenience function to compute packed index using reduced m-index im. This is useful when iterating over m-modes using im = 0, 1, 2, ... instead of m = 0, mres, 2*mres, ...
Equivalent to LM_index(lmax, mres, l, im*mres). Matches SHTns macro: LiM(shtns, l, im)
SHTnsKit.SH_Xrotate90 — Method
SH_Xrotate90(cfg::SHTConfig, Qlm::AbstractVector{<:Complex}, Rlm::AbstractVector{<:Complex})Rotate around X-axis by 90 degrees using ZYZ equivalence: Rz(π/2)·Ry(π/2)·Rz(-π/2).
SHTnsKit.SH_Yrotate — Method
SH_Yrotate(cfg::SHTConfig, Qlm::AbstractVector{<:Complex}, alpha::Real, Rlm::AbstractVector{<:Complex})Rotate a real-field SH expansion around the Y-axis by angle alpha. Uses Wigner-d mixing per l; dispatches to the general rotation engine.
SHTnsKit.SH_Yrotate90 — Method
SH_Yrotate90(cfg::SHTConfig, Qlm::AbstractVector{<:Complex}, Rlm::AbstractVector{<:Complex})SHTnsKit.SH_Zrotate — Method
SH_Zrotate(cfg::SHTConfig, Qlm::AbstractVector{<:Complex}, alpha::Real, Rlm::AbstractVector{<:Complex})Rotate a real-field SH expansion around the Z-axis by angle alpha. Input and output are packed Qlm vectors (LM order, m ≥ 0). In-place supported if Rlm === Qlm.
SHTnsKit.SH_mul_mx — Method
SH_mul_mx(cfg::SHTConfig, mx::AbstractVector{<:Real}, Qlm::AbstractVector{<:Complex}, Rlm::AbstractVector{<:Complex})Apply a nearest-neighbor-in-l operator represented by mx to Qlm and write to Rlm. Both Qlm and Rlm are length cfg.nlm packed vectors (m≥0, SHTns LM order).
SHTnsKit.SH_to_grad_point — Method
SH_to_grad_point(cfg::SHTConfig, DrSlm::AbstractVector{<:Complex}, Slm::AbstractVector{<:Complex}, cost::Real, phi::Real)
-> vr, vt, vpEvaluate the gradient of a scalar field at a point. DrSlm supplies the radial derivative spectrum and Slm supplies the tangential gradient.
SHTnsKit.SH_to_lat — Method
SH_to_lat(cfg::SHTConfig, Qlm::AbstractVector{<:Complex}, cost::Real;
nphi::Int=cfg.nlon, ltr::Int=cfg.lmax, mtr::Int=cfg.mmax) -> Vector{<:Real}Evaluate a real field along a latitude (fixed cosθ = cost) at nphi equispaced longitudes. Uses orthonormal harmonics and packed real coefficients Qlm (LM order).
SHTnsKit.SH_to_lat_cplx — Method
SH_to_lat_cplx(cfg::SHTConfig, alm_packed::AbstractVector{<:Complex}, cost::Real; nphi::Int=cfg.nlon, ltr::Int=cfg.lmax) -> Vector{<:Complex}Evaluate a complex field along a latitude using packed LM_cplx coefficients.
SHTnsKit.SHqst_to_lat — Method
SHqst_to_lat(cfg::SHTConfig, Qlm::AbstractVector{<:Complex}, Slm::AbstractVector{<:Complex}, Tlm::AbstractVector{<:Complex}, cost::Real;
nphi::Int=cfg.nlon, ltr::Int=cfg.lmax, mtr::Int=cfg.mmax) -> Vr, Vt, VpEvaluate 3D field along latitude (cosθ = cost) at nphi longitudes from packed real spectra. Inputs Qlm, Slm, Tlm are all packed (LM order) vectors for each component.
SHTnsKit.SHqst_to_point — Method
SHqst_to_point(cfg::SHTConfig, Qlm::AbstractVector{<:Complex}, Slm::AbstractVector{<:Complex}, Tlm::AbstractVector{<:Complex}, cost::Real, phi::Real)
-> vr, vt, vpEvaluate 3D field at a single point using packed real spectra.
SHTnsKit.allocate_padded_spatial — Function
allocate_padded_spatial(cfg::SHTConfig, T::Type=Float64) -> Array{T}Allocate a spatial array with proper padding if enabled.
Returns a 2D array of size (nlatpadded, nlon) where nlatpadded >= nlat. The first nlat rows contain the actual data; remaining rows are padding.
Example
cfg = create_gauss_config(64, 66)
set_allow_padding!(cfg)
field = allocate_padded_spatial(cfg)
# field has size (nlat_padded, nlon), use field[1:cfg.nlat, :] for dataSHTnsKit.allocate_padded_spatial_batch — Function
allocate_padded_spatial_batch(cfg::SHTConfig, nfields::Int, T::Type=Float64) -> Array{T}Allocate spatial arrays for batch transforms with proper padding if enabled.
Returns a 3D array of size (nlat_padded, nlon, nfields).
SHTnsKit.analysis! — Method
analysis!(cfg::SHTConfig, alm_out::AbstractMatrix, f::AbstractMatrix)In-place forward transform. Writes coefficients into alm_out. alm_out must be size (lmax+1, mmax+1).
SHTnsKit.analysis! — Method
analysis!(plan::SHTPlan, alm_out::AbstractMatrix, f::AbstractMatrix)In-place forward scalar SHT writing coefficients into alm_out.
SHTnsKit.analysis — Method
analysis(cfg::SHTConfig, f::AbstractMatrix) -> Matrix{ComplexF64}Forward transform on Gauss-Legendre x equiangular grid. Returns coefficients alm[l+1, m+1] in the normalization, real-normalization, and phase convention configured by cfg.
Parallelizes over m-modes using static scheduling for consistent performance.
SHTnsKit.analysis_axisym — Method
analysis_axisym(cfg, Vr) -> Vector{ComplexF64}Axisymmetric (m=0) transform from Gauss latitudes to degree-only coefficients. Input Vr should contain values at Gauss latitudes for a specific longitude mode. Returns coefficients Q_l for l = 0..lmax.
SHTnsKit.analysis_axisym_l — Method
analysis_axisym_l(cfg, Vr, ltr) -> Vector{ComplexF64}Axisymmetric degree-limited transform up to degree ltr.
SHTnsKit.analysis_batch! — Method
analysis_batch!(cfg::SHTConfig, alm_out::AbstractArray{<:Complex,3},
fields::AbstractArray{<:Real,3})In-place batch forward transform.
SHTnsKit.analysis_batch — Method
analysis_batch(cfg::SHTConfig, fields::AbstractArray{<:Real,3}) -> Array{ComplexF64,3}Batch forward transform for multiple scalar fields.
Arguments
cfg: SHTConfig with batch size configuredfields: 3D array of shape(nlat, nlon, nfields)containing spatial data
Returns
- 3D array of shape
(lmax+1, mmax+1, nfields)with spectral coefficients
Performance
Batch processing is more efficient than processing fields individually because:
- Legendre polynomials are computed once and reused across all fields
- FFT plans are shared
- Better cache utilization from contiguous memory access patterns
SHTnsKit.analysis_packed — Method
analysis_packed(cfg, Vr_flat::AbstractVector{<:Real}) -> Vector{ComplexF64}Packed scalar analysis from flattened grid values (length nlat*nlon) to Qlm (LM order).
SHTnsKit.analysis_packed_cplx_l — Method
analysis_packed_cplx_l(cfg, z, ltr)Analyze a complex spatial field into full LM_cplx storage while computing only degrees l ≤ ltr; entries above the limit are zero.
SHTnsKit.analysis_packed_l — Method
analysis_packed_l(cfg::SHTConfig, Vr::AbstractVector{<:Real}, ltr::Integer) -> Vector{ComplexF64}Scalar analysis truncated to degrees l ≤ ltr. The returned packed coefficient vector has length cfg.nlm; coefficients with l > ltr are set to zero.
SHTnsKit.analysis_packed_ml — Method
analysis_packed_ml(cfg, im, Vr_m, ltr) -> Vector{<:Complex}Transform spatial field for one stored azimuthal order to spherical harmonic coefficients. im is the zero-based stored-order index, so the physical order is m = im * cfg.mres. Vr_m contains complex spatial values for that mode. Returns coefficients Q_l for degrees l = m..ltr.
SHTnsKit.analysis_qst — Method
analysis_qst(cfg, Vr, Vt, Vp) -> (Qlm, Slm, Tlm)Transform 3D spatial vector field to QST spectral coefficients. Input: radial (Vr), colatitude (Vt), and azimuthal (Vp) components.
SHTnsKit.analysis_qst_batch — Method
analysis_qst_batch(cfg::SHTConfig, Vr_batch::AbstractArray{<:Real,3},
Vt_batch::AbstractArray{<:Real,3}, Vp_batch::AbstractArray{<:Real,3})Batch QST analysis for multiple 3D vector fields.
Returns
(Qlm_batch, Slm_batch, Tlm_batch): Tuple of 3D arrays with Q, S, T coefficients
SHTnsKit.analysis_qst_cplx — Method
analysis_qst_cplx(cfg, Vr, Vt, Vp) -> (Qlm, Slm, Tlm)Transform complex spatial vector field to QST coefficients.
SHTnsKit.analysis_qst_l — Method
analysis_qst_l(cfg, Vr, Vt, Vp, ltr) -> (Qlm, Slm, Tlm)Degree-limited version of analysis_qst, computing coefficients only up to degree ltr.
SHTnsKit.analysis_qst_ml — Method
analysis_qst_ml(cfg, im, Vr_m, Vt_m, Vp_m, ltr) -> (Ql, Sl, Tl)Mode-limited transform for specific azimuthal mode im.
SHTnsKit.analysis_sphtor! — Method
analysis_sphtor!(plan::SHTPlan, Slm_out::AbstractMatrix, Tlm_out::AbstractMatrix, Vt::AbstractMatrix, Vp::AbstractMatrix)In-place vector analysis. Accumulates Slm/Tlm into preallocated outputs. Uses a two-pass strategy over φ FFTs to avoid extra buffers.
SHTnsKit.analysis_sphtor — Method
analysis_sphtor(cfg, Vt, Vp) -> (Slm, Tlm)Transform horizontal vector field components to spheroidal/toroidal coefficients.
SHTnsKit.analysis_sphtor_batch — Method
analysis_sphtor_batch(cfg::SHTConfig, Vt_batch::AbstractArray{<:Real,3},
Vp_batch::AbstractArray{<:Real,3})Batch spheroidal-toroidal analysis for multiple vector fields.
Arguments
cfg: SHTConfigVt_batch: 3D array(nlat, nlon, nfields)of theta componentsVp_batch: 3D array(nlat, nlon, nfields)of phi components
Returns
(Slm_batch, Tlm_batch): Tuple of 3D arrays(lmax+1, mmax+1, nfields)containing spheroidal and toroidal coefficients
SHTnsKit.analysis_sphtor_cplx — Method
analysis_sphtor_cplx(cfg, Vt, Vp) -> (Slm, Tlm)Transform complex horizontal vector components to spheroidal/toroidal coefficients.
SHTnsKit.build_li_mi — Method
build_li_mi(lmax::Int, mmax::Int, mres::Int)Build lookup arrays mapping packed indices to spherical harmonic (l,m) values. These arrays enable efficient iteration over spherical harmonic modes when working with packed coefficient arrays.
Returns (li, mi) where li[k] and mi[k] give the degree and order for the k-th packed coefficient.
SHTnsKit.compute_optimal_padding — Method
compute_optimal_padding(nlat::Int, nlon::Int; sizeof_real::Int=8) -> IntCompute the optimal padding to add between latitude lines to avoid cache bank conflicts. This mimics the SHTns C library's padding strategy.
Arguments
nlat: Number of latitude pointsnlon: Number of longitude points (phi)sizeof_real: Size of real number in bytes (default 8 for Float64)
Returns
The number of extra elements to add per latitude line (padding amount).
Details
The padding strategy aims to:
- Align memory on 32-byte or 64-byte boundaries
- Avoid 8KB cache bank conflicts
- Avoid L2 cache bank/channel conflicts (especially important for AMD GPUs)
This is most beneficial for:
- Large transforms where cache effects matter
- Multi-threaded transforms
- GPU computing
SHTnsKit.copy_from_padded! — Method
copy_from_padded!(dest::AbstractMatrix, src::AbstractMatrix, cfg::SHTConfig)Copy data from a padded spatial array to a contiguous spatial array.
SHTnsKit.copy_to_padded! — Method
copy_to_padded!(dest::AbstractMatrix, src::AbstractMatrix, cfg::SHTConfig)Copy data from a contiguous spatial array to a padded spatial array.
SHTnsKit.create_config — Method
create_config(lmax::Int; mmax=lmax, mres=1, nlat=lmax+2,
nlon=max(2*lmax+1,4),
norm::Symbol=:orthonormal, cs_phase::Bool=true,
real_norm::Bool=false, robert_form::Bool=false,
grid_type::Symbol=:gauss) -> SHTConfigCompatibility wrapper for configuration creation used in some docs/snippets. Supports Gauss–Legendre (grid_type = :gauss), regular equiangular (grid_type = :regular or :regular_poles), and Driscoll-Healy (grid_type = :driscoll_healy) grids, forwarding to the appropriate creator. nlat/nlon defaults are adjusted to satisfy accuracy constraints for the chosen grid.
SHTnsKit.create_config — Method
create_config(::Type{T}, lmax::Int, nlat::Int, mres::Int=1; kwargs...) -> SHTConfigCompatibility method that ignores the element type T and calls create_config. Provided to match older example signatures like create_config(Float64, 20, 22, 1).
SHTnsKit.create_gauss_config — Method
create_gauss_config(lmax::Int, nlat::Int; mmax::Int=lmax, nlon::Int=_default_nlon(lmax)) -> SHTConfigCreate a Gauss–Legendre based SHT configuration. Constraints:
nlat ≥ lmax+1for exactness up tolmaxin θ integration.nlon ≥ 2*mmax+1to resolve azimuthal orders up tommax.
SHTnsKit.create_gauss_config_spf — Method
create_gauss_config_spf(lmax::Int, nlat::Int; kwargs...) -> SHTConfigCreate a Gauss-Legendre configuration with south-pole-first latitude ordering.
This is equivalent to calling create_gauss_config followed by set_south_pole_first!. All keyword arguments are passed to create_gauss_config.
Example
# Create a south-pole-first configuration
cfg = create_gauss_config_spf(32, 34)
is_south_pole_first(cfg) # trueSee also: create_gauss_config, set_south_pole_first!
SHTnsKit.create_gauss_fly_config — Method
create_gauss_fly_config(lmax::Int, nlat::Int; kwargs...) -> SHTConfigCreate a Gauss–Legendre configuration with on-the-fly Legendre polynomial computation.
This mode computes Legendre polynomials during each transform instead of using precomputed tables. Benefits:
- Lower memory usage: No storage for P_l^m tables (saves O(lmax² × nlat) memory)
- Better for large lmax: When lmax is large, tables become memory-intensive
- Good cache behavior: On modern CPUs, on-the-fly computation can be faster due to better cache utilization
Trade-offs:
- May be slower for repeated transforms with small lmax
- No speedup from table precomputation
This mirrors the sht_gauss_fly mode in SHTns C library.
Arguments
Same as create_gauss_config.
Example
# For large lmax, on-the-fly mode saves significant memory
cfg = create_gauss_fly_config(1024, 1026)
# Performs transform computing Legendre polynomials on-the-fly
alm = analysis(cfg, field)See also: create_gauss_config, set_on_the_fly!, set_use_tables!
SHTnsKit.create_regular_config — Method
create_regular_config(lmax::Int, nlat::Int; mmax::Int=lmax, mres::Int=1,
nlon::Int=_default_nlon(lmax), norm::Symbol=:orthonormal,
cs_phase::Bool=true, real_norm::Bool=false,
robert_form::Bool=false, include_poles::Bool=false,
precompute_plm::Bool=true, use_dh_weights::Bool=false) -> SHTConfigCreate an equiangular (regular) grid configuration. Regular grids use Fejér's first rule on θ = (i+0.5)π/nlat nodes by default; set include_poles=true to use pole-inclusive Clenshaw–Curtis nodes and weights. By default associated Legendre tables are precomputed, which mirrors SHTns' regular-grid behaviour and improves performance.
Driscoll-Healy Quadrature
Set use_dh_weights=true to use Driscoll-Healy quadrature for exact spherical harmonic transforms. This requires:
include_poles=truenlat = 2*(lmax+1)for exactness up to degree lmaxnlatmust be even
The DH grid uses θ = πj/n for j=0,...,n-1 (includes north pole, excludes south pole) and provides exact quadrature via specially computed weights.
Reference: Driscoll & Healy (1994), "Computing Fourier transforms and convolutions on the 2-sphere", Adv. Appl. Math., 15, 202-250.
SHTnsKit.destroy_config — Method
destroy_config(cfg::SHTConfig)No-op placeholder for API symmetry with libraries that require explicit teardown.
SHTnsKit.disable_fft_plan_cache! — Function
disable_fft_plan_cache!(; clear::Bool=true)Disable distributed FFT plan caching. Pass clear=false to retain existing cache entries.
SHTnsKit.disable_padding! — Method
disable_padding!(cfg::SHTConfig)Disable memory padding. Spatial arrays will use contiguous memory without extra padding between latitude lines.
See also: set_allow_padding!, is_padding_enabled
SHTnsKit.disable_plm_tables! — Method
disable_plm_tables!(cfg::SHTConfig)Disable use of precomputed Legendre tables.
SHTnsKit.divergence_from_spheroidal — Method
divergence_from_spheroidal(cfg, Slm) -> MatrixReturn divergence spectral coefficients δlm corresponding to spheroidal modes via δlm = −l(l+1) Slm (`δ{00} = 0`).
SHTnsKit.enable_fft_plan_cache! — Function
enable_fft_plan_cache!()Convenience wrapper to enable distributed FFT plan caching.
SHTnsKit.enable_plm_tables! — Method
enable_plm_tables!(cfg::SHTConfig)Alias for prepare_plm_tables!.
SHTnsKit.energy_scalar — Method
energy_scalar(cfg, alm; real_field=true) -> Float64Compute the total energy of a scalar field from its spherical harmonic coefficients.
For a scalar field f(θ,φ) = Σ alm Yl^m(θ,φ), the energy is defined as: E = (1/2) ∫ |f|² dΩ = (1/2) Σ |a_lm|²
This represents the L² norm of the field, which is conserved under orthonormal spherical harmonic transforms (Parseval's identity).
SHTnsKit.energy_scalar_l_spectrum — Method
energy_scalar_l_spectrum(cfg, alm; real_field=true) -> Vector{Float64}Compute energy spectrum as a function of spherical harmonic degree l. Returns E(l) = Σₘ |a_lm|² for each l = 0..lmax.
SHTnsKit.energy_scalar_lm — Method
energy_scalar_lm(cfg, alm; real_field=true) -> Matrix{Float64}Compute per-mode energy distribution Elm = |alm|² for each (l,m) mode. Returns matrix of size (lmax+1, mmax+1) with energy contributions.
SHTnsKit.energy_scalar_m_spectrum — Method
energy_scalar_m_spectrum(cfg, alm; real_field=true) -> Vector{Float64}Compute energy spectrum as a function of spherical harmonic order m. Returns E(m) = Σₗ |a_lm|² for each m = 0..mmax.
SHTnsKit.energy_scalar_packed — Method
energy_scalar_packed(cfg, Qlm; real_field=true) -> Float64Compute energy from packed spectral coefficients (1D vector format).
SHTnsKit.energy_vector — Method
energy_vector(cfg, Slm, Tlm; real_field=true) -> Float64Compute the total kinetic energy of a vector field from spheroidal/toroidal coefficients.
For a vector field V = ∇×(T Yl^m êᵣ) + ∇ₕ(S Yl^m), the kinetic energy is: KE = (1/2) ∫ |V|² dΩ = (1/2) Σ [l(l+1)|Slm|² + l(l+1)|Tlm|²]
SHTnsKit.energy_vector_l_spectrum — Method
energy_vector_l_spectrum(cfg, Slm, Tlm; real_field=true) -> Vector{Float64}Compute kinetic energy spectrum by degree l for vector fields. Returns KE(l) = Σₘ l(l+1)[|Slm|² + |Tlm|²] for each l = 1..lmax.
SHTnsKit.energy_vector_lm — Method
energy_vector_lm(cfg, Slm, Tlm; real_field=true) -> Matrix{Float64}Compute per-mode kinetic energy KElm = l(l+1)[|Slm|² + |T_lm|²] for vector fields. Returns matrix of size (lmax+1, mmax+1) with energy contributions.
SHTnsKit.energy_vector_m_spectrum — Method
energy_vector_m_spectrum(cfg, Slm, Tlm; real_field=true) -> Vector{Float64}Compute kinetic energy spectrum by order m for vector fields. Returns KE(m) = Σₗ l(l+1)[|Slm|² + |Tlm|²] for each m = 0..mmax.
SHTnsKit.energy_vector_packed — Method
energy_vector_packed(cfg, Spacked, Tpacked; real_field=true) -> Float64Compute vector field kinetic energy from packed S and T coefficients.
SHTnsKit.enstrophy — Method
enstrophy(cfg, Tlm; real_field=true) -> Float64Compute the enstrophy (kinetic energy of vorticity) from toroidal coefficients.
For a toroidal field with coefficients Tlm, the enstrophy is: Z = (1/2) ∫ |∇×V|² dΩ = (1/2) Σ l²(l+1)²|Tlm|²
This is a measure of the small-scale intensity of rotational motion.
SHTnsKit.enstrophy_l_spectrum — Method
enstrophy_l_spectrum(cfg, Tlm; real_field=true) -> Vector{Float64}Compute enstrophy spectrum as a function of degree l. Returns Z(l) = Σₘ l²(l+1)²|T_lm|² for each l = 1..lmax.
SHTnsKit.enstrophy_lm — Method
enstrophy_lm(cfg, Tlm; real_field=true) -> Matrix{Float64}Compute per-mode enstrophy Zlm = l²(l+1)²|Tlm|² for each (l,m) mode. Returns matrix of size (lmax+1, mmax+1) with enstrophy contributions.
SHTnsKit.enstrophy_m_spectrum — Method
enstrophy_m_spectrum(cfg, Tlm; real_field=true) -> Vector{Float64}Compute enstrophy spectrum as a function of order m. Returns Z(m) = Σₗ l²(l+1)²|T_lm|² for each m = 0..mmax.
SHTnsKit.estimate_padding_overhead — Method
estimate_padding_overhead(cfg::SHTConfig) -> Float64Estimate the memory overhead from padding as a percentage.
Returns 0.0 if padding is disabled.
SHTnsKit.estimate_table_memory — Method
estimate_table_memory(lmax::Int, mmax::Int, nlat::Int) -> IntEstimate memory usage (in bytes) for precomputed Legendre polynomial tables.
Returns the approximate memory needed for both Pl^m and dPl^m/dx tables.
SHTnsKit.estimate_table_memory — Method
estimate_table_memory(cfg::SHTConfig) -> IntEstimate memory usage for Legendre tables based on configuration.
SHTnsKit.fft_plan_cache_enabled — Function
fft_plan_cache_enabled() -> BoolReturn whether distributed FFT plan caching is currently enabled.
SHTnsKit.get_batch_size — Method
get_batch_size(cfg::SHTConfig) -> IntReturn the current batch size configuration.
SHTnsKit.get_device — Method
Return the preferred compute device without silently relabelling requests.
SHTnsKit.get_nlat_padded — Method
get_nlat_padded(cfg::SHTConfig) -> IntGet the padded latitude dimension. Returns cfg.nlat if padding is disabled, or cfg.nlat_padded if padding is enabled.
This is the stride between successive phi (longitude) values in padded spatial arrays.
SHTnsKit.get_spat_dist — Method
get_spat_dist(cfg::SHTConfig) -> IntGet the distance between spatial arrays in batch mode. Returns cfg.nspat if padding is disabled, or the padded spatial distance if enabled.
SHTnsKit.gpu_analysis_sphtor — Method
gpu_analysis_sphtor(cfg, Vt, Vp; device=GPU(), prototype=nothing)Compatibility wrapper for the historical host-returning GPU vector API. Ordinary analysis_sphtor(GPU(), ...) remains device-resident; this legacy entry point deliberately copies its two results back to CPU storage.
SHTnsKit.gpu_clear_cache! — Method
Clear scalar-table caches for the selected GPU vendor.
SHTnsKit.gpu_synthesis_sphtor — Method
gpu_synthesis_sphtor(cfg, S, T; device=GPU(), real_output=true,
prototype=nothing)Compatibility wrapper for the historical host-returning GPU vector API.
SHTnsKit.grad_energy_scalar_alm — Method
grad_energy_scalar_alm(cfg, alm; real_field=true) -> MatrixCompute gradient of scalar field energy with respect to spectral coefficients. Returns ∂E/∂a_lm for use in optimization problems.
SHTnsKit.grad_energy_scalar_packed — Method
grad_energy_scalar_packed(cfg, Qlm; real_field=true) -> VectorCompute energy gradient for packed coefficients format.
SHTnsKit.grad_energy_vector_Slm_Tlm — Method
grad_energy_vector_Slm_Tlm(cfg, Slm, Tlm; real_field=true) -> (grad_S, grad_T)Compute gradients of vector field kinetic energy with respect to S and T coefficients.
SHTnsKit.grad_energy_vector_packed — Method
grad_energy_vector_packed(cfg, Spacked, Tpacked; real_field=true) -> (grad_S, grad_T)Compute energy gradients for packed vector coefficients.
SHTnsKit.grad_enstrophy_Tlm — Method
grad_enstrophy_Tlm(cfg, Tlm; real_field=true) -> MatrixCompute gradient of enstrophy with respect to toroidal coefficients. Returns ∂Z/∂Tlm = l²(l+1)² Tlm for optimization applications.
SHTnsKit.grad_grid_energy_scalar_field — Method
grad_grid_energy_scalar_field(cfg, f) -> MatrixCompute gradient of grid-based scalar energy with respect to spatial field values.
SHTnsKit.grad_grid_energy_vector_fields — Method
grad_grid_energy_vector_fields(cfg, Vt, Vp) -> (grad_Vt, grad_Vp)Compute gradients of grid-based vector energy with respect to vector components.
SHTnsKit.grad_grid_enstrophy_zeta — Method
grad_grid_enstrophy_zeta(cfg, ζ) -> MatrixCompute gradient of grid-based enstrophy with respect to vorticity field values. Returns ∂Z/∂ζ for each grid point.
SHTnsKit.grad_loss_vorticity_Tlm — Method
grad_loss_vorticity_Tlm(cfg, Tlm, ζ_target) -> MatrixCompute gradient of vorticity loss with respect to toroidal coefficients. Uses adjoint method for efficient computation.
SHTnsKit.grid_energy_scalar — Method
grid_energy_scalar(cfg, f) -> Float64Compute energy of a scalar field directly from its spatial representation. Uses Gauss-Legendre quadrature for accurate integration.
SHTnsKit.grid_energy_vector — Method
grid_energy_vector(cfg, Vt, Vp) -> Float64Compute kinetic energy of a vector field from its θ and φ components.
SHTnsKit.grid_enstrophy — Method
grid_enstrophy(cfg, ζ) -> Float64Compute enstrophy directly from gridded vorticity field using quadrature. Z = (1/2) ∫ ζ² dΩ using Gauss-Legendre integration.
SHTnsKit.im_from_lm — Method
im_from_lm(lm::Int, lmax::Int, mres::Int) -> IntInverse operation: determine the reduced m-index (im = m/mres) from a packed index. This function searches through the m-blocks to find which block contains the given packed index.
Useful for algorithms that need to determine the azimuthal symmetry of a coefficient from its packed storage location.
SHTnsKit.inside — Method
inside(a; buff=1)Return CartesianIndices range excluding buff layers of cells on all boundaries. Useful for iterating over interior points while respecting boundary conditions.
SHTnsKit.is_on_the_fly — Method
is_on_the_fly(cfg::SHTConfig) -> BoolCheck if configuration is set to on-the-fly Legendre computation mode.
SHTnsKit.is_padding_enabled — Method
is_padding_enabled(cfg::SHTConfig) -> BoolCheck if memory padding is enabled for the configuration.
SHTnsKit.is_south_pole_first — Method
is_south_pole_first(cfg::SHTConfig) -> BoolCheck if the configuration uses south-pole-first latitude ordering.
Returns true if latitude data starts at the south pole (θ=π), false if it starts at the north pole (θ=0, the default).
SHTnsKit.latitude_range — Method
latitude_range(nlat)Return a range for iterating over latitude bands.
SHTnsKit.local_range — Method
local_range(arr)Return CartesianIndices for iterating over the local portion of an array. For PencilArrays, this iterates over parent(arr) dimensions. For regular arrays, this is equivalent to CartesianIndices(arr).
Example
# With PencilArray (MPI-distributed)
@sht_loop local_data[I] = value over I ∈ local_range(pencil_arr)
# With regular array
@sht_loop field[I] = value over I ∈ local_range(regular_arr)SHTnsKit.local_size — Method
local_size(arr)Return the size of the local portion of an array. For PencilArrays, returns size(parent(arr)). For regular arrays, returns size(arr).
SHTnsKit.loop_backend — Method
loop_backend()Return the current loop backend mode: "auto" or "SIMD".
SHTnsKit.loss_and_grad_vorticity_Tlm — Method
loss_and_grad_vorticity_Tlm(cfg, Tlm, ζ_target) -> (loss, grad)Combined computation of loss and gradient for vorticity optimization. More efficient than separate computations due to shared forward pass.
SHTnsKit.loss_vorticity_grid — Method
loss_vorticity_grid(cfg, Tlm, ζ_target) -> Float64Compute loss function for vorticity matching problem. L = (1/2) ∫ [ζ(Tlm) - ζ_target]² dΩ where ζ(Tlm) is computed vorticity.
SHTnsKit.mode_range — Method
mode_range(mmax)Return a range for iterating over azimuthal modes (0 to mmax). Storage index: m+1 for m ∈ 0:mmax
SHTnsKit.nlm_calc — Method
nlm_calc(lmax::Integer, mmax::Integer, mres::Integer) -> IntCalculate the total number of packed spectral coefficients for a real scalar field. Real fields only need m ≥ 0 modes due to Hermitian symmetry: Yl^{-m} = (-1)^m (Yl^m)*
The packing scheme groups modes by m-order, then by l-degree within each m block. This layout is optimized for vectorized operations and cache efficiency.
SHTnsKit.nlm_cplx_calc — Method
nlm_cplx_calc(lmax::Integer, mmax::Integer, mres::Integer) -> IntCalculate the total number of spectral coefficients for a complex field. Complex fields require both positive and negative m modes, unlike real fields which use Hermitian symmetry to store only m ≥ 0 modes.
This is used for complex-valued spherical harmonic expansions where no symmetry assumptions can be made about the coefficients.
SHTnsKit.on_device — Method
Return CPU() for ordinary arrays; vendor extensions specialize this.
SHTnsKit.prepare_plm_tables! — Method
prepare_plm_tables!(cfg::SHTConfig)Precompute associated Legendre tables Pl^m(xi) for all i and m, stored as cfg.plm_tables[m+1][l+1, i]. Enables faster scalar transforms on regular grids.
SHTnsKit.reset_batch_size! — Method
reset_batch_size!(cfg::SHTConfig)Reset batch size to 1 (single field processing).
SHTnsKit.scratch_fft — Function
scratch_fft(cfg::SHTConfig, T::Type=ComplexF64) -> Matrix{T}Allocate a complex buffer sized for φ-FFTs (nlat, nlon). Reuse this across analysis!/synthesis! calls via the fft_scratch keyword to avoid per-call allocations.
SHTnsKit.scratch_spatial — Function
scratch_spatial(cfg::SHTConfig, T::Type=Float64) -> Matrix{T}Allocate a spatial grid buffer of size (nlat, nlon).
SHTnsKit.set_allow_padding! — Method
set_allow_padding!(cfg::SHTConfig; auto_compute::Bool=true)Enable memory padding for cache optimization. When enabled, spatial arrays can have extra padding between latitude lines to avoid cache bank conflicts.
This can improve performance by 1-50% depending on the problem size and hardware, especially for multi-threaded and GPU transforms.
Arguments
cfg: SHTConfig to modifyauto_compute: If true, automatically compute optimal padding. If false, you must setcfg.nlat_paddedmanually.
Example
cfg = create_gauss_config(64, 66)
set_allow_padding!(cfg)
println("Padded nlat: $(cfg.nlat_padded)") # May be > 66See also: disable_padding!, is_padding_enabled, get_nlat_padded
SHTnsKit.set_batch_size! — Method
set_batch_size!(cfg::SHTConfig, howmany::Int; spec_dist::Int=0)Configure batch processing for multiple fields. After calling this function, batch transform functions (analysis_batch, synthesis_batch, etc.) will process howmany fields simultaneously.
Arguments
cfg: SHTConfig to modifyhowmany: Number of fields to process in each batch (≥1)spec_dist: Distance between spectral coefficient arrays in memory. If 0, arrays are assumed contiguous. Otherwise, this is the stride between the start of successive spectral arrays.
Returns
- The configured batch size (always ≥1)
Example
cfg = create_gauss_config(32, 34)
set_batch_size!(cfg, 4) # Process 4 fields at once
# Now use batch transforms
fields = rand(cfg.nlat, cfg.nlon, 4)
alms = analysis_batch(cfg, fields)SHTnsKit.set_device! — Method
Select CPU() or GPU() as the preferred compute device.
SHTnsKit.set_fft_plan_cache! — Function
set_fft_plan_cache!(flag::Bool; clear::Bool=true)Enable or disable caching of distributed FFT plans. When disabling and clear=true, cached plans are freed.
SHTnsKit.set_loop_backend — Method
set_loop_backend(backend::String)Set the loop backend preference. Valid values:
- "auto": Automatically detect from array type (default) - uses GPU when arrays are on GPU
- "SIMD": Force CPU SIMD path (useful for debugging or when GPU is not desired)
SHTnsKit.set_north_pole_first! — Method
set_north_pole_first!(cfg::SHTConfig)Enable north-pole-first latitude ordering (the default). In this mode, latitude data starts at the north pole (θ=0).
This reverses the internal grid arrays if the configuration was previously in south-pole-first mode, and recalculates any precomputed Legendre tables.
Example
cfg = create_gauss_config(32, 34)
set_south_pole_first!(cfg) # Data starts at south pole
set_north_pole_first!(cfg) # Back to default (north pole first)See also: set_south_pole_first!, is_south_pole_first
SHTnsKit.set_on_the_fly! — Method
set_on_the_fly!(cfg::SHTConfig)Enable on-the-fly Legendre polynomial computation mode. This disables precomputed tables and computes P_l^m(x) during each transform.
Benefits:
- Lower memory usage (no table storage)
- Better for large lmax values
- Can be faster on modern CPUs due to cache effects
See also: set_use_tables!, create_gauss_fly_config
SHTnsKit.set_south_pole_first! — Method
set_south_pole_first!(cfg::SHTConfig)Enable south-pole-first latitude ordering. In this mode, latitude data starts at the south pole (θ=π) instead of the default north pole (θ=0).
This reverses the internal grid arrays (θ, x, w, st) and recalculates any precomputed Legendre tables if necessary.
Example
cfg = create_gauss_config(32, 34)
set_south_pole_first!(cfg) # Data now starts at south poleSee also: set_north_pole_first!, is_south_pole_first
SHTnsKit.set_use_tables! — Method
set_use_tables!(cfg::SHTConfig)Enable precomputed Legendre polynomial tables. This precomputes Pl^m(xi) for all grid points and stores them for reuse.
Benefits:
- Faster for repeated transforms with same grid
- No redundant computation of Legendre polynomials
Trade-offs:
- Higher memory usage: O(lmax × mmax × nlat)
- Initial table computation overhead
See also: set_on_the_fly!, prepare_plm_tables!
SHTnsKit.shtns37_capabilities — Method
shtns37_capabilities() -> Vector{SHTns37Capability}Return a copy of the executable SHTns 3.7 mathematical capability matrix. CPU and MPI/CPU cells remain :required until an immutable CI artifact is recorded for their named runner. A successful local parity gate is readiness evidence, not certification. Accelerator cells remain :unverified_hardware until their named runner has passed on physical hardware and its immutable CI artifact has been recorded.
SHTnsKit.shtns_rotation_apply_real — Method
shtns_rotation_apply_real(r::SHTRotation, Qlm::AbstractVector{<:Complex}, Rlm::AbstractVector{<:Complex})Apply rotation to real-field SH coefficients in packed LM layout (m ≥ 0). Requires mres==1.
SHTnsKit.shtns_rotation_create — Method
shtns_rotation_create(lmax::Integer, mmax::Integer, norm::Integer) -> SHTRotationSHTnsKit.shtns_rotation_destroy — Method
shtnsrotationdestroy(r::SHTRotation)
SHTnsKit.shtns_rotation_set_angle_axis — Method
shtns_rotation_set_angle_axis(r::SHTRotation, theta::Real, Vx::Real, Vy::Real, Vz::Real)Define rotation from angle-axis (theta around vector V). Angles are set in ZYZ convention.
SHTnsKit.shtns_rotation_set_angles_ZXZ — Method
shtnsrotationsetanglesZXZ(r, alpha, beta, gamma)
SHTnsKit.shtns_rotation_set_angles_ZYZ — Method
shtnsrotationsetanglesZYZ(r, alpha, beta, gamma)
SHTnsKit.shtns_rotation_wigner_d_matrix — Method
shtns_rotation_wigner_d_matrix(r::SHTRotation, l::Integer, mx::AbstractVector{<:Real}) -> IntFill mx (length ≥ (2l+1)^2) with d^l in row-major order. Returns size 2l+1.
SHTnsKit.spatial_range — Method
spatial_range(nlat, nlon)Return a CartesianIndices range for iterating over spatial grid points.
SHTnsKit.spectral_range — Method
spectral_range(lmax, mmax)Return a CartesianIndices range for iterating over valid (l,m) coefficient pairs. Note: Returns range for 1-based indexing of storage array, so iterate as: for idx ∈ spectral_range(lmax, mmax) l, m = idx[1] - 1, idx[2] - 1 # Convert to 0-based degree/order # ... work with alm[l+1, m+1] end
SHTnsKit.spheroidal_from_divergence — Method
spheroidal_from_divergence(cfg, δlm) -> MatrixInvert δlm = −l(l+1) Slm for l ≥ 1 to recover spheroidal coefficients.
SHTnsKit.st_dt_matrix — Method
st_dt_matrix(cfg::SHTConfig, mx::AbstractVector{<:Real})Fill mx with coupling coefficients for sinθ ∂θ operator: sinθ ∂θ Yl^m = l bl^m Y{l+1}^m - (l+1) al^m Y_{l-1}^m.
SHTnsKit.suggest_pencil_grid — Function
suggest_pencil_grid(comm_or_nprocs, nlat, nlon; prefer_square=true, allow_one_dim=true)Return a suggested MPI pencil decomposition (p_theta, p_phi) for a grid of size nlat x nlon. The base package provides a (1,1) fallback so the function is always defined; when SHTnsKitParallelExt is loaded the callback is replaced with an MPI-aware heuristic that favours balanced 2D decompositions.
SHTnsKit.synthesis! — Method
synthesis!(cfg::SHTConfig, f_out::AbstractMatrix, alm::AbstractMatrix; real_output::Bool=true)In-place inverse transform. Writes the spatial field into f_out.
SHTnsKit.synthesis! — Method
synthesis!(plan::SHTPlan, f_out::AbstractMatrix, alm::AbstractMatrix; real_output=true)In-place inverse scalar SHT writing spatial field into f_out. Streams m→k directly without building a (θ×m) intermediate.
SHTnsKit.synthesis — Method
synthesis(cfg::SHTConfig, alm::AbstractMatrix; real_output::Bool=true) -> MatrixInverse transform back to a grid (nlat, nlon). If real_output=true, Hermitian symmetry is enforced before IFFT.
SHTnsKit.synthesis_axisym — Method
synthesis_axisym(cfg, Qlm) -> Vector{Float64}Axisymmetric synthesis from degree-only coefficients to Gauss latitudes. Input Qlm should contain coefficients Q_l for l = 0..lmax. Returns spatial values at Gauss latitudes.
SHTnsKit.synthesis_axisym_l — Method
synthesis_axisym_l(cfg, Qlm, ltr) -> Vector{Float64}Axisymmetric degree-limited synthesis using degrees up to ltr.
SHTnsKit.synthesis_batch! — Method
synthesis_batch!(cfg::SHTConfig, f_out::AbstractArray,
alm_batch::AbstractArray{<:Complex,3}; real_output::Bool=true)In-place batch inverse transform.
SHTnsKit.synthesis_batch — Method
synthesis_batch(cfg::SHTConfig, alm_batch::AbstractArray{<:Complex,3};
real_output::Bool=true) -> ArrayBatch inverse transform for multiple spectral coefficient sets.
Arguments
cfg: SHTConfig with batch size configuredalm_batch: 3D array of shape(lmax+1, mmax+1, nfields)with spectral coefficientsreal_output: If true, return real spatial fields; otherwise complex
Returns
- 3D array of shape
(nlat, nlon, nfields)with spatial data
SHTnsKit.synthesis_batch_cplx — Method
synthesis_batch_cplx(cfg::SHTConfig, alm_batch::AbstractArray{<:Complex,3}) -> Array{ComplexF64,3}Complex-output batch inverse transform. Equivalent to synthesis_batch(cfg, alm_batch; real_output=false) with a concrete return type for inference-sensitive callers.
SHTnsKit.synthesis_cplx — Method
synthesis_cplx(cfg::SHTConfig, alm::AbstractMatrix) -> Matrix{<:Complex}Complex-output inverse scalar transform. This is equivalent to synthesis(cfg, alm; real_output=false) but dispatches through a compile-time output mode so callers can rely on a concrete return type.
SHTnsKit.synthesis_grad — Method
synthesis_grad(cfg::SHTConfig, Slm::AbstractMatrix; real_output::Bool=true)Gradient synthesis alias for compatibility with SHTns.
SHTnsKit.synthesis_grad_l — Method
synthesis_grad_l(cfg::SHTConfig, Slm::AbstractMatrix, ltr::Int; real_output::Bool=true)Degree-limited gradient synthesis alias.
SHTnsKit.synthesis_grad_ml — Method
synthesis_grad_ml(cfg::SHTConfig, im::Int, Sl::AbstractVector{<:Complex}, ltr::Int)Mode-limited gradient synthesis alias.
SHTnsKit.synthesis_packed — Method
synthesis_packed(cfg, Qlm::AbstractVector{<:Complex}) -> Vector{Float64}Packed scalar synthesis from Qlm (LM order) to flattened real grid (length nlat*nlon).
SHTnsKit.synthesis_packed_cplx_l — Method
synthesis_packed_cplx_l(cfg, alm_packed, ltr)Synthesize a complex spatial field from the LM_cplx coefficients with degrees l > ltr ignored. The input retains the full packed storage shape.
SHTnsKit.synthesis_packed_l — Method
synthesis_packed_l(cfg::SHTConfig, Qlm::AbstractVector{<:Complex}, ltr::Integer) -> Vector{Float64}Scalar synthesis truncated to degrees l ≤ ltr. Contributions from higher degrees are ignored.
SHTnsKit.synthesis_packed_ml — Method
synthesis_packed_ml(cfg, im, Ql, ltr) -> Vector{<:Complex}Transform spherical harmonic coefficients for specific mode m to spatial field. im is the zero-based stored-order index (m = im * cfg.mres); Ql contains coefficients for degrees l = m..ltr. Returns complex spatial values for that azimuthal mode.
SHTnsKit.synthesis_point_cplx — Method
synthesis_point_cplx(cfg::SHTConfig, alm::AbstractVector{<:Complex}, cost::Real, phi::Real) -> ComplexEvaluate a complex field represented by packed alm at a single point.
SHTnsKit.synthesis_qst — Method
synthesis_qst(cfg, Qlm, Slm, Tlm; real_output=true, use_rfft=false) -> (Vr, Vt, Vp)Transform QST spectral coefficients to 3D spatial vector field components. Returns radial (Vr), colatitude (Vt), and azimuthal (Vp) components.
SHTnsKit.synthesis_qst_batch — Method
synthesis_qst_batch(cfg::SHTConfig, Qlm_batch::AbstractArray{<:Complex,3},
Slm_batch::AbstractArray{<:Complex,3}, Tlm_batch::AbstractArray{<:Complex,3};
real_output::Bool=true)Batch QST synthesis for multiple 3D vector fields.
Returns
(Vr_batch, Vt_batch, Vp_batch): Tuple of 3D arrays with spatial components
SHTnsKit.synthesis_qst_batch_cplx — Method
Complex-output batch QST synthesis with a concrete return type.
SHTnsKit.synthesis_qst_cplx — Method
synthesis_qst_cplx(cfg, Qlm, Slm, Tlm) -> (Vr, Vt, Vp)Complex version of QST to spatial transform, preserving complex values.
SHTnsKit.synthesis_qst_l — Method
synthesis_qst_l(cfg, Qlm, Slm, Tlm, ltr; real_output=true) -> (Vr, Vt, Vp)Degree-limited version of synthesis_qst, using coefficients only up to degree ltr.
SHTnsKit.synthesis_qst_ml — Method
synthesis_qst_ml(cfg, im, Ql, Sl, Tl, ltr) -> (Vr_m, Vt_m, Vp_m)Mode-limited synthesis for specific azimuthal mode im.
SHTnsKit.synthesis_sph — Method
synthesis_sph(cfg, Slm; real_output=true) -> (Vt, Vp)Transform only spheroidal component to spatial vector field (Tlm = 0).
SHTnsKit.synthesis_sph_cplx — Method
synthesis_sph_cplx(cfg, Slm) -> (Vt, Vp)Complex-output spheroidal-only synthesis without allocating a dense zero toroidal spectrum.
SHTnsKit.synthesis_sph_l — Method
synthesis_sph_l(cfg, Slm, ltr; real_output=true) -> (Vt, Vp)Degree-limited spheroidal-only transform.
SHTnsKit.synthesis_sph_ml — Method
synthesis_sph_ml(cfg::SHTConfig, im::Int, Sl::AbstractVector{<:Complex}, ltr::Int)Mode-limited spheroidal-only synthesis wrapper.
SHTnsKit.synthesis_sphtor! — Method
synthesis_sphtor!(plan::SHTPlan, Vt_out::AbstractMatrix, Vp_out::AbstractMatrix, Slm::AbstractMatrix, Tlm::AbstractMatrix; real_output=true)In-place vector synthesis. Streams m→k without forming (θ×m) intermediates; inverse FFT Vt then Vp.
SHTnsKit.synthesis_sphtor — Method
synthesis_sphtor(cfg, Slm, Tlm; real_output=true) -> (Vt, Vp)Transform spheroidal/toroidal coefficients to horizontal vector field components. Returns colatitude (Vt) and azimuthal (Vp) components on the spatial grid.
SHTnsKit.synthesis_sphtor_batch — Method
synthesis_sphtor_batch(cfg::SHTConfig, Slm_batch::AbstractArray{<:Complex,3},
Tlm_batch::AbstractArray{<:Complex,3}; real_output::Bool=true)Batch spheroidal-toroidal synthesis for multiple vector fields.
Returns
(Vt_batch, Vp_batch): Tuple of 3D arrays(nlat, nlon, nfields)containing theta and phi components
SHTnsKit.synthesis_sphtor_batch_cplx — Method
Complex-output batch spheroidal/toroidal synthesis with a concrete return type.
SHTnsKit.synthesis_sphtor_cplx — Method
synthesis_sphtor_cplx(cfg, Slm, Tlm) -> (Vt, Vp)Complex version preserving complex values in output.
SHTnsKit.synthesis_sphtor_ml — Method
synthesis_sphtor_ml(cfg, mval, Sl, Tl, ltr) -> (Vt_m, Vp_m)Mode-limited synthesis for a single azimuthal order mval: Vθ = ∂S/∂θ - (i·mval/sinθ) * T Vφ = (i·mval/sinθ) * S + ∂T/∂θ
The order argument is named mval, NOT im: a binding called im shadows Julia's imaginary unit, and 1.0im is juxtaposition (1.0 * im), so the coupling terms above silently became real. Do not rename it back.
SHTnsKit.synthesis_tor — Method
synthesis_tor(cfg, Tlm; real_output=true) -> (Vt, Vp)Transform only toroidal component to spatial vector field (Slm = 0).
SHTnsKit.synthesis_tor_cplx — Method
synthesis_tor_cplx(cfg, Tlm) -> (Vt, Vp)Complex-output toroidal-only synthesis without allocating a dense zero spheroidal spectrum.
SHTnsKit.synthesis_tor_l — Method
synthesis_tor_l(cfg, Tlm, ltr; real_output=true) -> (Vt, Vp)Degree-limited toroidal-only transform.
SHTnsKit.synthesis_tor_ml — Method
synthesis_tor_ml(cfg::SHTConfig, im::Int, Tl::AbstractVector{<:Complex}, ltr::Int)Mode-limited toroidal-only synthesis wrapper.
SHTnsKit.toroidal_from_vorticity — Method
toroidal_from_vorticity(cfg, ζlm) -> MatrixRecover toroidal stream function coefficients from vorticity spectra.
SHTnsKit.vorticity_from_toroidal — Method
vorticity_from_toroidal(cfg, Tlm) -> MatrixReturn vorticity spectral coefficients ζlm = −l(l+1) Tlm.
SHTnsKit.vorticity_grid — Method
vorticity_grid(cfg, Tlm) -> MatrixTransform toroidal coefficients to vorticity on the spatial grid. This combines spectral vorticity calculation with spherical harmonic synthesis.
SHTnsKit.vorticity_spectral — Method
vorticity_spectral(cfg, Tlm) -> Matrix{ComplexF64}Compute vorticity coefficients ζlm from toroidal stream function coefficients Tlm. Relationship: ζlm = -l(l+1) Tlm
SHTnsKit.δ — Method
δ(i, N::Int)
δ(i, I::CartesianIndex{N})Return a CartesianIndex of dimension N which is one at index i and zero elsewhere. Useful for offsetting indices in a specific direction.
Example
δ(1, CartesianIndex(2,3)) # Returns CartesianIndex(1,0)SHTnsKit.@sht_inside — Macro
@sht_inside <arr[I] = expr>Convenience macro to loop over interior points of an array, excluding boundaries. Automatically determines the loop range from the array size.
Example
@sht_inside field[I] = 0.5 * (field_old[I+δ(1,I)] + field_old[I-δ(1,I)])SHTnsKit.@sht_loop — Macro
@sht_loop <expr> over <I ∈ R>Macro to automate fast loops using @simd when running on CPU, or KernelAbstractions when running on GPU (requires GPU extension).
The macro extracts all symbols from the expression, creates kernel functions for both CPU and GPU paths, and dispatches based on the array backend at runtime.
Examples
# Loop over 2D Cartesian range
@sht_loop dest[i, j] = src[i, j] * scale over (i, j) ∈ CartesianIndices((n, m))
# Loop with accumulation pattern
@sht_loop alm[l+1, m+1] += weights[i] * Plm[i, l+1, m+1] * Fm[i, m+1] over i ∈ 1:nlatNotes
- Detects CPU vs GPU from the first array in the expression
- GPU path requires GPU extension (CUDA.jl + KernelAbstractions)
- CPU path uses @simd @fastmath @inbounds for vectorization
- Set
SHTnsKit.set_loop_backend("SIMD")to force CPU path
Field accesses in the body (e.g. cfg.scale) are supported: the expression is evaluated once at the call site and passed in under a hygienic name, so it can never pick up an unrelated caller local that happens to share the field name.
Configuration lifecycle
SHTConfig is managed by Julia's garbage collector. destroy_config(cfg) is a no-op retained for API symmetry; callers do not need a try/finally teardown pattern.