Skip to content

Commit

Permalink
Merge pull request #33 from GillesOrban/master
Browse files Browse the repository at this point in the history
Zernike array coordinate definition
  • Loading branch information
matthewtownson committed Jan 11, 2018
2 parents 7d94ad9 + c7f4a4e commit c34c48f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
16 changes: 10 additions & 6 deletions aotools/functions/zernike.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ def zernike_nm(n, m, N):
Returns:
ndarray: The Zernike mode
"""
coords = numpy.linspace(-1, 1, N)
X,Y = numpy.meshgrid(coords, coords)
coords = (numpy.arange(N) - N / 2. + 0.5) / (N / 2.)
X, Y = numpy.meshgrid(coords, coords)
R = numpy.sqrt(X**2 + Y**2)
theta = numpy.arctan2(Y, X)

Expand Down Expand Up @@ -89,10 +89,14 @@ def zernikeRadialFunc(n, m, r):
"""

R = numpy.zeros(r.shape)
for i in xrange(0,int((n-m)/2)+1):

R += r**(n-2*i) * (((-1)**(i))*numpy.math.factorial(n-i)) / ( numpy.math.factorial(i) * numpy.math.factorial(0.5*(n+m)-i) * numpy.math.factorial(0.5*(n-m)-i) )

for i in xrange(0, int((n - m) / 2) + 1):

R += numpy.array(r**(n - 2 * i) * (((-1)**(i)) *
numpy.math.factorial(n - i)) /
(numpy.math.factorial(i) *
numpy.math.factorial(0.5 * (n + m) - i) *
numpy.math.factorial(0.5 * (n - m) - i)),
dtype='float')
return R


Expand Down
3 changes: 3 additions & 0 deletions test/test_zernike.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ def test_zenikeRadialFunc():
r = numpy.sqrt(x ** 2 + y ** 2)

radial_function = functions.zernikeRadialFunc(5, 3, r)
# test no casting error for high order modes
_ = functions.zernikeRadialFunc(21, 1, r)
_ = functions.zernikeRadialFunc(50, 16, r)
assert(radial_function.shape == (32, 32))


Expand Down

0 comments on commit c34c48f

Please sign in to comment.