Coverage for src/bioimageio/core/_utils/tiff_metadata.py: 94%

33 statements  

« prev     ^ index     » next       coverage.py v7.17.3, created at 2026-11-20 09:46 +0000

1from __future__ import annotations 

2 

3from pydantic import BaseModel 

4 

5from .xml_utils import xml_to_dict 

6 

7 

8class ImageJMetadata(BaseModel, extra="allow"): 

9 """(Partial) Metadata for ImageJ TIFF files.""" 

10 

11 unit: str | None = None 

12 """The unit of measurement for the image (e.g., "micron", "pixel").""" 

13 

14 yunit: str | None = None 

15 """The unit of measurement for the Y dimension (e.g., "micron", "pixel").""" 

16 

17 zunit: str | None = None 

18 """The unit of measurement for the Z dimension (e.g., "micron", "pixel").""" 

19 

20 spacing: float | None = None 

21 """The physical spacing between slices in the Z dimension.""" 

22 

23 finterval: float | None = None 

24 """Time interval between frames in seconds.""" 

25 

26 fps: float | None = None 

27 """Frames per second for time-lapse images.""" 

28 

29 

30class OmeChannelMetadata(BaseModel, extra="allow"): 

31 """Partial Metadata for OME-TIFF channel information.""" 

32 

33 Name: list[str] 

34 """The name of the channel.""" 

35 

36 

37class OmeMetadata(BaseModel, extra="allow"): 

38 """Partial Metadata for ImageJ TIFF files.""" 

39 

40 Channel: OmeChannelMetadata | None = None 

41 DimensionOrder: str | None = None 

42 PhysicalSizeX: float | None = None 

43 PhysicalSizeXUnit: str | None = None 

44 PhysicalSizeY: float | None = None 

45 PhysicalSizeYUnit: str | None = None 

46 PhysicalSizeZ: float | None = None 

47 PhysicalSizeZUnit: str | None = None 

48 TimeIncrement: float | None = None 

49 TimeIncrementUnit: str | None = None 

50 

51 

52def create_ome_metadata_from_xml_string(xml_string: str) -> OmeMetadata: 

53 raw_ome_metadata = xml_to_dict(xml_string) 

54 return OmeMetadata.model_validate(raw_ome_metadata)