Skip to content

Commit

Permalink
refined tests for 2d/3d
Browse files Browse the repository at this point in the history
  • Loading branch information
haesleinhuepf committed Dec 2, 2022
1 parent b205e1c commit 803e129
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
8 changes: 5 additions & 3 deletions pyclesperanto_prototype/_tier3/_maximum_position.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,18 @@ def maximum_position(source: Image) -> tuple:
Examples
--------
>>> import pyclesperanto_prototype as cle
>>> cle.maximum_of_all_pixels(source)
>>> cle.maximum_position(source)
References
----------
"""
from .._tier1 import maximum_x_projection
from .._tier1 import maximum_y_projection
from .._tier1 import maximum_z_projection
from .._tier2 import x_position_of_maximum_x_projection
from .._tier2 import y_position_of_maximum_y_projection
from .._tier2 import z_position_of_maximum_z_projection

# Find maximum projections and positions along each axis, reducing the dimensionality of the array
# To have the same properties as ndi.maximum_position, find projections in the order X -> Y -> Z
Expand All @@ -50,8 +52,8 @@ def maximum_position(source: Image) -> tuple:
source = temp_max

if len(dimensionality) > 2:
# Use x position as input array is 2d
pos_z = x_position_of_maximum_x_projection(source)
# Use z position as input array is 3d
pos_z = z_position_of_maximum_z_projection(source)

# Use calculated max positions to find coordinates of each axis
if pos_z is not None:
Expand Down
18 changes: 16 additions & 2 deletions tests/test_maximum_position.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import pyclesperanto_prototype as cle
import numpy as np
from scipy import ndimage

def test_maximum_position():
def test_maximum_position_3d():
np_input= np.asarray([
[
[1, 2, 3, 10],
Expand All @@ -15,7 +16,20 @@ def test_maximum_position():
]
])

reference = (0, 1, 1)
reference = ndimage.maximum_position(np_input)
gpu_input = cle.push(np_input)
result = cle.maximum_position(gpu_input)

assert (result == reference)

def test_maximum_position_2d():
np_input= np.asarray([
[1, 2, 3, 10],
[4, 16, 6, 11],
[7, 8, 9, 12]
])

reference = ndimage.maximum_position(np_input)
gpu_input = cle.push(np_input)
result = cle.maximum_position(gpu_input)

Expand Down

0 comments on commit 803e129

Please sign in to comment.