Skip to content

Commit

Permalink
Merge branch 'philips'
Browse files Browse the repository at this point in the history
  • Loading branch information
ap-- committed Nov 29, 2023
2 parents 3b6b1fc + 9963b57 commit 3f5382d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ repos:
- id: black
language_version: python3
- repo: https://github.com/pre-commit/mirrors-mypy
rev: 'v1.6.1'
rev: 'v1.7.1'
hooks:
- id: mypy
additional_dependencies: ["numpy"]
Expand Down
5 changes: 1 addition & 4 deletions tiffslide/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,7 @@ def __getattr__(name: str) -> Any:
raise AttributeError(name)


if sys.version_info >= (3, 9):
PathLikeStr: TypeAlias = os.PathLike[str]
else:
PathLikeStr: TypeAlias = os.PathLike
PathLikeStr: TypeAlias = "os.PathLike[str]"


@runtime_checkable
Expand Down
30 changes: 30 additions & 0 deletions tiffslide/tiffslide.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from typing import Iterator
from typing import Literal
from typing import Mapping
from typing import Optional
from typing import TypeVar
from typing import overload
from warnings import warn
Expand Down Expand Up @@ -644,6 +645,7 @@ class _PropertyParser:
scn="leica",
bif="ventana",
ndpi="hamamatsu",
philips="philips_tiff"
# add more when needed
)

Expand Down Expand Up @@ -843,6 +845,34 @@ def parse_generic_tiff(self) -> dict[str, Any]:
md.update(self.collect_level_info(series0))
return md

def parse_philips_tiff(self) -> dict[str, Any]:
"""parse Philips tiff properties"""
md = self.parse_generic_tiff()
if self._tf.philips_metadata is None:
return md
philips_metadata = ElementTree.fromstring(self._tf.philips_metadata)

def get_first_attribute_with_name(
root: ElementTree.Element, name: str
) -> str | None:
return next(root.iterfind(f".//Attribute[@Name='{name}']")).text

md[PROPERTY_NAME_VENDOR] = get_first_attribute_with_name(
philips_metadata, "DICOM_MANUFACTURER"
)
pixel_spacing_attribute = get_first_attribute_with_name(
philips_metadata, "DICOM_PIXEL_SPACING"
)
if pixel_spacing_attribute is not None:
pixel_spacings = [
float(element.strip('"')) * 1000
for element in pixel_spacing_attribute.split(" ")
]
mpp_x, mpp_y = pixel_spacings[0], pixel_spacings[1]
md[PROPERTY_NAME_MPP_X] = mpp_x
md[PROPERTY_NAME_MPP_Y] = mpp_y
return md


def _parse_metadata_aperio(desc: str) -> dict[str, Any]:
"""Aperio SVS metadata"""
Expand Down

0 comments on commit 3f5382d

Please sign in to comment.