Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add associated Legendre function calculations #505

Merged
merged 17 commits into from
Jun 12, 2024
Merged

Add associated Legendre function calculations #505

merged 17 commits into from
Jun 12, 2024

Conversation

leouieda
Copy link
Member

@leouieda leouieda commented May 10, 2024

The numba-based functions calculate the associated Legendre functions (unnormalized, Schmidt normalized, and fully normalized) and their derivatives $\dfrac{\partial P_n^m}{\partial \theta}(\cos\theta)$. The derivatives functions can be used to calculate higher order derivatives as well. Values are tested against analytical solutions for the first 4 degrees as well as an identity for the Schmidt functions and the Legendre equation for the Schmidt and fully normalized functions. The values are returned as 2D numpy arrays. This is a bit of a waste of memory but it's much easier to use than storing these in sparse matrices or 1D arrays. But it should be acceptable since we're unlikely to ever go over ~2700 degree so the waste is in the order of a few Mb at worse.

Relevant issues/PRs:

Related to #504

Allocate the output array out of the loop. This way we can do it once
only when evaluating the spherical harmonics. Pre-compute the square
roots of integers that we use in the loops. Doesn't work well if the
square roots are calculated at the module level (probably a numba
thing).
@leouieda leouieda mentioned this pull request May 14, 2024
@leouieda leouieda marked this pull request as ready for review May 23, 2024 22:43
@leouieda
Copy link
Member Author

leouieda commented May 23, 2024

@santisoler and @MarkWieczorek this is ready now. I added the Holmes and Featherstone scaling and tested until degree 2800. I was surprised that calculating the derivatives on rescaled functions works well. That's nice because it means we can keep them separate and use the derivative functions to calculate higher order derivatives (which would appear in gravity gradients).

If you could both have a quick look I'd really appreciate it. And thanks for all the information and code examples @MarkWieczorek! It really helped.

Copy link
Member

@santisoler santisoler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work @leouieda! I think it will be great to have the spherical harmonics in Harmonica (redundancy required 😁), and this is step forward that.

I left some minor comments here. Let me know what do you think.

harmonica/tests/test_legendre.py Outdated Show resolved Hide resolved
harmonica/tests/test_legendre.py Outdated Show resolved Hide resolved
harmonica/tests/test_legendre.py Show resolved Hide resolved
harmonica/tests/test_legendre.py Outdated Show resolved Hide resolved
harmonica/tests/test_legendre.py Outdated Show resolved Hide resolved
harmonica/tests/test_legendre.py Show resolved Hide resolved
Co-authored-by: Santiago Soler <[email protected]>
@leouieda leouieda requested a review from santisoler June 10, 2024 13:41
@leouieda
Copy link
Member Author

Thanks, @santisoler! What do you think?

@santisoler
Copy link
Member

Looking great @leouieda! I'm updating the branch so we can merge it.

@leouieda leouieda merged commit 855a36e into main Jun 12, 2024
19 checks passed
@leouieda leouieda deleted the legendre branch June 12, 2024 12:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants