Add support for Clenshaw-Curtis and Fejér second rule quadrature / sampling schemes - #381
matt-graham wants to merge 47 commits into
Conversation
…larities in numpy forward transform
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #381 +/- ##
==========================================
+ Coverage 96.10% 96.39% +0.29%
==========================================
Files 34 34
Lines 3539 3603 +64
==========================================
+ Hits 3401 3473 +72
+ Misses 138 130 -8 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
| elif sampling == "cc": | ||
| return 2 * n_theta - 2 | ||
| elif sampling == "f2": | ||
| return 2 * n_theta + 2 |
There was a problem hiding this comment.
@jasonmcewen I arrived at these by trial and error as I could not see the pattern in how the values for the other schemes was derived - if there some underlying relationship here it would be good to document. It might also be worth moving this to one of modules under s2fft.sampling
|
Copying discussion from Slack here so we have a record going forwards: The Hotte and Ujiie (2018) paper suggests we require The Generating a set of random coefficients then running Looking at the implementation of So if we want to support |
|
@jasonmcewen from my perspective this is now ready to merge. I have addressed the points discussed when I did the code walkthrough / review with you and Kevin, most significantly checking the quadrature rule tests for exact integration of polynomial functions tests the rules at the relevant minimum number of points, and also clarified the logic behind |
I can confirm that this is exactly how it is done. The beautiful aspect about this is that, after upsampling and applying the weights, you can downsample again and still carry out the Legendre transform part on the low number of rings. |
|
@claude review |
There was a problem hiding this comment.
If your organization's extra usage balance is empty, an organization admin can add extra usage credits at claude.ai/admin-settings/usage. If its monthly spend limit was reached, an admin can raise it on the same page. If neither applies, contact Anthropic support.
Once extra usage is available, comment @claude review on this pull request to trigger a review.
|
Just stumbled upon this. My downstream package For common atmospheric science data, it is common to use I am using the As a side note, the current s2fft |
Should resolve #251 and also does some work towards #340
Adds implementations of the Clenshaw-Curtis and Fejér's (second) quadrature rules and corresponding sampling schemes.
The quadrature weights are computed using the FFT based approach described in
Following the definitions in that paper the Clenshaw-Curtis scheme includes samples at both poles ($\theta = \pm \pi$ ) while the Fejér's second rule scheme excludes both poles. The Clenshaw-Curtis scheme is selected with
sampling="cc"and Fejér's second rule withsampling="f2"arguments to relevant functions.To facilitate adding these new schemes, this PR also does some light refactoring of the existing quadrature and sample related modules to try to make the code more DRY and with a more standardized interfaced across the different schemes. In some cases the rationale for special casing code paths on different sampling schemes was a bit unclear, particularly around handling of pole singularities and setting
m_offset, so I've done a best efforts attempt at trying to rationalise this but this probably could do with some careful checking.Currently for a bandlimit$L$ both schemes have $N_\theta = 2L - 1$ and $N_\phi = 2L$ . The former appears to be required to be $\sim 2L$ to give round-trip errors close to machine precision; I believe this related to the comment
in the paper Hotte and Ujiie (2018) A nestable, multigrid-friendly grid on a sphere for global spectral models based on Clenshaw–Curtis quadrature with their definition of$N$ corresponding to $L - 1$ and $J$ to $N_\theta$ in our notation and hence we require $N_\theta \geq 2 L - 1$ .
Choosing$N_\theta = 2L - 1$ gives an odd number of nodes in the latitude axis and so includes the equator as a node, this matching the co-latitude points used in Hotte and Ujiie (2018). This still leaves $N_\phi$ undetermined - here I have chosen $N_\phi = 2L$ which is sufficient to avoid aliasing in FFT operations (which requires $N_\phi > 2L - 2$ ), and matches the MW scheme, but gives $N_\theta \approx N_\phi$ while it seems quite common in grids used in practice in climate applications to have $N_\phi \approx 2N_\theta$ which might suggest using $N_\phi = 4L$ .
@jasonmcewen I'm tagging you as you mentioned you would be interested in looking through the details of this.
TODO: