Created
April 27, 2017 15:05
-
-
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
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
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