From 391cb7d5dfe0bd9f5aaa168154dda7ad67207609 Mon Sep 17 00:00:00 2001 From: drodarie Date: Thu, 10 Apr 2025 11:14:41 +0200 Subject: [PATCH] feat: expose unique labels of PlacementSet allow to filter non labelled placement sets --- bsb/_encoding.py | 15 +++++++++++++-- bsb/storage/interfaces.py | 21 +++++++++++++++++---- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/bsb/_encoding.py b/bsb/_encoding.py index 396c360e3..ecb08d41a 100644 --- a/bsb/_encoding.py +++ b/bsb/_encoding.py @@ -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): diff --git a/bsb/storage/interfaces.py b/bsb/storage/interfaces.py index 3f7888659..098fc4abd 100644 --- a/bsb/storage/interfaces.py +++ b/bsb/storage/interfaces.py @@ -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]