Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add getROIs #380

Merged
merged 5 commits into from
Aug 23, 2023
Merged
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
56 changes: 36 additions & 20 deletions src/omero/gateway/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10354,18 +10354,7 @@ def getInplaceImport(self):
if ns == a['ns']:
return a['value']

def getROICount(self, shapeType=None, filterByCurrentUser=False):
"""
Count number of ROIs associated to an image

:param shapeType: Filter by shape type ("Rectangle",...).
:param filterByCurrentUser: Whether or not to filter the count by
the currently logged in user.
:return: Number of ROIs found for the currently logged in user if
filterByCurrentUser is True, otherwise the total number
found.
"""

def _get_rois(self, shapeType=None, filterByCurrentUser=False):
# Create ROI shape validator (return True if at least one shape is
# found)
def isValidType(shape):
Expand All @@ -10385,6 +10374,40 @@ def isValidROI(roi):
return True
return False

roiOptions = omero.api.RoiOptions()
if filterByCurrentUser:
roiOptions.userId = omero.rtypes.rlong(self._conn.getUserId())

result = self._conn.getRoiService().findByImage(self.id, roiOptions)
rois = [roi for roi in result.rois if isValidROI(roi)]
return rois

def getROIs(self, shapeType=None, filterByCurrentUser=False):
"""
Gets ROIs associated to an image

:param shapeType: Filter by shape type ("Rectangle",...).
:param filterByCurrentUser: Whether or not to filter the count by
the currently logged in user.
:return: list of ROIs found for the currently logged in user if
filterByCurrentUser is True, otherwise the total rois
found.
"""
return [RoiWrapper(self._conn, roi) for roi in
self._get_rois(shapeType, filterByCurrentUser)]


def getROICount(self, shapeType=None, filterByCurrentUser=False):
"""
Count number of ROIs associated to an image

:param shapeType: Filter by shape type ("Rectangle",...).
:param filterByCurrentUser: Whether or not to filter the count by
the currently logged in user.
:return: Number of ROIs found for the currently logged in user if
filterByCurrentUser is True, otherwise the total number
found.
"""
# Optimisation for the most common use case of unfiltered ROI counts
# for the current user.
if shapeType is None:
Expand All @@ -10400,14 +10423,7 @@ def isValidROI(roi):
# Projection returns a two dimensional array of RType wrapped
# return values so we want the value of row one, column one.
return count[0][0].getValue()

roiOptions = omero.api.RoiOptions()
if filterByCurrentUser:
roiOptions.userId = omero.rtypes.rlong(self._conn.getUserId())

result = self._conn.getRoiService().findByImage(self.id, roiOptions)
count = sum(1 for roi in result.rois if isValidROI(roi))
return count
return len(self._get_rois(shapeType, filterByCurrentUser))

ImageWrapper = _ImageWrapper

Expand Down