Skip to content

Commit 33905ee

Browse files
author
Dani Bodor
committed
make matrix_layout a property
1 parent 4f78ebb commit 33905ee

2 files changed

Lines changed: 11 additions & 8 deletions

File tree

eitprocessing/roi_selection/gridselection.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ class GridSelection(ROISelection):
4141
4242
`split_columns` has the same effect on columns as `split_rows` has on rows.
4343
44-
Regions are ordered according to C indexing order. The `matrix_layout()` method provides a map
45-
showing how the regions are ordered.
44+
Regions are ordered according to C indexing order. The `matrix_layout` attribute provides a map
45+
showing how these regions are ordered.
4646
4747
Common grids are pre-defined:
4848
- VentralAndDorsal: vertically divided into ventral and dorsal;
@@ -66,7 +66,7 @@ class GridSelection(ROISelection):
6666
[16, 17, 18]])
6767
>>> gs = GridSelection(3, 1, split_rows=False)
6868
>>> rois = gs.find_grid(pixel_map)
69-
>>> gs.matrix_layout()
69+
>>> gs.matrix_layout
7070
array([[0],
7171
[1],
7272
[2]])
@@ -86,7 +86,7 @@ class GridSelection(ROISelection):
8686
[0, 0, 0]])
8787
>>> gs2 = GridSelection(2, 2, split_columns=True)
8888
>>> rois2 = gs.find_grid(pixel_map)
89-
>>> gs2.matrix_layout()
89+
>>> gs2.matrix_layout
9090
array([[0, 1],
9191
[2, 3]])
9292
>>> rois2[2]
@@ -316,11 +316,15 @@ def _create_grouping_vector_split_pixels( # pylint: disable=too-many-locals
316316

317317
return final
318318

319-
def matrix_layout(self) -> NDArray:
319+
@property
320+
def _matrix_layout(self) -> NDArray:
320321
"""Returns a 2D array showing the layout of the matrices returned by
321322
`find_grid`."""
322323
n_regions = self.v_split * self.h_split
323324
return np.reshape(np.arange(n_regions), (self.v_split, self.h_split))
325+
@_matrix_layout.getter # private attribute with getter avoids users overriding this property
326+
def matrix_layout(self):
327+
return self._matrix_layout
324328

325329

326330
class InvalidDivision(Exception):

tests/test_gridselection.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ def test_split_pixels_nans(data_string, split_vh, result):
465465
)
466466
def test_matrix_layout(split_vh: tuple[int, int], result: list[list[int]]):
467467
"""
468-
Test `matrix_layout()` method.
468+
Test `matrix_layout` method.
469469
470470
Args:
471471
split_vh (tuple[int, int]): `v_split` and `h_split`.
@@ -474,6 +474,5 @@ def test_matrix_layout(split_vh: tuple[int, int], result: list[list[int]]):
474474
"""
475475

476476
gs = GridSelection(*split_vh)
477-
layout = gs.matrix_layout()
478477

479-
assert np.array_equal(layout, np.array(result))
478+
assert np.array_equal(gs.matrix_layout, np.array(result))

0 commit comments

Comments
 (0)