Skip to content

Commit 39f2aa8

Browse files
authored
Merge pull request #58 from pskeshu/master
Fixed a problem with OMEXML parsing metadata. Added Instrument and Objective information parsing from OMEXML.
2 parents 17bf5ee + 10722d5 commit 39f2aa8

File tree

1 file changed

+109
-2
lines changed

1 file changed

+109
-2
lines changed

bioformats/omexml.py

Lines changed: 109 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,11 @@ def __init__(self, xml=None):
317317
xml = default_xml
318318
if isinstance(xml, str):
319319
xml = xml.encode("utf-8")
320-
self.dom = ElementTree.ElementTree(ElementTree.fromstring(xml))
321-
320+
try:
321+
self.dom = ElementTree.ElementTree(ElementTree.fromstring(xml))
322+
except UnicodeEncodeError:
323+
xml = xml.encode("utf-8")
324+
self.dom = ElementTree.ElementTree(ElementTree.fromstring(xml))
322325
# determine OME namespaces
323326
self.ns = get_namespaces(self.dom.getroot())
324327
if self.ns['ome'] is None:
@@ -604,6 +607,21 @@ def get_PixelType(self):
604607
and set the pixel type.
605608
'''
606609
return self.node.get("Type")
610+
611+
def get_PhysicalSizeX(self):
612+
'''The length of a single pixel in microns in X direction'''
613+
return get_float_attr(self.node, "PhysicalSizeX")
614+
def set_PhysicalSizeX(self, value):
615+
self.node.set("PhysicalSizeX", str(value))
616+
PhysicalSizeX = property(get_PhysicalSizeX, set_PhysicalSizeX)
617+
618+
def get_PhysicalSizeY(self):
619+
'''The length of a single pixel in microns in Y direction'''
620+
return get_float_attr(self.node, "PhysicalSizeY")
621+
def set_PhysicalSizeY(self, value):
622+
self.node.set("PhysicalSizeY", str(value))
623+
PhysicalSizeY = property(get_PhysicalSizeY, set_PhysicalSizeY)
624+
607625
def set_PixelType(self, value):
608626
self.node.set("Type", value)
609627
PixelType = property(get_PixelType, set_PixelType)
@@ -713,6 +731,95 @@ def Plane(self, index=0):
713731
plane = self.node.findall(qn(self.ns['ome'], "Plane"))[index]
714732
return OMEXML.Plane(plane)
715733

734+
class Instrument(object):
735+
'''Representation of the OME/Instrument element'''
736+
def __init__(self, node):
737+
self.node = node
738+
self.ns = get_namespaces(self.node)
739+
740+
def get_ID(self):
741+
return self.node.get("ID")
742+
743+
def set_ID(self, value):
744+
self.node.set("ID", value)
745+
746+
ID = property(get_ID, set_ID)
747+
748+
@property
749+
def Detector(self):
750+
return OMEXML.Detector(self.node.find(qn(self.ns['ome'], "Detector")))
751+
752+
@property
753+
def Objective(self):
754+
return OMEXML.Objective(self.node.find(qn(self.ns['ome'], "Objective")))
755+
756+
757+
def instrument(self, index=0):
758+
return self.Instrument(self.root_node.findall(qn(self.ns['ome'], "Instrument"))[index])
759+
760+
761+
class Objective(object):
762+
def __init__(self, node):
763+
self.node = node
764+
self.ns = get_namespaces(self.node)
765+
766+
def get_ID(self):
767+
return self.node.get("ID")
768+
def set_ID(self, value):
769+
self.node.set("ID", value)
770+
ID = property(get_ID, set_ID)
771+
772+
def get_LensNA(self):
773+
return self.node.get("LensNA")
774+
775+
def set_LensNA(self, value):
776+
self.node.set("LensNA", value)
777+
LensNA = property(get_LensNA, set_LensNA)
778+
779+
def get_NominalMagnification(self):
780+
return self.node.get("NominalMagnification")
781+
def set_NominalMagnification(self, value):
782+
self.node.set("NominalMagnification", value)
783+
NominalMagnification = property(get_NominalMagnification, set_NominalMagnification)
784+
785+
def get_WorkingDistanceUnit(self):
786+
return get_int_attr(self.node, "WorkingDistanceUnit")
787+
def set_WorkingDistanceUnit(self, value):
788+
self.node.set("WorkingDistanceUnit", str(value))
789+
WorkingDistanceUnit = property(get_WorkingDistanceUnit, set_WorkingDistanceUnit)
790+
791+
class Detector(object):
792+
def __init__(self, node):
793+
self.node = node
794+
self.ns = get_namespaces(self.node)
795+
796+
def get_ID(self):
797+
return self.node.get("ID")
798+
def set_ID(self, value):
799+
self.node.set("ID", value)
800+
ID = property(get_ID, set_ID)
801+
802+
def get_Gain(self):
803+
return self.node.get("Gain")
804+
805+
def set_Gain(self, value):
806+
self.node.set("Gain", value)
807+
Gain = property(get_Gain, set_Gain)
808+
809+
def get_Model(self):
810+
return self.node.get("Model")
811+
def set_Model(self, value):
812+
self.node.set("Model", value)
813+
Model = property(get_Model, set_Model)
814+
815+
def get_Type(self):
816+
return get_int_attr(self.node, "Type")
817+
def set_Type(self, value):
818+
self.node.set("Type", str(value))
819+
Type = property(get_Type, set_Type)
820+
821+
822+
716823
class StructuredAnnotations(dict):
717824
'''The OME/StructuredAnnotations element
718825

0 commit comments

Comments
 (0)