Skip to content

Commit 13f3f88

Browse files
sbessontlambert03
andauthored
docs: Add example of writing companion files using ome-types (#277)
Illustrate the example of a single multi-Z, multi-T, multi-C image with one TIFF file per timepoint using the raw fluorescence images from idr0052 as the source (https://doi.org/10.17867/10000123a). Co-authored-by: Talley Lambert <[email protected]>
1 parent f8822fa commit 13f3f88

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

docs/usage.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,3 +176,59 @@ In [23]: print(to_xml(ome)) # or ome.to_xml()
176176
</Image>
177177
</OME>
178178
```
179+
180+
## Writing companion OME files
181+
182+
The writing capability can be used to generate OME-TIFF filesets as
183+
described in the [OME-TIFF](https://ome-model.readthedocs.io/en/stable/ome-tiff/specification.html)
184+
by storing the metadata as OME-XML into a companion file.
185+
186+
The following code demonstrates how to write companion files for the
187+
multi-channel fluorescent images published in
188+
[IDR](https://idr.openmicroscopy.org/) under the accession idr0052 and
189+
available at [10.17867/10000123a](https://doi.org/10.17867/10000123a).
190+
191+
The associated raw TIFF files can be downloaded from
192+
[here](https://ftp.ebi.ac.uk/pub/databases/IDR/idr0052-walther-condensinmap/20181113-ftp/MitoSys/160719_NCAPD2gfpc272c78_MitoSys2/cell0005_R0001/rawtif/)
193+
194+
```python
195+
from ome_types.model import Channel
196+
from ome_types.model import Image
197+
from ome_types.model import OME
198+
from ome_types.model import Pixels
199+
from ome_types.model import TiffData
200+
import uuid
201+
202+
ome = OME(uuid=f"urn:uuid:{uuid.uuid4()}")
203+
pixels = Pixels(
204+
dimension_order='XYZCT',
205+
physical_size_x="0.2516",
206+
physical_size_y="0.2516",
207+
physical_size_z="0.75",
208+
size_x=256,
209+
size_y=256,
210+
size_z=31,
211+
size_c=3,
212+
size_t=40,
213+
type='uint16')
214+
pixels.channels.extend([
215+
Channel(color="16711935", name="NCAPD2", samples_per_pixel=1),
216+
Channel(color="65535", name="DNA", samples_per_pixel=1),
217+
Channel(color="-1", name="NEG_Dextran", samples_per_pixel=1)])
218+
ome.images.append(Image(name="cell0005_R0001", pixels=pixels))
219+
220+
for t in range(40):
221+
filename = "TR1_2_W0001_P0001_T%04g.tif" % (t+1)
222+
tiff_uuid = f"urn:uuid:{uuid.uuid4()}"
223+
tiff = TiffData(
224+
first_c=0,
225+
first_t=t,
226+
first_z=0,
227+
plane_count=93,
228+
uuid=TiffData.UUID(value=tiff_uuid, file_name=filename)
229+
)
230+
pixels.tiff_data_blocks.append(tiff)
231+
232+
with open("cell0005_R0001.companion.ome", 'w') as f:
233+
f.write(ome.to_xml())
234+
```

0 commit comments

Comments
 (0)