Skip to content

Commit 3a33806

Browse files
Merge pull request #78 from matthewtownson/master
Update imports, fixing #67
2 parents 21a7d87 + d789da5 commit 3a33806

File tree

5 files changed

+273
-299
lines changed

5 files changed

+273
-299
lines changed

aotools/functions/zernike.py

+6-12
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
import numpy
22
from . import circle
33

4-
# xrange just "range" in python3.
5-
# This code means fastest implementation used in 2 and 3
6-
try:
7-
xrange
8-
except NameError:
9-
xrange = range
104

115
def phaseFromZernikes(zCoeffs, size, norm="noll"):
126
"""
@@ -22,7 +16,7 @@ def phaseFromZernikes(zCoeffs, size, norm="noll"):
2216
"""
2317
Zs = zernikeArray(len(zCoeffs), size, norm=norm)
2418
phase = numpy.zeros((size, size))
25-
for z in xrange(len(zCoeffs)):
19+
for z in range(len(zCoeffs)):
2620
phase += Zs[z] * zCoeffs[z]
2721

2822
return phase
@@ -90,7 +84,7 @@ def zernikeRadialFunc(n, m, r):
9084

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

9589
R += numpy.array(r**(n - 2 * i) * (((-1)**(i)) *
9690
numpy.math.factorial(n - i)) /
@@ -143,7 +137,7 @@ def zernikeArray(J, N, norm="noll"):
143137
try:
144138
nJ = len(J)
145139
Zs = numpy.empty((nJ, N, N))
146-
for i in xrange(nJ):
140+
for i in range(nJ):
147141
Zs[i] = zernike_noll(J[i], N)
148142

149143
# Else, cast to int and create up to that number
@@ -154,16 +148,16 @@ def zernikeArray(J, N, norm="noll"):
154148

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

157-
for j in xrange(1, maxJ+1):
151+
for j in range(1, maxJ+1):
158152
Zs[j-1] = zernike_noll(j, N)
159153

160154

161155
if norm=="p2v":
162-
for z in xrange(len(Zs)):
156+
for z in range(len(Zs)):
163157
Zs[z] /= (Zs[z].max()-Zs[z].min())
164158

165159
elif norm=="rms":
166-
for z in xrange(len(Zs)):
160+
for z in range(len(Zs)):
167161
# Norm by RMS. Remember only to include circle elements in mean
168162
Zs[z] /= numpy.sqrt(
169163
numpy.sum(Zs[z]**2)/numpy.sum(circle(N/2., N)))

aotools/turbulence/infinitephasescreen.py

+1-10
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,9 @@
55
An implementation of the "infinite phase screen", as deduced by Francois Assemat and Richard W. Wilson, 2006.
66
"""
77

8-
from scipy.special import gamma, kv
98
from scipy import linalg
10-
from scipy.interpolate import interp2d
119
import numpy
12-
from numpy import pi
13-
14-
# Numba compiles python code to machine code for faster execution
15-
try:
16-
import numba
17-
except:
18-
numba = None
19-
10+
import numba
2011

2112
from . import phasescreen, turb
2213

aotools/turbulence/phasescreen.py

+3-8
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@
1111
import time
1212
import random
1313

14-
# Fastest range in both python2 and python3
15-
try:
16-
xrange
17-
except NameError:
18-
xrange = range
1914

2015
def ft_sh_phase_screen(r0, N, delta, L0, l0, FFT=None, seed=None):
2116

@@ -57,7 +52,7 @@ def ft_sh_phase_screen(r0, N, delta, L0, l0, FFT=None, seed=None):
5752
phs_lo = numpy.zeros(phs_hi.shape)
5853

5954
# loop over frequency grids with spacing 1/(3^p*L)
60-
for p in xrange(1,4):
55+
for p in range(1,4):
6156
# setup the PSD
6257
del_f = 1 / (3**p*D) #frequency grid spacing [1/m]
6358
fx = numpy.arange(-1,2) * del_f
@@ -81,8 +76,8 @@ def ft_sh_phase_screen(r0, N, delta, L0, l0, FFT=None, seed=None):
8176
* numpy.sqrt(PSD_phi)*del_f )
8277
SH = numpy.zeros((N,N),dtype="complex")
8378
# loop over frequencies on this grid
84-
for i in xrange(0, 3):
85-
for j in xrange(0, 3):
79+
for i in range(0, 3):
80+
for j in range(0, 3):
8681

8782
SH += cn[i,j] * numpy.exp(1j*2*numpy.pi*(fx[i,j]*x+fy[i,j]*y))
8883

aotools/wfs/wfslib.py

-6
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,6 @@
44

55
import numpy
66

7-
# Best range for python2 and 3
8-
try:
9-
range = xrange
10-
except:
11-
pass
12-
137

148
def findActiveSubaps(subaps, mask, threshold, returnFill=False):
159
"""

0 commit comments

Comments
 (0)