Skip to content

Commit

Permalink
Fixed the xrange/range screw up
Browse files Browse the repository at this point in the history
  • Loading branch information
spangly authored and Matthew Townson committed Jan 27, 2023
1 parent 610c921 commit 8669dec
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions aotools/functions/zernike.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
import numpy
from . import circle

# xrange just "range" in python3.
# This code means fastest implementation used in 2 and 3
try:
xrange
except NameError:
xrange = range

def phaseFromZernikes(zCoeffs, size, norm="noll", rot=0):
"""
Creates an array of the sum of zernike polynomials with specified coefficeints
Expand All @@ -22,7 +15,7 @@ def phaseFromZernikes(zCoeffs, size, norm="noll", rot=0):
"""
Zs = zernikeArray(len(zCoeffs), size, norm=norm, rot=rot)
phase = numpy.zeros((size, size))
for z in xrange(len(zCoeffs)):
for z in range(len(zCoeffs)):
phase += Zs[z] * zCoeffs[z]

return phase
Expand Down Expand Up @@ -92,7 +85,7 @@ def zernikeRadialFunc(n, m, r):

R = numpy.zeros(r.shape)
# Can cast the below to "int", n,m are always *both* either even or odd
for i in xrange(0, int((n - m) / 2) + 1):
for i in range(0, int((n - m) / 2) + 1):

R += numpy.array(r**(n - 2 * i) * (((-1)**(i)) *
numpy.math.factorial(n - i)) /
Expand Down Expand Up @@ -146,7 +139,7 @@ def zernikeArray(J, N, norm="noll", rot=0):
try:
nJ = len(J)
Zs = numpy.empty((nJ, N, N))
for i in xrange(nJ):
for i in range(nJ):
Zs[i] = zernike_noll(J[i], N, rot)

# Else, cast to int and create up to that number
Expand All @@ -157,16 +150,16 @@ def zernikeArray(J, N, norm="noll", rot=0):

Zs = numpy.empty((maxJ, N, N))

for j in xrange(1, maxJ+1):
for j in range(1, maxJ+1):
Zs[j-1] = zernike_noll(j, N, rot)


if norm=="p2v":
for z in xrange(len(Zs)):
for z in range(len(Zs)):
Zs[z] /= (Zs[z].max()-Zs[z].min())

elif norm=="rms":
for z in xrange(len(Zs)):
for z in range(len(Zs)):
# Norm by RMS. Remember only to include circle elements in mean
Zs[z] /= numpy.sqrt(
numpy.sum(Zs[z]**2)/numpy.sum(circle(N/2., N)))
Expand Down

0 comments on commit 8669dec

Please sign in to comment.