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 4th order derivative transforms #586

Merged
merged 22 commits into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
8922d94
Increase max matrix size of transform
unalmis Jul 17, 2023
3399eaf
Add fourth order zernike radial
unalmis Jul 18, 2023
cdefd9f
Merge branch 'master' into higher_order_deriv
unalmis Jul 18, 2023
8f3ca37
Lower bound transform matrix order to 1
unalmis Jul 18, 2023
e5eee12
Update transform class for deriv order
unalmis Jul 18, 2023
abfda65
Add back dropped line of code
unalmis Jul 18, 2023
3ff4ebf
Add back dummy _set_up method
unalmis Jul 19, 2023
15f816a
Document use of _set_up function and fix test to raise ValueError
unalmis Jul 19, 2023
d78e4a5
Remove _set_up method now that io save stuff was...
unalmis Jul 19, 2023
0882ba4
Merge branch 'master' into higher_order_deriv
f0uriest Jul 20, 2023
07bed02
Merge branch 'master' into higher_order_deriv
f0uriest Jul 20, 2023
e6a84a0
Tests for Zernike polynomial radial derivative
unalmis Jul 20, 2023
7574d8a
Merge branch 'master' into higher_order_deriv
unalmis Jul 20, 2023
b8c877f
Ignore division by zero warnings in compute funs
unalmis Jul 21, 2023
60a5bb0
Fix test_zernike_radial
unalmis Jul 25, 2023
8683ba2
git checkout add_all_limits desc/compute/_core.py
unalmis Jul 25, 2023
1a63fb9
Merge branch 'master' into higher_order_deriv
unalmis Jul 25, 2023
73fab8f
Sort _core using script
unalmis Jul 25, 2023
73e4c57
Merge branch 'master' into higher_order_deriv
unalmis Jul 27, 2023
b021ef2
Merge branch 'master' into higher_order_deriv
f0uriest Jul 28, 2023
9e18d49
Merge branch 'master' into higher_order_deriv
f0uriest Jul 28, 2023
d76d9dd
Merge branch 'master' into higher_order_deriv
f0uriest Jul 29, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 36 additions & 22 deletions desc/basis.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@

def _set_up(self):
"""Do things after loading or changing resolution."""
# Also recreates any attributes not in _io_attrs on load from input file.
# See IOAble class docstring for more info.
self._enforce_symmetry()
self._sort_modes()
self._create_idx()
Expand Down Expand Up @@ -614,7 +616,7 @@
For L>0, the indexing scheme defines order of the basis functions:

``'ansi'``: ANSI indexing fills in the pyramid with triangles of
decreasing size, ending in a triagle shape. For L == M,
decreasing size, ending in a triangle shape. For L == M,
the traditional ANSI pyramid indexing is recovered. For L>M, adds rows
to the bottom of the pyramid, increasing L while keeping M constant,
giving a "house" shape.
Expand Down Expand Up @@ -657,7 +659,7 @@
For L>0, the indexing scheme defines order of the basis functions:

``'ansi'``: ANSI indexing fills in the pyramid with triangles of
decreasing size, ending in a triagle shape. For L == M,
decreasing size, ending in a triangle shape. For L == M,
the traditional ANSI pyramid indexing is recovered. For L>M, adds rows
to the bottom of the pyramid, increasing L while keeping M constant,
giving a "house" shape.
Expand Down Expand Up @@ -971,7 +973,7 @@
For L>0, the indexing scheme defines order of the basis functions:

``'ansi'``: ANSI indexing fills in the pyramid with triangles of
decreasing size, ending in a triagle shape. For L == M,
decreasing size, ending in a triangle shape. For L == M,
the traditional ANSI pyramid indexing is recovered. For L>M, adds rows
to the bottom of the pyramid, increasing L while keeping M constant,
giving a "house" shape.
Expand Down Expand Up @@ -1016,7 +1018,7 @@
For L>0, the indexing scheme defines order of the basis functions:

``'ansi'``: ANSI indexing fills in the pyramid with triangles of
decreasing size, ending in a triagle shape. For L == M,
decreasing size, ending in a triangle shape. For L == M,
the traditional ANSI pyramid indexing is recovered. For L>M, adds rows
to the bottom of the pyramid, increasing L while keeping M constant,
giving a "house" shape.
Expand Down Expand Up @@ -1395,37 +1397,49 @@
beta = 0
n = (l - m) // 2
s = (-1) ** n
jacobi_arg = 1 - 2 * r**2
if dr == 0:
out = r**m * _jacobi(n, alpha, beta, 1 - 2 * r**2, 0)
out = r**m * _jacobi(n, alpha, beta, jacobi_arg, 0)
elif dr == 1:
f = _jacobi(n, alpha, beta, 1 - 2 * r**2, 0)
df = _jacobi(n, alpha, beta, 1 - 2 * r**2, 1)
f = _jacobi(n, alpha, beta, jacobi_arg, 0)
df = _jacobi(n, alpha, beta, jacobi_arg, 1)
out = m * r ** jnp.maximum(m - 1, 0) * f - 4 * r ** (m + 1) * df
elif dr == 2:
f = _jacobi(n, alpha, beta, 1 - 2 * r**2, 0)
df = _jacobi(n, alpha, beta, 1 - 2 * r**2, 1)
d2f = _jacobi(n, alpha, beta, 1 - 2 * r**2, 2)
f = _jacobi(n, alpha, beta, jacobi_arg, 0)
df = _jacobi(n, alpha, beta, jacobi_arg, 1)
d2f = _jacobi(n, alpha, beta, jacobi_arg, 2)
out = (
m * (m - 1) * r ** jnp.maximum((m - 2), 0) * f
- 2 * 4 * m * r**m * df
+ r**m * (16 * r**2 * d2f - 4 * df)
(m - 1) * m * r ** jnp.maximum(m - 2, 0) * f
- 4 * (2 * m + 1) * r**m * df
+ 16 * r ** (m + 2) * d2f
)
elif dr == 3:
f = _jacobi(n, alpha, beta, 1 - 2 * r**2, 0)
df = _jacobi(n, alpha, beta, 1 - 2 * r**2, 1)
d2f = _jacobi(n, alpha, beta, 1 - 2 * r**2, 2)
d3f = _jacobi(n, alpha, beta, 1 - 2 * r**2, 3)
f = _jacobi(n, alpha, beta, jacobi_arg, 0)
df = _jacobi(n, alpha, beta, jacobi_arg, 1)
d2f = _jacobi(n, alpha, beta, jacobi_arg, 2)
d3f = _jacobi(n, alpha, beta, jacobi_arg, 3)
out = (
(m - 2) * (m - 1) * m * r ** jnp.maximum(m - 3, 0) * f
- 12 * (m - 1) * m * r ** jnp.maximum(m - 1, 0) * df
+ 48 * r ** (m + 1) * d2f
- 12 * m**2 * r ** jnp.maximum(m - 1, 0) * df
+ 48 * (m + 1) * r ** (m + 1) * d2f
dpanici marked this conversation as resolved.
Show resolved Hide resolved
- 64 * r ** (m + 3) * d3f
+ 48 * m * r ** (m + 1) * d2f
- 12 * m * r ** jnp.maximum(m - 1, 0) * df
)
elif dr == 4:
f = _jacobi(n, alpha, beta, jacobi_arg, 0)
df = _jacobi(n, alpha, beta, jacobi_arg, 1)
d2f = _jacobi(n, alpha, beta, jacobi_arg, 2)
d3f = _jacobi(n, alpha, beta, jacobi_arg, 3)
d4f = _jacobi(n, alpha, beta, jacobi_arg, 4)
out = (

Check warning on line 1433 in desc/basis.py

View check run for this annotation

Codecov / codecov/patch

desc/basis.py#L1427-L1433

Added lines #L1427 - L1433 were not covered by tests
(m - 3) * (m - 2) * (m - 1) * m * r ** jnp.maximum(m - 4, 0) * f
- 8 * m * (2 * m**2 - 3 * m + 1) * r ** jnp.maximum(m - 2, 0) * df
+ 48 * (2 * m**2 + 2 * m + 1) * r**m * d2f
- 128 * (2 * m + 3) * r ** (m + 2) * d3f
+ 256 * r ** (m + 4) * d4f
)
else:
raise NotImplementedError(
"Analytic radial derivatives of Zernike polynomials for order>3 "
"Analytic radial derivatives of Zernike polynomials for order>4 "
+ "have not been implemented."
)
return s * jnp.where((l - m) % 2 == 0, out, 0)
Expand Down
Loading