-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3776 from chris-allan/plate-metadata-perf-develop
Optimize plate grid metadata
- Loading branch information
Showing
6 changed files
with
552 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
components/tools/OmeroPy/test/integration/gatewaytest/test_image_wrapper.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
# Copyright (C) 2015 Glencoe Software, Inc. | ||
# All rights reserved. | ||
# | ||
# Use is subject to license terms supplied in LICENSE.txt | ||
|
||
""" | ||
gateway tests - Testing the gateway image wrapper | ||
pytest fixtures used as defined in conftest.py: | ||
- gatewaywrapper | ||
""" | ||
|
||
import pytest | ||
|
||
from omero.model import ImageI | ||
from omero.rtypes import rstring, rtime | ||
from datetime import datetime | ||
|
||
|
||
@pytest.fixture() | ||
def image(request, gatewaywrapper): | ||
"""Creates an Image.""" | ||
gatewaywrapper.loginAsAuthor() | ||
gw = gatewaywrapper.gateway | ||
update_service = gw.getUpdateService() | ||
image = ImageI() | ||
image.name = rstring('an image') | ||
# 2015-04-21 01:15:00 | ||
image.acquisitionDate = rtime(1429578900000L) | ||
image_id, = update_service.saveAndReturnIds([image]) | ||
return gw.getObject('Image', image_id) | ||
|
||
|
||
@pytest.fixture() | ||
def image_no_acquisition_date(request, gatewaywrapper): | ||
"""Creates an Image.""" | ||
gatewaywrapper.loginAsAuthor() | ||
gw = gatewaywrapper.gateway | ||
update_service = gw.getUpdateService() | ||
image = ImageI() | ||
image.name = rstring('an image') | ||
image.acquisitionDate = rtime(0L) | ||
image_id, = update_service.saveAndReturnIds([image]) | ||
return gw.getObject('Image', image_id) | ||
|
||
|
||
class TestImageWrapper(object): | ||
|
||
def testGetDate(self, gatewaywrapper, image): | ||
date = image.getDate() | ||
assert date == datetime.fromtimestamp(1429578900L) | ||
|
||
def testGetDateNoAcquisitionDate( | ||
self, gatewaywrapper, image_no_acquisition_date): | ||
date = image_no_acquisition_date.getDate() | ||
creation_event_date = image_no_acquisition_date.creationEventDate() | ||
assert date == creation_event_date | ||
|
||
def testSimpleMarshal(self, gatewaywrapper, image): | ||
marshalled = image.simpleMarshal() | ||
assert marshalled == { | ||
'description': '', | ||
'author': 'Author ', | ||
'date': 1429578900.0, | ||
'type': 'Image', | ||
'id': image.getId(), | ||
'name': 'an image' | ||
} |
54 changes: 54 additions & 0 deletions
54
components/tools/OmeroPy/test/integration/gatewaytest/test_plate_wrapper.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
# Copyright (C) 2015 Glencoe Software, Inc. | ||
# All rights reserved. | ||
# | ||
# Use is subject to license terms supplied in LICENSE.txt | ||
|
||
""" | ||
gateway tests - Testing the gateway plate wrapper | ||
pytest fixtures used as defined in conftest.py: | ||
- gatewaywrapper | ||
""" | ||
|
||
import pytest | ||
|
||
from omero.model import PlateI, WellI, WellSampleI, ImageI | ||
from omero.rtypes import rstring, rint, rtime | ||
from uuid import uuid4 | ||
|
||
|
||
def uuid(): | ||
return str(uuid4()) | ||
|
||
|
||
@pytest.fixture() | ||
def plate(request, gatewaywrapper): | ||
"""Creates a Plate.""" | ||
gatewaywrapper.loginAsAuthor() | ||
gw = gatewaywrapper.gateway | ||
update_service = gw.getUpdateService() | ||
plate = PlateI() | ||
plate.name = rstring(uuid()) | ||
for well_index in range(3): | ||
well = WellI() | ||
well.row = rint(well_index**2) | ||
well.column = rint(well_index**3) | ||
for well_sample_index in range(2): | ||
well_sample = WellSampleI() | ||
image = ImageI() | ||
image.name = rstring('%s_%d' % (uuid(), well_sample_index)) | ||
image.acquisitionDate = rtime(0) | ||
well_sample.image = image | ||
well.addWellSample(well_sample) | ||
plate.addWell(well) | ||
plate_id, = update_service.saveAndReturnIds([plate]) | ||
return gw.getObject('Plate', plate_id) | ||
|
||
|
||
class TestPlateWrapper(object): | ||
|
||
def testGetGridSize(self, gatewaywrapper, plate): | ||
assert plate.getGridSize() == {'rows': 5L, 'columns': 9L} |
86 changes: 86 additions & 0 deletions
86
components/tools/OmeroWeb/omeroweb/webgateway/plategrid.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
# Copyright (C) 2015 Glencoe Software, Inc. | ||
# All rights reserved. | ||
# | ||
# Use is subject to license terms supplied in LICENSE.txt | ||
|
||
""" | ||
Module to encapsulate operations concerned with displaying the contents of a | ||
plate as a grid. | ||
""" | ||
|
||
import logging | ||
|
||
import omero.sys | ||
from omero.rtypes import rint | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class PlateGrid(object): | ||
""" | ||
A PlateGrid object encapsulates a PlateI reference and provides a number of | ||
methods useful for displaying the contents of the plate as a grid. | ||
""" | ||
|
||
def __init__(self, conn, pid, fid, thumbprefix=''): | ||
self.plate = conn.getObject('plate', long(pid)) | ||
self._conn = conn | ||
self.field = fid | ||
self._thumbprefix = thumbprefix | ||
self._metadata = None | ||
|
||
@property | ||
def metadata(self): | ||
if self._metadata is None: | ||
self.plate.setGridSizeConstraints(8, 12) | ||
size = self.plate.getGridSize() | ||
grid = [[None] * size['columns'] for _ in range(size['rows'])] | ||
|
||
q = self._conn.getQueryService() | ||
params = omero.sys.ParametersI() | ||
params.addId(self.plate.id) | ||
params.add('wsidx', rint(self.field)) | ||
query = "select well.row, well.column, img.id, img.name, "\ | ||
"author.firstName||' '||author.lastName, "\ | ||
"well.id, img.acquisitionDate, "\ | ||
"img.details.creationEvent.time, "\ | ||
"img.description "\ | ||
"from Well well "\ | ||
"join well.wellSamples ws "\ | ||
"join ws.image img "\ | ||
"join img.details.owner author "\ | ||
"where well.plate.id = :id "\ | ||
"and index(ws) = :wsidx" | ||
|
||
for res in q.projection(query, params, self._conn.SERVICE_OPTS): | ||
row, col, img_id, img_name, author, well_id, acq_date, \ | ||
create_date, description = res | ||
|
||
if acq_date is not None and acq_date.val > 0: | ||
date = acq_date.val / 1000 | ||
else: | ||
date = create_date.val / 1000 | ||
description = (description and description.val) or '' | ||
|
||
wellmeta = {'type': 'Image', | ||
'id': img_id.val, | ||
'name': img_name.val, | ||
'description': description, | ||
'author': author.val, | ||
'date': date, | ||
'wellId': well_id.val, | ||
'field': self.field} | ||
|
||
if callable(self._thumbprefix): | ||
wellmeta['thumb_url'] = self._thumbprefix(str(img_id.val)) | ||
else: | ||
wellmeta['thumb_url'] = self._thumbprefix + str(img_id.val) | ||
|
||
grid[row.val][col.val] = wellmeta | ||
|
||
self._metadata = {'grid': grid, | ||
'collabels': self.plate.getColumnLabels(), | ||
'rowlabels': self.plate.getRowLabels()} | ||
return self._metadata |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.