Skip to content

Commit

Permalink
fix: count_ratio on non overlapping partitions
Browse files Browse the repository at this point in the history
  • Loading branch information
drodarie committed Sep 21, 2024
1 parent 6b73dbe commit 2405b8e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
10 changes: 4 additions & 6 deletions bsb/placement/indicator.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,10 @@ def guess(self, chunk=None, voxels=None):
relation = relative_to
if count_ratio is not None:
strats = self._strat.scaffold.get_placement_of(relation)
estimate = (
sum(
PlacementIndicator(s, relation).guess(chunk, voxels)
for s in strats
)
* count_ratio
estimate = self._estim_for_chunk(
chunk,
sum(PlacementIndicator(s, relation).guess() for s in strats)
* count_ratio,
)
elif density_ratio is not None:
# Create an indicator based on this strategy for the related CT.
Expand Down
20 changes: 20 additions & 0 deletions tests/test_placement.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
PlacementError,
PlacementRelationError,
PlacementStrategy,
Rhomboid,
Scaffold,
VoxelData,
Voxels,
Expand Down Expand Up @@ -222,6 +223,25 @@ def test_guess_vox_density(self):
# voxel density key not found
dud4_ind.guess(voxels=self.voxels.get_voxelset())

def test_regression_issue_885(self):
# Test placement with count ratio in separated partitions
self.network.topology.children.append(
part := Rhomboid(
name="dud_layer2", origin=[0, 0, 120], dimensions=[200, 200, 80]
)
)
self.network.resize()
placement = PlacementDud(
name="dud",
strategy="PlacementDud",
partitions=[part],
cell_types=[self.network.cell_types["cell_rel_count"]],
)
self.network.placement["dud3"] = placement
indic = placement.get_indicators()["cell_rel_count"]
self.assertEqual(20 / 4, indic.guess(_chunk(0, 0, 1)))
self.assertEqual(20 / 4, indic.guess(_chunk(1, 1, 1)))

def test_negative_guess_count(self):
self.placement = single_layer_placement(
self.network, offset=np.array([-300.0, -300.0, -300.0])
Expand Down

0 comments on commit 2405b8e

Please sign in to comment.