Skip to content
This repository was archived by the owner on Jun 11, 2025. It is now read-only.
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
15 changes: 13 additions & 2 deletions bsb/_encoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,19 @@ def index_of(self, labels):
else:
raise IndexError(f"Labelset {labels} does not exist")

def get_mask(self, labels):
has_any = [k for k, v in self.labels.items() if any(lbl in v for lbl in labels)]
def get_mask(self, labels=None):
"""
Get indexes matching the labels provided.

:param list[str] labels: List of labels
:rtype: numpy.ndarray[int]
"""
labels = set(labels or [])
has_any = [
k
for k, v in self.labels.items()
if any(lbl in v for lbl in labels) or v == labels
]
return np.isin(self, has_any)

def walk(self):
Expand Down
21 changes: 17 additions & 4 deletions bsb/storage/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -628,27 +628,40 @@ def label(self, labels, cells):
"""
Should label the cells with given labels.

:param cells: Array of cells in this set to label.
:type cells: numpy.ndarray
:param labels: List of labels
:type labels: list[str]
:param cells: Array of cells in this set to label.
:type cells: list[int]
"""
pass

@abc.abstractmethod
def get_unique_labels(self):
"""
Should return the unique labels assigned to the cells.

:return: List of unique labels
:rtype: list[set[str]]
"""
pass

@abc.abstractmethod
def get_labelled(self, labels):
def get_labelled(self, labels=None):
"""
Should return the ids of the cells labelled with given labels.
If labels are not provided, will filter non labelled cells.

:param labels: List of labels
:type labels: list[str]
:rtype: numpy.ndarray[int]
"""
pass

@abc.abstractmethod
def get_label_mask(self, labels):
def get_label_mask(self, labels=None):
"""
Should return a mask that fits the placement set for the cells with given labels.
If labels are not provided, will filter non labelled cells.

:param labels: List of labels
:type labels: list[str]
Expand Down
Loading