fix(spherical): conventions and dead code — coefficient scale, negative-m rule, explicit `radius`, `weights` ignore R, `Lx ≠ 2π` inconsistency, unused `dealias`/`m`/`spectral` flags, docstring sign errors
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 45/100
- Issue type
- Documentation
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- jupyter-notebook, python
- Domain
- backend-api-design, documentation
Research direction
The issue lists many specific files: harmonics.py, grid.py, operators.py, filters.py, solvers.py, and docs/theory/spherical.md. Start by reading the theory documentation and the class docstrings to understand the spherical harmonic conventions. Then, examine the transform and coefficient scaling in harmonics.py and grid.py. Verify the numerical tests mentioned, and check for unused code with ruff. The goal is to correct documentation, fix sign errors, and remove dead code, ensuring all changes are backward compatible and tested.
Written by the indexing model from the issue text.
Description
Part of #81.
Everything here was verified numerically; none of it changes results for the default Lx = 2π, Ly = π grid, but all of it misleads users or blocks interop with other SH libraries.
Conventions (documented wrongly)
- Coefficient scale. The basis actually used is
P̃_l^{|m|}(cos θ) e^{imφ}withP̃orthonormal on[−1, 1]w.r.t.dμand an unnormalised FFT, so the stored coefficient of an orthonormal (scipysph_harm_y)Y_lmisNx / sqrt(2π)(measured 12.766 = 32/√(2π) for every(l, m)tested, leakage ≤ 2e-13).harmonics.py:16-19says "4π-normalised in the real convention";docs/theory/spherical.md §2says "fully normalised". Neither describes the stored numbers; a power spectrum or a comparison with pyshtools/SHTns is off byNx²/(2π). Document the exact scale, or normalise the transform so that coefficients are orthonormal-Y_lmcoefficients (preferred; then a power spectrum isΣ_m |c_lm|²). - Negative m.
c[l, −m] = conj(c[l, m])(measured), vs the standard(−1)^m conj(c[l, m]); the coefficient of scipy'sY_l^{−m}is(−1)^m Nx/√(2π). Only documented in a code comment (grid.py:490-496). Document in the class docstring and theory page. - Condon–Shortley phase is included (via
lpmv);harmonics.py:18-19("no Condon–Shortley phase … beyond what lpmv supplies") is confusing. State it plainly. - Alias-free range. The Ny-point Gauss–Legendre rule is exact for
P̃_l^m P̃_l'^m(degree ≤ 2Ny − 2), so the linear transform is alias-free forl ≤ Ny − 1,|m| ≤ Nx/2. Nothing enforcesNx ≥ 2Ny − 1; with smallerNxthe truncation is silently rectangular.docs/theory/spherical.md §5saysJ ≥ (3L+1)/2nodes are needed — that is the quadratic-product condition; the grid providesJ = L + 1anddealiasis never applied (below). Fix the doc; consider a warning whenNx < 2Ny − 1.
Radius handling
-
SphericalGrid2D.weights(grid.py:603-610) sums to2·Lx = 4πregardless of radius (12.566 measured withR = 2;4πR² = 50.27), whiletests/test_spherical_grid.py:175-186claims "area = 4πR²" and only testsR = 1. Either scale byR²or rename/document as unit-sphere weights; test atR ≠ 1. - Radius is
Ly / π(solvers.py:54-57,operators.py:328, 374, 420, 498,filters.py:548, 646). Replace with an explicitradiusattribute/constructor argument; keepLyfor back-compat with a deprecation. -
Lx ≠ 2πis inconsistent:grid.mand derivatives use2πk/Lx(operators.py:338) but_P_lmuses the integer FFT index as the ALP order (grid.py:487-500); measuredgrid.m[:4] = [0, 0.5, 1, 1.5]vs orders0..3forLx = 4π. FixLxto2π(raise otherwise) onceradiusexists.
Dead code / ignored arguments
-
dealias,l_dealias,dealias_filter(grid.py:191, 337-365, 456, 640-664) are never applied by any transform or operator (only tests touch them). Remove, or apply where products are formed. -
SphericalGrid2D.m(grid.py:618-621) unused. -
spectralargument ofdivergence/curl(operators.py:353, 396) accepted and ignored. -
_gradient_alp_matrix(operators.py:56-89) is a two-line wrapper;nodes_weights,laplacian_eigenvaluesunused internally. -
SphericalGrid1D.L,dx,check_consistency,from_L_dx(grid.py:221-273) are copy-pasted from the Fourier grid and meaningless for non-uniform Gauss–Legendre nodes. Rename the class toLegendreGrid1D/ZonalGrid1D(with alias) and drop the uniform-grid members.
Docstring sign/formula errors
- Curl sign in
operators.py:23and:280is the negative of what the code and:400implement. - Hyperviscosity docstring
∂u/∂t = (−1)^{p+1} ν ∇^p u(filters.py:522-524) is anti-diffusive forp = 2; should be(−1)^{p/2+1}. -
grid.py:24-28stability envelope (see the NaN issue);grid.py:420-426shows a ½ factor not present in the code;solvers.py:176-179zero_meanclaim (see #92);docs/api/spherical/solvers.mdomits the three GFD solvers.
Acceptance criteria
- Test comparing
transform(Y_lm)againstscipy.special.sph_harm_yfor a handful of(l, ±m)with the documented scale and sign. - Test
weights.sum() == 4πR²atR ∈ {1, 2, 6.371e6}(or the documented unit-sphere value). -
ruffreports no unused code after removal;mkdocs build --strictpasses.
- 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
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from jejjohnson/spectraldiffx
-
documentation
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
jejjohnson/spectraldiffx#172 ·
-
epic
Difficulty 1/5 Under an hour Newbie friendliness 62/100
jejjohnson/spectraldiffx#167 · 1 comment ·
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
jejjohnson/spectraldiffx#113 ·
-
documentation
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
jejjohnson/spectraldiffx#105 ·
-
dependencies
Difficulty 4/5 3-5 days Newbie friendliness 45/100
jejjohnson/spectraldiffx#181 ·
All issues in jejjohnson/spectraldiffx
Similar issues
-
bug(operator): VolterraOperator built inside jax.jit with a concrete decay raises TracerBoolConversionErrorPossibly taken @jejjohnson claimed this today. Opentype:bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
jejjohnson/integrix#144 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
finos/ai-governance-framework#459 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
autowarefoundation/autoware_carla_scenario#2963 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
freelawproject/litigant-portal#1307 ·
Maintainers usually reply within 2 days
-
type/bug
Difficulty 1/5 Under an hour Newbie friendliness 86/100
h2oai/h2o-llmstudio#1163 ·
Maintainers usually reply within 1 day