Last active
November 6, 2024 14:34
-
-
Save sbesson/2e6ceb0b01429ab2cd4e0d685d8ebcc4 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env python | |
# Generate companion files for the TIFF files of the | |
# first sample dataset of EMPIAR-11537 available from | |
# https://ftp.ebi.ac.uk/empiar/world_availability/11537/data/4G_Run%201/ | |
import re | |
import sys | |
import uuid | |
import xml.etree.ElementTree as ET | |
OME_ATTRIBUTES = { | |
'UUID': "urn:uuid:%s" % uuid.uuid4(), | |
'xmlns': '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', | |
} | |
root = ET.Element("OME", attrib=OME_ATTRIBUTES) | |
image = ET.SubElement(root, "Image", attrib = { | |
'ID': 'Image:0', 'Name': '4G_Run 1'}) | |
pixels = ET.SubElement(image, "Pixels", attrib = { | |
'ID': 'Pixels:0:0', | |
'DimensionOrder': "XYZCT", | |
'Type': 'uint16', | |
'SizeX': '14976', | |
'SizeY': '14976', | |
'SizeZ': '3419', | |
'SizeT': '1', | |
'SizeC': '1', | |
'PhysicalSizeX': '50', | |
'PhysicalSizeXUnit': 'Å', | |
'PhysicalSizeY': '50', | |
'PhysicalSizeYUnit': 'Å'}) | |
# Requires a file_list.txt file with all the TIFF files | |
with open('file_list.txt', 'r') as f: | |
tiffs = [line.rstrip() for line in f] | |
for i in range(len(tiffs)): | |
tiffdata = ET.SubElement(pixels, "TiffData", attrib={ | |
"FirstC": "0", | |
"FirstT": "0", | |
"FirstZ": str(i), | |
"IFD": "0", | |
"PlaneCount": "1"}) | |
ET.SubElement(tiffdata, "UUID", { | |
"FileName": tiffs[i]}).text = "urn:uuid:%s" % uuid.uuid4() | |
kwargs = { | |
"encoding": "UTF-8", | |
"xml_declaration": True | |
} | |
ET.ElementTree(root).write("EMPIAR-11537.companion.ome", **kwargs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment