Skip to content

Commit

Permalink
fix area calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
rhayes777 committed Nov 11, 2024
1 parent 4ed1a13 commit 9704153
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
4 changes: 2 additions & 2 deletions autoarray/structures/triangles/abstract_coordinate_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def means(self):

@property
def area(self):
return (3**0.5 / 4 * self.side_length**2) * len(self.coordinates)
return (3**0.5 / 4 * self.side_length**2) * len(self)

def __len__(self):
return len(self.coordinates)
return np.count_nonzero(~np.isnan(self.coordinates).any(axis=1))
16 changes: 15 additions & 1 deletion test_autoarray/structures/triangles/test_coordinate_jax.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from autoarray.numpy_wrapper import jit
import pytest

from autoarray.structures.triangles.abstract import HEIGHT_FACTOR
from autoarray.structures.triangles.shape import Point

try:
Expand Down Expand Up @@ -110,4 +111,17 @@ def test_means(one_triangle):

up_sampled = one_triangle.up_sample()
neighborhood = up_sampled.neighborhood()
assert np.count_nonzero(~np.isnan(neighborhood.means)) == 20
assert np.count_nonzero(~np.isnan(neighborhood.means).any(axis=1)) == 10


ONE_TRIANGLE_AREA = HEIGHT_FACTOR * 0.5


def test_area(one_triangle):
assert one_triangle.area == ONE_TRIANGLE_AREA
assert one_triangle.up_sample().area == ONE_TRIANGLE_AREA

neighborhood = one_triangle.neighborhood()
assert neighborhood.area == 4 * ONE_TRIANGLE_AREA
assert neighborhood.up_sample().area == 4 * ONE_TRIANGLE_AREA
assert neighborhood.neighborhood().area == 10 * ONE_TRIANGLE_AREA

0 comments on commit 9704153

Please sign in to comment.