Skip to content

Commit

Permalink
Merge pull request #29 from matthewtownson/master
Browse files Browse the repository at this point in the history
Tests and bug fixing
  • Loading branch information
Andrew Reeves authored Jul 5, 2017
2 parents c0f0d3d + 11a543b commit 004539c
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 69 deletions.
25 changes: 13 additions & 12 deletions aotools/functions/_functions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import numpy
from . import pupil


def gaussian2d(size, width, amplitude=1., cent=None):
Expand All @@ -7,31 +8,31 @@ def gaussian2d(size, width, amplitude=1., cent=None):
Args:
size (tuple, float): Dimensions of Array to place gaussian
size (tuple, float): Dimensions of Array to place gaussian (y, x)
width (tuple, float): Width of distribution.
Accepts tuple for x and y values.
Accepts tuple for x and y values in order (y, x).
amplitude (float): Amplitude of guassian distribution
cent (tuple): Centre of distribution on grid.
cent (tuple): Centre of distribution on grid in order (y, x).
'''

try:
xSize = size[0]
ySize = size[1]
ySize = size[0]
xSize = size[1]
except (TypeError, IndexError):
xSize = ySize = size

try:
xWidth = float(width[0])
yWidth = float(width[1])
yWidth = float(width[0])
xWidth = float(width[1])
except (TypeError, IndexError):
xWidth = yWidth = float(width)

if not cent:
xCent = size[0] / 2.
yCent = size[1] / 2.
xCent = xSize/2.
yCent = ySize/2.
else:
xCent = cent[0]
yCent = cent[1]
yCent = cent[0]
xCent = cent[1]

X, Y = numpy.meshgrid(range(0, xSize), range(0, ySize))

Expand All @@ -55,7 +56,7 @@ def aziAvg(data):
size = data.shape[0]
avg = numpy.empty(size / 2, dtype="float")
for i in range(size / 2):
ring = circle(i + 1, size) - circle(i, size)
ring = pupil.circle(i + 1, size) - pupil.circle(i, size)
avg[i] = (ring * data).sum() / (ring.sum())

return avg
6 changes: 3 additions & 3 deletions aotools/image_processing/_image_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def r0fromSlopes(slopes, wavelength, subapDiam):

r0 = ((0.162 * (wavelength ** 2) * subapDiam ** (-1. / 3)) / slopeVar) ** (3. / 5)

r0 = r0.mean()
r0 = float(r0.mean())

return r0

Expand Down Expand Up @@ -50,7 +50,7 @@ def image_contrast(image):

contrast = (image.max() - image.min()) / (image.max() + image.min())

return contrast
return float(contrast)


def rms_contrast(image):
Expand All @@ -66,4 +66,4 @@ def rms_contrast(image):

image /= image.max()

return image.std()
return float(image.std())
50 changes: 0 additions & 50 deletions aotools/turbulence/slopecovariance.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,53 +481,3 @@ def create_tomographic_covariance_reconstructor(covariance_matrix, n_onaxis_suba
tomo_recon = cov_onoff.dot(icov_offoff)

return tomo_recon

if __name__ == "__main__":

N = 1
threads = 20

n_wfs = 6
telescope_diameter = 4.2
nx_subaps = 10

n_layers = 3
layer_altitudes = numpy.linspace(0, 20000, 35)
layer_r0s = [1] * n_layers
layer_L0s = [25.] * n_layers

asterism_radius = 60

subap_diameters = [telescope_diameter / nx_subaps] * n_wfs
pupil_masks = [circle(nx_subaps/2., nx_subaps)] * n_wfs
gs_altitudes = [90000] * n_wfs
gs_positions = [
[asterism_radius, 0],
[numpy.sin(numpy.pi/3.) * asterism_radius, numpy.cos(numpy.pi/3.) * asterism_radius],
[numpy.sin(numpy.pi/3.) * asterism_radius, -numpy.cos(numpy.pi/3.) * asterism_radius],
[-numpy.sin(numpy.pi/3.) * asterism_radius, numpy.cos(numpy.pi/3.) * asterism_radius],
[-numpy.sin(numpy.pi/3.) * asterism_radius, -numpy.cos(numpy.pi/3.) * asterism_radius],
[-asterism_radius, 0]]
wfs_magnifications = [1.] * n_wfs
pupil_offsets = [[0, 0]] * n_wfs
wfs_rotations = [0] * n_wfs
wfs_wavelengths = [550e-9] * n_wfs

t1 = time.time()
for i in range(N):
print("\nIteration {}".format(i))
cov_mat = CovarianceMatrix(n_wfs, pupil_masks, telescope_diameter, subap_diameters, gs_altitudes, gs_positions, wfs_wavelengths,
n_layers, layer_altitudes, layer_r0s, layer_L0s, wfs_magnifications, pupil_offsets, wfs_rotations, threads)
cov_mat.make_covariance_matrix()

t2 = time.time()

time_taken = (t2 - t1)/N
covmat_per_sec = 1./time_taken
print("Time for 1 Covariance Matrix: {}s".format(time_taken))
print("Covariance Matrics per second: {} cps".format(covmat_per_sec))


# from matplotlib import pyplot
# pyplot.imshow(cov_mat.covariance_matrix)
# pyplot.show()
13 changes: 13 additions & 0 deletions test/test_functions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from aotools import functions
import numpy


def test_gaussian2d():
gaussian = functions.gaussian2d(10, 3, 10.)
assert gaussian.shape == (10, 10)


def test_gaussian2d_2d():
gaussian = functions.gaussian2d((10, 8), (3, 2), 10., (4, 3))
print(gaussian.shape)
assert gaussian.shape == (10, 8)
30 changes: 30 additions & 0 deletions test/test_image_processing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from aotools import image_processing
import numpy


def test_r0fromSlopes():
slopes = numpy.random.random((2, 100, 2))
wavelength = 500e-9
subapDiam = 0.5
r0 = image_processing.r0fromSlopes(slopes, wavelength, subapDiam)
print(type(r0))


def test_slopeVarfromR0():
r0 = 0.1
wavelength = 500e-9
subapDiam = 0.5
variance = image_processing.slopeVarfromR0(r0, wavelength, subapDiam)
assert type(variance) == float


def test_image_contrast():
image = numpy.random.random((20, 20))
contrast = image_processing.image_contrast(image)
assert type(contrast) == float


def test_rms_contrast():
image = numpy.random.random((20, 20))
contrast = image_processing.rms_contrast(image)
assert type(contrast) == float
8 changes: 4 additions & 4 deletions test/test_slopecovariance.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def test_slopecovmat_makecovmat_multithreaded():

if __name__ == "__main__":
N = 1
threads = 2
threads = 20

n_wfs = 6
telescope_diameter = 8.
Expand Down Expand Up @@ -198,6 +198,6 @@ def test_slopecovmat_makecovmat_multithreaded():
print("Time for 1 Covariance Matrix: {}s".format(time_taken))
print("Covariance Matrics per second: {} cps".format(covmat_per_sec))

from matplotlib import pyplot
pyplot.imshow(cov_mat.covariance_matrix)
pyplot.show()
# from matplotlib import pyplot
# pyplot.imshow(cov_mat.covariance_matrix)
# pyplot.show()

0 comments on commit 004539c

Please sign in to comment.