Skip to content

Commit

Permalink
Merge pull request #54 from andrewpaulreeves/master
Browse files Browse the repository at this point in the history
Fix Gaussian 2d bug when numpy array given as centre point coordinates
  • Loading branch information
Matthew Townson committed Apr 15, 2020
2 parents 3b6ae03 + 32ceb84 commit 025e059
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
9 changes: 5 additions & 4 deletions aotools/functions/_functions.py
Expand Up @@ -10,8 +10,8 @@ def gaussian2d(size, width, amplitude=1., cent=None):
size (tuple, float): Dimensions of Array to place gaussian (y, x)
width (tuple, float): Width of distribution.
Accepts tuple for x and y values in order (y, x).
amplitude (float): Amplitude of guassian distribution
cent (tuple): Centre of distribution on grid in order (y, x).
amplitude (float, optional): Amplitude of guassian distribution. default is 1.
cent (tuple, optional): Centre of distribution on grid in order (y, x). Default is middle
'''

try:
Expand All @@ -25,8 +25,9 @@ def gaussian2d(size, width, amplitude=1., cent=None):
xWidth = float(width[1])
except (TypeError, IndexError):
xWidth = yWidth = float(width)

if not cent:

# If a centre point not given, centre is centre of array
if cent is None:
xCent = xSize/2.
yCent = ySize/2.
else:
Expand Down
6 changes: 5 additions & 1 deletion test/test_functions.py
Expand Up @@ -7,7 +7,11 @@ def test_gaussian2d():
assert gaussian.shape == (10, 10)


def test_gaussian2d_array_centre_point():
gaussian = functions.gaussian2d((10, 8), (3, 2), 10., numpy.asarray((4, 3)))
assert gaussian.shape == (10, 8)


def test_gaussian2d_2d():
gaussian = functions.gaussian2d((10, 8), (3, 2), 10., (4, 3))
print(gaussian.shape)
assert gaussian.shape == (10, 8)

0 comments on commit 025e059

Please sign in to comment.