diff --git a/aotools/functions/_functions.py b/aotools/functions/_functions.py index e00a2b5..76f2486 100644 --- a/aotools/functions/_functions.py +++ b/aotools/functions/_functions.py @@ -1,4 +1,5 @@ import numpy +from . import pupil def gaussian2d(size, width, amplitude=1., cent=None): @@ -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)) @@ -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 diff --git a/aotools/image_processing/_image_processing.py b/aotools/image_processing/_image_processing.py index 9ddea7c..e81cfab 100644 --- a/aotools/image_processing/_image_processing.py +++ b/aotools/image_processing/_image_processing.py @@ -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 @@ -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): @@ -66,4 +66,4 @@ def rms_contrast(image): image /= image.max() - return image.std() + return float(image.std()) diff --git a/aotools/turbulence/slopecovariance.py b/aotools/turbulence/slopecovariance.py index 2d9cfd1..251f6d9 100644 --- a/aotools/turbulence/slopecovariance.py +++ b/aotools/turbulence/slopecovariance.py @@ -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() diff --git a/test/test_functions.py b/test/test_functions.py new file mode 100644 index 0000000..388c817 --- /dev/null +++ b/test/test_functions.py @@ -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) diff --git a/test/test_image_processing.py b/test/test_image_processing.py new file mode 100644 index 0000000..6ae7757 --- /dev/null +++ b/test/test_image_processing.py @@ -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 \ No newline at end of file diff --git a/test/test_slopecovariance.py b/test/test_slopecovariance.py index 145c873..daff7b4 100644 --- a/test/test_slopecovariance.py +++ b/test/test_slopecovariance.py @@ -155,7 +155,7 @@ def test_slopecovmat_makecovmat_multithreaded(): if __name__ == "__main__": N = 1 - threads = 2 + threads = 20 n_wfs = 6 telescope_diameter = 8. @@ -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() \ No newline at end of file + # from matplotlib import pyplot + # pyplot.imshow(cov_mat.covariance_matrix) + # pyplot.show() \ No newline at end of file