Skip to content

Commit

Permalink
Updated tests to new function names
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Townson committed Oct 25, 2019
1 parent 918bd50 commit 4cded35
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 52 deletions.
8 changes: 4 additions & 4 deletions aotools/image_processing/centroiders.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def correlation_centroid(im, ref, threshold=0., padding=1):
# Correlate frame with reference image
corr = cross_correlate(im[frame], ref, padding=padding)

cx, cy = centreOfGravity(corr, threshold=threshold)
cx, cy = centre_of_gravity(corr, threshold=threshold)

cy -= float(ny) / 2. * (float(padding) - 1)
cx -= float(nx) / 2. * (float(padding) - 1)
Expand All @@ -51,7 +51,7 @@ def correlation_centroid(im, ref, threshold=0., padding=1):
return centroids


def centre_of_gravity(img, threshold=0, **kwargs):
def centre_of_gravity(img, threshold=0, min_threshold=0, **kwargs):
"""
Centroids an image, or an array of images.
Centroids over the last 2 dimensions.
Expand All @@ -69,10 +69,10 @@ def centre_of_gravity(img, threshold=0, **kwargs):

if threshold != 0:
if len(img.shape) == 2:
thres = numpy.max((threshold*img.max(), minThreshold))
thres = numpy.max((threshold*img.max(), min_threshold))
img = numpy.where(img > thres, img - thres, 0)
else:
thres = numpy.maximum(threshold*img.max(-1).max(-1), [minThreshold]*img.shape[0])
thres = numpy.maximum(threshold*img.max(-1).max(-1), [min_threshold]*img.shape[0])
img_temp = (img.T - thres).T
zero_coords = numpy.where(img_temp < 0)
img[zero_coords] = 0
Expand Down
18 changes: 9 additions & 9 deletions test/test_centroiders.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,33 @@
from nose.tools import raises


def test_centreOfGravity_single():
def test_centre_of_gravity_single():
img = numpy.random.random((10, 10))
com = image_processing.centreOfGravity(img, 0.1)
com = image_processing.centre_of_gravity(img, 0.1)
assert(com.shape[0]) == 2


def test_centreOfGravity_many():
def test_centre_of_gravity_many():
img = numpy.random.random((5, 10, 10))
com = image_processing.centreOfGravity(img, 0.1)
com = image_processing.centre_of_gravity(img, 0.1)
assert(com.shape[0] == 2)
assert(com.shape[1] == 5)

def test_centreOfGravity_value():
def test_centre_of_gravity_value():
img = numpy.zeros((1, 5, 5))
img[0, 1:3, 2:4] = 1.
centroid = image_processing.centreOfGravity(img)
centroid = image_processing.centre_of_gravity(img)
numpy.testing.assert_almost_equal(centroid, numpy.array([[2.5], [1.5]]))

def test_brightestPxl_single():
def test_brightest_pixel_single():
img = numpy.random.random((10, 10))
com = image_processing.brightestPxl(img, 0.3)
com = image_processing.brightest_pixel(img, 0.3)
assert(com.shape[0] == 2)


def test_brightestPxl_many():
img = numpy.random.random((5, 10, 10))
com = image_processing.brightestPxl(img, 0.1)
com = image_processing.brightest_pixel(img, 0.1)
assert(com.shape[0] == 2)
assert(com.shape[1] == 5)

Expand Down
23 changes: 0 additions & 23 deletions test/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,3 @@ def test_gaussian2d_2d():
gaussian = functions.gaussian2d((10, 8), (3, 2), 10., (4, 3))
print(gaussian.shape)
assert gaussian.shape == (10, 8)


def test_encircledEnergy():
data = numpy.random.rand(32, 32)
ee50d = functions.encircledEnergy(data)
print(ee50d)
assert type(ee50d) == float


def test_encircledEnergy_func():
data = numpy.random.rand(32, 32)
x, y = functions.encircledEnergy(data, eeDiameter=False)
print(y.min(), y.max())
assert len(x) == len(y)
assert numpy.max(y) <= 1
assert numpy.min(y) >= 0


def test_aziAvg():
data = numpy.random.rand(32, 32)
azi = functions.aziAvg(data)
print(azi.shape)
assert azi.shape == (16,)
39 changes: 23 additions & 16 deletions test/test_image_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,6 @@
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)
Expand Down Expand Up @@ -51,3 +35,26 @@ def test_azimuthal_average():
azi = image_processing.azimuthal_average(data)
print(azi.shape)
assert azi.shape == (16,)


def test_encircledEnergy():
data = numpy.random.rand(32, 32)
ee50d = image_processing.encircled_energy(data)
print(ee50d)
assert type(ee50d) == float


def test_encircledEnergy_func():
data = numpy.random.rand(32, 32)
x, y = image_processing.encircled_energy(data, eeDiameter=False)
print(y.min(), y.max())
assert len(x) == len(y)
assert numpy.max(y) <= 1
assert numpy.min(y) >= 0


def test_aziAvg():
data = numpy.random.rand(32, 32)
azi = image_processing.azimuthal_average(data)
print(azi.shape)
assert azi.shape == (16,)
18 changes: 18 additions & 0 deletions test/test_turbulence.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from aotools import turbulence
import numpy


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


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

0 comments on commit 4cded35

Please sign in to comment.