Skip to content

Commit

Permalink
Pull out _tiff2xml from from_tiff (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
tlambert03 authored Jan 29, 2021
1 parent f24cf68 commit 18cd362
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/ome_types/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,29 @@ def from_tiff(path: Union[Path, str]) -> OME:
ome: ome_types.model.ome.OME
ome_types.OME metadata object
Raises
------
ValueError
If the TIFF file has no OME metadata.
"""
return from_xml(_tiff2xml(path))


def _tiff2xml(path: Union[Path, str]) -> str:
"""Extract OME XML from OME-TIFF path.
This will use the first ImageDescription tag found in the TIFF header.
Parameters
----------
path : Union[Path, str]
Path to OME TIFF.
Returns
-------
xml : str
OME XML
Raises
------
ValueError
Expand Down Expand Up @@ -89,4 +112,4 @@ def from_tiff(path: Union[Path, str]) -> OME:
raise ValueError(f"No OME metadata found in file: {path}")
if desc[-1] == 0:
desc = desc[:-1]
return from_xml(desc.decode("utf-8"))
return desc.decode("utf-8")

0 comments on commit 18cd362

Please sign in to comment.