Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix datetime writing #106

Merged
merged 3 commits into from
Aug 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/ome_types/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from xml.etree import ElementTree

import xmlschema
from elementpath.datatypes import DateTime10
from xmlschema import ElementData, XMLSchemaParseError
from xmlschema.converters import XMLSchemaConverter
from xmlschema.documents import XMLSchemaValueError
Expand Down Expand Up @@ -189,7 +188,9 @@ def element_encode(
tag = xsd_element.qualified_name
if not isinstance(obj, OMEType):
if isinstance(obj, datetime):
return ElementData(tag, DateTime10.fromdatetime(obj), None, {})
return ElementData(
tag, obj.isoformat().replace("+00:00", "Z"), None, {}
)
elif isinstance(obj, ElementTree.Element):
# ElementData can't represent mixed content, so we'll leave this
# element empty and fix it up after encoding is complete.
Expand Down Expand Up @@ -241,7 +242,7 @@ def element_encode(
elif isinstance(value, Enum):
value = value.value
elif isinstance(value, datetime):
value = DateTime10.fromdatetime(value)
value = value.isoformat().replace("+00:00", "Z")
attributes[name] = value
elif name == "Value" and xsd_element.local_name in {"BinData", "UUID", "M"}:
text = value
Expand Down
44 changes: 44 additions & 0 deletions testing/data/OverViewScan.ome.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?xml version="1.0"?>
<ome:OME xmlns:ome="http://www.openmicroscopy.org/Schemas/OME/2016-06"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.openmicroscopy.org/Schemas/OME/2016-06 http://www.openmicroscopy.org/Schemas/OME/2016-06/ome.xsd">
<ome:Plate ID="Plate:1" WellOriginX="0" WellOriginY="0">
<ome:PlateAcquisition ID="PlateAcquisition:1"
StartTime="2016-03-11T10:23:44.925154Z"/>
</ome:Plate>
<ome:Experimenter ID="Experimenter:M1SRH" UserName="M1SRH"/>
<ome:Instrument ID="Instrument:0">
<ome:Microscope Manufacturer="Zeiss" Model="" SerialNumber=""/>
<ome:Filament ID="LightSource:1" Type="Other"/>
<ome:Detector ID="Detector:506m_Intern" Model="Axiocam506m"/>
<ome:Objective ID="Objective:1"/>
</ome:Instrument>
<ome:Image ID="Image:0" Name="TR1">
<ome:AcquisitionDate>2016-03-11T10:23:44.925154Z</ome:AcquisitionDate>
<ome:ObjectiveSettings ID="Objective:1" Medium="Air"
RefractiveIndex="1.000293"/>
<ome:Pixels ID="Pixels:1-0" DimensionOrder="XYZCT" SignificantBits="14"
Type="uint16" SizeX="7398" SizeY="3212" SizeZ="1" SizeC="1"
SizeT="1" PhysicalSizeX="4.5743626119409"
PhysicalSizeXUnit="µm" PhysicalSizeY="4.5743626119409"
PhysicalSizeYUnit="µm">
<ome:Channel ID="Channel:0-0" Name="DAPI"
AcquisitionMode="WideField"
IlluminationType="Epifluorescence"
ExcitationWavelength="353"
ExcitationWavelengthUnit="nm" EmissionWavelength="465"
EmissionWavelengthUnit="nm" Fluor="DAPI">
<ome:DetectorSettings ID="Detector:506m_Intern"
Binning="Other"/>
</ome:Channel>
<ome:TiffData IFD="1"/>
</ome:Pixels>
</ome:Image>
<ome:StructuredAnnotations>
<ome:XMLAnnotation
ID="urn:lsid:allencell.org:Annotation:AcquisitionSoftware">
<ome:Description>ZEN 2 (blue edition)2.3.64.0</ome:Description>
<ome:Value/>
</ome:XMLAnnotation>
</ome:StructuredAnnotations>
</ome:OME>