Skip to content

Instantly share code, notes, and snippets.

@will-moore
Created April 27, 2017 15:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save will-moore/03ef6cbd1f95d837af747538ba379b4c to your computer and use it in GitHub Desktop.
Save will-moore/03ef6cbd1f95d837af747538ba379b4c to your computer and use it in GitHub Desktop.
Convert OMERO image Original metadata into a map annotation on the Image
import omero
from omero.gateway import BlitzGateway
# See https://www.openmicroscopy.org/community/viewtopic.php?f=4&t=8268
imageId = 72416
conn = BlitzGateway("username", "password", host="localhost", port=4064)
conn.connect()
image = conn.getObject("Image", imageId)
map_ann_data = []
# Pick these items of metadata -> map annotation
attributes = ('Camera Name', 'CameraOffset', 'dPosName', 'sObjective')
# Load the 'Original Metadata' for the image
# ==========================================
om = image.loadOriginalMetadata()
if om is not None:
key_values = om[1] + om[2]
for key_value in key_values:
if len(key_value) > 1 and key_value[0] in attributes:
map_ann_data.append([key_value[0], str(key_value[1])])
# Create a 'map' annotation (list of key: value pairs)
# ====================================================
map_ann = omero.gateway.MapAnnotationWrapper(conn)
map_ann.setNs('original.metadata.from.script')
map_ann.setValue(map_ann_data)
map_ann.save()
image.linkAnnotation(map_ann)
conn.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment