Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ProcessArea): add area #384

Merged
merged 3 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions aviary/_utils/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,14 @@ def coordinates(

self._coordinates = value

@property
def area(self) -> int:
"""
Returns:
area in square meters
"""
return len(self) * self._tile_size ** 2

@classmethod
def from_bounding_box(
cls,
Expand Down
12 changes: 12 additions & 0 deletions docs/how_to_guides/api/how_to_use_the_process_area.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,18 @@ We can visualize the process area.

---

You can access the area of the process area with the `area` attribute.

``` python
print(process_area.area)
```

``` title="Output"
8192
```

---

A process area is an iterable object, so it supports indexing, length and iteration.

You can access the coordinates of the process area with the index operator.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,20 @@
],
"id": "623715cb0e58a824"
},
{
"metadata": {},
"cell_type": "markdown",
"source": "You can access the area of the process area with the `area` attribute.",
"id": "f5097de6607f33c1"
},
{
"metadata": {},
"cell_type": "code",
"outputs": [],
"execution_count": null,
"source": "print(process_area.area)",
"id": "704910cd8ebbd281"
},
{
"metadata": {},
"cell_type": "markdown",
Expand Down
29 changes: 28 additions & 1 deletion tests/_utils/data/data_test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import numpy as np

# noinspection PyProtectedMember
from aviary._utils.types import BoundingBox
from aviary._utils.types import (
BoundingBox,
ProcessArea,
)

data_test_bounding_box_buffer = [
# test case 1: buffer_size is 0
Expand Down Expand Up @@ -173,3 +176,27 @@
re.escape('Invalid tile size! tile_size must be positive.'),
),
]

data_test_process_area_area = [
# test case 1: process area has no tiles
(
ProcessArea(tile_size=128),
0,
),
# test case 2: process area has one tile
(
ProcessArea(
coordinates=np.array([[-128, -128]], dtype=np.int32),
tile_size=128,
),
16384,
),
# test case 3: process area has four tiles
(
ProcessArea(
coordinates=np.array([[-128, -128], [0, -128], [-128, 0], [0, 0]], dtype=np.int32),
tile_size=128,
),
65536,
),
]
9 changes: 9 additions & 0 deletions tests/_utils/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
data_test_bounding_box_properties_exceptions,
data_test_bounding_box_quantize,
data_test_bounding_box_quantize_exceptions,
data_test_process_area_area,
data_test_process_area_init_exceptions,
data_test_process_area_properties_exceptions,
)
Expand Down Expand Up @@ -342,6 +343,14 @@ def test_process_area_properties_exceptions(
setattr(process_area, property_, value)


@pytest.mark.parametrize(('process_area', 'expected'), data_test_process_area_area)
def test_process_area_area(
process_area: ProcessArea,
expected: int,
) -> None:
assert process_area.area == expected


def test_process_area_from_bounding_box() -> None:
x_min = -128
y_min = -128
Expand Down