|
8 | 8 | from tiledb.bioimg import ATTR_NAME |
9 | 9 | from tiledb.cc import WebpInputFormat |
10 | 10 | from tiledb.bioimg.helpers import merge_ned_ranges |
| 11 | +import xml.etree.ElementTree as ET |
11 | 12 |
|
12 | 13 | DATA_DIR = Path(__file__).parent / "data" |
13 | 14 |
|
@@ -112,3 +113,96 @@ def generate_test_case(num_axes, num_ranges, max_value): |
112 | 113 | expected_output = merge_ned_ranges(input_ranges) |
113 | 114 |
|
114 | 115 | return input_ranges, expected_output |
| 116 | + |
| 117 | + |
| 118 | +def generate_xml(has_macro=True, has_label=True, root_tag="OME", num_images=1): |
| 119 | + """Generate synthetic XML strings with options to include 'macro' and 'label' images.""" |
| 120 | + |
| 121 | + # Create the root element |
| 122 | + ome = ET.Element( |
| 123 | + root_tag, |
| 124 | + { |
| 125 | + "xmlns": "http://www.openmicroscopy.org/Schemas/OME/2016-06", |
| 126 | + "xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance", |
| 127 | + "Creator": "tifffile.py 2023.7.4", |
| 128 | + "UUID": "urn:uuid:40348664-c1f8-11ee-a19b-58112295faaf", |
| 129 | + "xsi:schemaLocation": "http://www.openmicroscopy.org/Schemas/OME/2016-06 http://www.openmicroscopy.org/Schemas/OME/2016-06/ome.xsd", |
| 130 | + }, |
| 131 | + ) |
| 132 | + |
| 133 | + # Create an instrument element |
| 134 | + instrument = ET.SubElement(ome, "Instrument", ID="Instrument:95") |
| 135 | + objective = ET.SubElement( |
| 136 | + instrument, "Objective", ID="Objective:95", NominalMagnification="40.0" |
| 137 | + ) |
| 138 | + |
| 139 | + # Create standard image elements |
| 140 | + for i in range(num_images): |
| 141 | + image = ET.SubElement(ome, "Image", ID=f"Image:{i}", Name=f"Image{i}") |
| 142 | + pixels = ET.SubElement( |
| 143 | + image, |
| 144 | + "Pixels", |
| 145 | + DimensionOrder="XYCZT", |
| 146 | + ID=f"Pixels:{i}", |
| 147 | + SizeC="3", |
| 148 | + SizeT="1", |
| 149 | + SizeX="86272", |
| 150 | + SizeY="159488", |
| 151 | + SizeZ="1", |
| 152 | + Type="uint8", |
| 153 | + Interleaved="true", |
| 154 | + PhysicalSizeX="0.2827", |
| 155 | + PhysicalSizeY="0.2827", |
| 156 | + ) |
| 157 | + channel = ET.SubElement( |
| 158 | + pixels, "Channel", ID=f"Channel:{i}:0", SamplesPerPixel="3" |
| 159 | + ) |
| 160 | + tiffdata = ET.SubElement(pixels, "TiffData", PlaneCount="1") |
| 161 | + |
| 162 | + # Conditionally add 'macro' and 'label' images |
| 163 | + if has_label: |
| 164 | + label_image = ET.SubElement(ome, "Image", ID="Image:label", Name="label") |
| 165 | + pixels = ET.SubElement( |
| 166 | + label_image, |
| 167 | + "Pixels", |
| 168 | + DimensionOrder="XYCZT", |
| 169 | + ID="Pixels:label", |
| 170 | + SizeC="3", |
| 171 | + SizeT="1", |
| 172 | + SizeX="604", |
| 173 | + SizeY="594", |
| 174 | + SizeZ="1", |
| 175 | + Type="uint8", |
| 176 | + Interleaved="true", |
| 177 | + PhysicalSizeX="43.0", |
| 178 | + PhysicalSizeY="43.0", |
| 179 | + ) |
| 180 | + channel = ET.SubElement( |
| 181 | + pixels, "Channel", ID="Channel:label:0", SamplesPerPixel="3" |
| 182 | + ) |
| 183 | + tiffdata = ET.SubElement(pixels, "TiffData", IFD="1", PlaneCount="1") |
| 184 | + |
| 185 | + if has_macro: |
| 186 | + macro_image = ET.SubElement(ome, "Image", ID="Image:macro", Name="macro") |
| 187 | + pixels = ET.SubElement( |
| 188 | + macro_image, |
| 189 | + "Pixels", |
| 190 | + DimensionOrder="XYCZT", |
| 191 | + ID="Pixels:macro", |
| 192 | + SizeC="3", |
| 193 | + SizeT="1", |
| 194 | + SizeX="604", |
| 195 | + SizeY="1248", |
| 196 | + SizeZ="1", |
| 197 | + Type="uint8", |
| 198 | + Interleaved="true", |
| 199 | + PhysicalSizeX="43.0", |
| 200 | + PhysicalSizeY="43.0", |
| 201 | + ) |
| 202 | + channel = ET.SubElement( |
| 203 | + pixels, "Channel", ID="Channel:macro:0", SamplesPerPixel="3" |
| 204 | + ) |
| 205 | + tiffdata = ET.SubElement(pixels, "TiffData", IFD="2", PlaneCount="1") |
| 206 | + |
| 207 | + # Convert the ElementTree to a string |
| 208 | + return ET.tostring(ome, encoding="unicode") |
0 commit comments