Epic: Spherical harmonics rewrite (stable Legendre tables, spectral vector calculus, SHTns-style storage)

Open
#81 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
25/100
Issue type
Refactor
Clarity
Mostly clear
Activity status
Active
Tech stack
jupyter-notebook, python

Research direction

The work is in the spectraldiffx/_src/spherical/ module. Start by reading the child issues #96 through #101 to understand the specific defects. Examine the current Legendre table construction and transform code. Verify correctness with existing tests for quadrature, orthonormality, and transforms. The goal is a coherent rewrite that fixes critical bugs, enables JIT compilation, and adopts an efficient storage layout.

Written by the indexing model from the issue text.

Description

bug epic

Scope

The spherical-harmonics module (spectraldiffx/_src/spherical/) has two critical defects that make it unusable above T85 and wrong for any field with odd zonal wavenumber, plus a storage layout that is 8x larger than necessary and cannot be jitted in the GFD solvers. These are best fixed as one coherent piece of work because they all touch the same table-construction and transform code.

What is verified correct today and must be preserved: Gauss–Legendre quadrature and weights; discrete orthonormality of the basis (Gram off-diagonal 8e-17); forward/inverse round trip of band-limited fields (≤1.2e-11 up to T31, including odd Nx, odd Ny, Nx<2Ny); agreement with scipy.special.sph_harm_y up to a scale factor; Laplacian eigenvalues −l(l+1)/R² (rel. err 4e-11 at R=1, 2, 6.371e6); exact FFT longitude derivative; Poisson/Helmholtz eigenvalue inversion (2e-13); isotropic filters.

Child issues (in suggested order)

  • #96 fix(spherical): every transform returns NaN at T86 and above (lpmv overflow) — critical
  • #97 fix(spherical): θ-derivative wrong for odd m, O(1) non-converging error — critical
  • #98 fix(spherical): GFD solvers rebuild operators per call and cannot be jitted — high
  • #99 perf(spherical): SHTns-style Legendre storage (rfft, l≥m, parity, real tables) — high
  • #100 fix(spherical): conventions, radius, weights, dead dealias code, docstring sign errors — medium
  • #101 feat(spherical): operators needed by the sphere models (jacobian, velocity_from_streamfunction, spectra, …) — medium

Items 1–3 are bug fixes and can go first; 4 is the performance rewrite and is easiest once 1–2 have replaced lpmv; 5–6 are API work.

Blocks

  • #9 (SWE on a sphere), #11 (QG on a sphere), #13 (barotropic vorticity on a sphere) all need correct vector calculus on the sphere (#97) and the operators in #101.

Related

  • #80 (correctness), #82 (JAX-native), #83 (Fourier consolidation), #84 (gaussx integration), #85 (hygiene).
Dominant language
Python
Stars
2
Forks
0
Avg merge
8h 13m
Merged PRs (30d)
8

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from jejjohnson/spectraldiffx

All issues in jejjohnson/spectraldiffx

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.