retuve.typehints

Useful Type Hints for the Retuve package.

 1# Copyright 2024 Adam McArthur
 2#
 3# Licensed under the Apache License, Version 2.0 (the "License");
 4# you may not use this file except in compliance with the License.
 5# You may obtain a copy of the License at
 6#
 7#     http://www.apache.org/licenses/LICENSE-2.0
 8#
 9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15"""
16Useful Type Hints for the Retuve package.
17"""
18
19from typing import (
20    Annotated,
21    Any,
22    BinaryIO,
23    Callable,
24    Dict,
25    List,
26    Literal,
27    Tuple,
28    TypeVar,
29    Union,
30)
31
32import numpy as np
33import numpy.typing as npt
34import pydicom
35from PIL import Image
36
37from retuve.classes.seg import SegFrameObjects
38from retuve.hip_xray.classes import LandmarksXRay
39
40DType = TypeVar("DType", bound=np.generic)
41
42"""The type of retuves expected mask"""
43NDArrayImg_NxNx3_AllWhite = Annotated[npt.NDArray[DType], Literal["N", "N", 3]]
44
45"""The expected type of midlines"""
46MidLine = List[Tuple[int, int]]
47
48"""Any acceptable file-like object."""
49FileLike = Union[BinaryIO, Image.Image, pydicom.FileDataset]
50
51"""Keyphrase as a string or a config"""
52KeyphraseLike = Union[str, List[str]]
53
54"""The expected form of AI Model Functions for the retuve package"""
55GeneralModeFuncType = Callable[
56    [
57        FileLike,
58        KeyphraseLike,
59        Dict[str, Any],
60    ],
61    Union[
62        Tuple[List[LandmarksXRay], List[SegFrameObjects]],
63        List[SegFrameObjects],
64    ],
65]
DType = ~DType

The type of retuves expected mask

NDArrayImg_NxNx3_AllWhite = typing.Annotated[numpy.ndarray[typing.Any, numpy.dtype[~DType]], typing.Literal['N', 3]]

The expected type of midlines

MidLine = typing.List[typing.Tuple[int, int]]

Any acceptable file-like object.

FileLike = typing.Union[typing.BinaryIO, PIL.Image.Image, pydicom.dataset.FileDataset]

Keyphrase as a string or a config

KeyphraseLike = typing.Union[str, typing.List[str]]

The expected form of AI Model Functions for the retuve package

GeneralModeFuncType = typing.Callable[[typing.Union[typing.BinaryIO, PIL.Image.Image, pydicom.dataset.FileDataset], typing.Union[str, typing.List[str]], typing.Dict[str, typing.Any]], typing.Union[typing.Tuple[typing.List[retuve.hip_xray.classes.LandmarksXRay], typing.List[retuve.classes.seg.SegFrameObjects]], typing.List[retuve.classes.seg.SegFrameObjects]]]