Created
November 13, 2017 13:34
-
-
Save will-moore/b9ba8c9e162c8db6fe336fb1d1b47858 to your computer and use it in GitHub Desktop.
Adding Instrument metadata to an Image in OMERO
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
# See https://www.openmicroscopy.org/community/viewtopic.php?f=4&t=8397#p18758 | |
import omero | |
from omero.gateway import BlitzGateway | |
from omero.model import InstrumentI, MicroscopeI, ObjectiveSettingsI, ObjectiveI | |
from omero.rtypes import rstring, rdouble | |
conn = BlitzGateway("user", "password", host="server.org", port=4064) | |
conn.connect() | |
image_id = 72495 | |
update_service = conn.getUpdateService() | |
# Objects listed at http://docs.openmicroscopy.org/latest/omero/developers/Model/EveryObject.html | |
microscope = MicroscopeI() | |
microscope.manufacturer = rstring("XYZ Microscope Co") | |
microscope.model = rstring("ABC-123") | |
# To see enumeration types:, e.g. ['MicroscopeType', 'Immersion',...] | |
# conn.getEnumerations() | |
# To see values for a particular enumeration: e.g. ['Upright', 'Inverted',...] | |
# for t in conn.getEnumerationEntries('MicroscopeType'): | |
# print t.getValue() | |
# Lookup the enumeration we need | |
t = conn.getTypesService().getEnumeration('MicroscopeType', 'Upright') | |
microscope.type = t | |
instrument = InstrumentI() | |
instrument.microscope = microscope | |
# Objective and Objective Settings. | |
objective = ObjectiveI() | |
objective.nominalMagnification = rdouble(40) | |
i = conn.getTypesService().getEnumeration('Immersion', 'Oil') | |
objective.immersion = i | |
c = conn.getTypesService().getEnumeration('Correction', 'PlanApo') | |
objective.correction = c | |
objective.instrument = instrument | |
obj_settings = ObjectiveSettingsI() | |
obj_settings.objective = objective | |
# Image | |
image = conn.getQueryService().get('Image', image_id) | |
image.instrument = instrument | |
image.objectiveSettings = obj_settings | |
update_service.saveObject(image) | |
conn.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment