Skip to content

Commit

Permalink
fix: drop stack_order and fix documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
drodarie committed Aug 1, 2024
1 parent 702104e commit d5c1160
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 42 deletions.
25 changes: 3 additions & 22 deletions bsb/topology/region.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,34 +85,16 @@ def scale(self, factors):
@config.node
class Stack(RegionGroup, classmap_entry="stack"):
"""
Stack components on top of each other based on their ``stack_order`` if it is defined
and adjust its own height accordingly.
Stack components on top of each other and adjust its own height accordingly.
"""

axis: typing.Union[typing.Literal["x"], typing.Literal["y"], typing.Literal["z"]] = (
config.attr(type=types.in_(["x", "y", "z"]), default="z")
)
stack_order: list[typing.Union["Region", "Partition"]] = config.reflist(
refs.regional_ref, backref="region"
)
anchor: typing.Union["Region", "Partition"] = config.ref(
refs.regional_ref, backref="region"
)

def _resolve_stack_order(self, layout):
corrected_order = []
children_owners = [child._owner for child in layout.children]
for child in self.stack_order:
if child in children_owners:
to_add = layout.children[children_owners.index(child)]
if to_add not in corrected_order:
corrected_order.append(to_add)

for child in layout.children:
if child not in corrected_order:
corrected_order.append(child)
return corrected_order

def _resolve_anchor_offset(self, children, axis_idx):
children_owners = [child._owner for child in children]
if self.anchor is not None and self.anchor in children_owners:
Expand All @@ -129,10 +111,9 @@ def get_layout(self, hint):
trans_eye = np.zeros(3)
trans_eye[axis_idx] = 1

children = self._resolve_stack_order(layout)
# origin of stack corresponds to the origin of the first child
cumul_offset = self._resolve_anchor_offset(children, axis_idx)
for child in children:
cumul_offset = self._resolve_anchor_offset(layout.children, axis_idx)
for child in layout.children:
if child.data is None:
warn(f"Skipped layout arrangement of {child._owner.name} in {self.name}")
continue
Expand Down
2 changes: 1 addition & 1 deletion docs/getting-started/getting-started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ Connectivity

.. literalinclude:: getting-started.json
:language: json
:lines: 56-66
:lines: 54-64

.. literalinclude:: getting_started.py
:language: python
Expand Down
4 changes: 2 additions & 2 deletions docs/getting-started/include_morphos.rst
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,11 @@ connection strategies such as :class:`~.connectivity.detailed.voxel_intersection

.. literalinclude:: include_morphos.yaml
:language: yaml
:lines: 56-64
:lines: 54-62

.. literalinclude:: include_morphos.json
:language: json
:lines: 74-84
:lines: 72-82

.. literalinclude:: include_morphos.py
:language: python
Expand Down
17 changes: 0 additions & 17 deletions tests/test_topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,23 +135,6 @@ def test_default_order(self):
network = Scaffold(Configuration.default(**self.cfg), self.storage)
self._test_dimensions_offset(np.array(network.regions["a"].children))

def test_stack_order(self):
self.cfg["regions"]["a"]["stack_order"] = [
"layer0",
"layer1",
"layer1",
"layer2",
"rhomboid1",
"rhomboid2",
]
expected_order = ["layer1", "layer2", "rhomboid1", "rhomboid2", "rhomboid3"]
expected_index = np.array([3, 1, 0, 2, 4])
network = Scaffold(Configuration.default(**self.cfg), self.storage)
for i, child in enumerate(
np.array(network.regions["a"].children)[expected_index]
):
self.assertEqual(child.name, expected_order[i])

def test_anchor(self):
self.cfg["regions"]["a"]["anchor"] = "layer2"
network = Scaffold(Configuration.default(**self.cfg), self.storage)
Expand Down

0 comments on commit d5c1160

Please sign in to comment.