retuve.hip_xray.classes

Class Structs related to Hip X-Ray

  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"""
 16Class Structs related to Hip X-Ray
 17"""
 18
 19from enum import Enum
 20from typing import Any, Dict, List, Tuple
 21
 22from retuve.classes.general import RecordedError
 23from retuve.classes.metrics import Metric2D
 24
 25
 26class HipLabelsXray(Enum):
 27    """
 28    Segmentation Labels for Hip X-Ray
 29    """
 30
 31    AceTriangle = 0
 32
 33    @classmethod
 34    def get_name(cls, label: "HipLabelsXray"):
 35        """
 36        Get the name of the label from the Enum
 37
 38        :param label: The label
 39        :return: The name of the label
 40
 41        """
 42        if label == HipLabelsXray.AceTriangle:
 43            return "Acentabular Triangle"
 44        else:
 45            return "Unknown"
 46
 47
 48class DevMetricsXRay:
 49    """
 50    Developer Metrics for Hip X-Ray
 51
 52    Currently, this is a placeholder class.
 53    """
 54
 55    def __init__(self):
 56        pass
 57
 58    def docs(self):
 59        return {}
 60
 61    def __repr__(self) -> str:
 62        return "DevMetricsXRay()"
 63
 64    def data(self):
 65        return []
 66
 67    def json_dump(self):
 68        return {}
 69
 70
 71class LandmarksXRay:
 72    """
 73    Landmarks for Hip X-Ray
 74
 75    :attr pel_l_o: The Outer Pelvis Landmark on the Left
 76    :attr pel_l_i: The Inner Pelvis Landmark on the Left
 77    :attr pel_r_o: The Outer Pelvis Landmark on the Right
 78    :attr pel_r_i: The Inner Pelvis Landmark on the Right
 79    :attr fem_l: The Femoral Landmark on the Left
 80    :attr fem_r: The Femoral Landmark on the Right
 81    """
 82
 83    def __init__(
 84        self,
 85        pel_l_o: Tuple[float, float] = None,
 86        pel_l_i: Tuple[float, float] = None,
 87        pel_r_o: Tuple[float, float] = None,
 88        pel_r_i: Tuple[float, float] = None,
 89        fem_l: Tuple[float, float] = None,
 90        fem_r: Tuple[float, float] = None,
 91    ):
 92        self.pel_l_o = pel_l_o
 93        self.pel_l_i = pel_l_i
 94        self.pel_r_o = pel_r_o
 95        self.pel_r_i = pel_r_i
 96
 97        self.fem_l = fem_l
 98        self.fem_r = fem_r
 99
100    def __str__(self) -> str:
101        return (
102            f"Landmarks(pel_l_o={self.pel_l_o}, pel_l_i={self.pel_l_i}, "
103            f"pel_r_o={self.pel_r_o}, pel_r_i={self.pel_r_i}, "
104            f"fem_l={self.fem_l}, fem_r={self.fem_r})"
105        )
106
107    def __iter__(self) -> List[Tuple[float, float]]:
108        return iter(
109            [
110                self.pel_l_o,
111                self.pel_l_i,
112                self.pel_r_o,
113                self.pel_r_i,
114                self.fem_l,
115                self.fem_r,
116            ]
117        )
118
119    def items(self) -> Dict[str, Tuple]:
120        return {
121            "pel_l_o": self.pel_l_o,
122            "pel_l_i": self.pel_l_i,
123            "pel_r_o": self.pel_r_o,
124            "pel_r_i": self.pel_r_i,
125            "fem_l": self.fem_l,
126            "fem_r": self.fem_r,
127        }.items()
128
129    def __setitem__(self, key: str, value: Tuple[int, int]):
130        # use setattr to avoid infinite recursion
131        setattr(self, key, value)
132
133
134class HipDataXray:
135    """
136    Hip Data for X-Ray
137
138    :attr metrics: The Metrics
139    :attr dev_metrics: The Developer Metrics
140    :attr landmarks: The Landmarks
141    :attr frame_no: The Frame Number
142    :attr recorded_error: The Recorded Error
143    """
144
145    def __init__(self):
146        self.metrics: List[Metric2D] = []
147        self.dev_metrics: DevMetricsXRay = []
148        self.landmarks: LandmarksXRay = None
149        self.frame_no: int = None
150        self.recorded_error: RecordedError = RecordedError()
151
152    def json_dump(self, config, dev_metrics: DevMetricsXRay) -> Dict[str, Any]:
153        return {
154            "metrics": [
155                {metric.name: metric.value} for metric in self.metrics
156            ],
157            "keyphrase": config.name,
158            "dev_metrics": dev_metrics.json_dump(),
159        }
class HipLabelsXray(enum.Enum):
27class HipLabelsXray(Enum):
28    """
29    Segmentation Labels for Hip X-Ray
30    """
31
32    AceTriangle = 0
33
34    @classmethod
35    def get_name(cls, label: "HipLabelsXray"):
36        """
37        Get the name of the label from the Enum
38
39        :param label: The label
40        :return: The name of the label
41
42        """
43        if label == HipLabelsXray.AceTriangle:
44            return "Acentabular Triangle"
45        else:
46            return "Unknown"

Segmentation Labels for Hip X-Ray

AceTriangle = <HipLabelsXray.AceTriangle: 0>
@classmethod
def get_name(cls, label: HipLabelsXray):
34    @classmethod
35    def get_name(cls, label: "HipLabelsXray"):
36        """
37        Get the name of the label from the Enum
38
39        :param label: The label
40        :return: The name of the label
41
42        """
43        if label == HipLabelsXray.AceTriangle:
44            return "Acentabular Triangle"
45        else:
46            return "Unknown"

Get the name of the label from the Enum

Parameters
  • label: The label
Returns

The name of the label

Inherited Members
enum.Enum
name
value
class DevMetricsXRay:
49class DevMetricsXRay:
50    """
51    Developer Metrics for Hip X-Ray
52
53    Currently, this is a placeholder class.
54    """
55
56    def __init__(self):
57        pass
58
59    def docs(self):
60        return {}
61
62    def __repr__(self) -> str:
63        return "DevMetricsXRay()"
64
65    def data(self):
66        return []
67
68    def json_dump(self):
69        return {}

Developer Metrics for Hip X-Ray

Currently, this is a placeholder class.

def docs(self):
59    def docs(self):
60        return {}
def data(self):
65    def data(self):
66        return []
def json_dump(self):
68    def json_dump(self):
69        return {}
class LandmarksXRay:
 72class LandmarksXRay:
 73    """
 74    Landmarks for Hip X-Ray
 75
 76    :attr pel_l_o: The Outer Pelvis Landmark on the Left
 77    :attr pel_l_i: The Inner Pelvis Landmark on the Left
 78    :attr pel_r_o: The Outer Pelvis Landmark on the Right
 79    :attr pel_r_i: The Inner Pelvis Landmark on the Right
 80    :attr fem_l: The Femoral Landmark on the Left
 81    :attr fem_r: The Femoral Landmark on the Right
 82    """
 83
 84    def __init__(
 85        self,
 86        pel_l_o: Tuple[float, float] = None,
 87        pel_l_i: Tuple[float, float] = None,
 88        pel_r_o: Tuple[float, float] = None,
 89        pel_r_i: Tuple[float, float] = None,
 90        fem_l: Tuple[float, float] = None,
 91        fem_r: Tuple[float, float] = None,
 92    ):
 93        self.pel_l_o = pel_l_o
 94        self.pel_l_i = pel_l_i
 95        self.pel_r_o = pel_r_o
 96        self.pel_r_i = pel_r_i
 97
 98        self.fem_l = fem_l
 99        self.fem_r = fem_r
100
101    def __str__(self) -> str:
102        return (
103            f"Landmarks(pel_l_o={self.pel_l_o}, pel_l_i={self.pel_l_i}, "
104            f"pel_r_o={self.pel_r_o}, pel_r_i={self.pel_r_i}, "
105            f"fem_l={self.fem_l}, fem_r={self.fem_r})"
106        )
107
108    def __iter__(self) -> List[Tuple[float, float]]:
109        return iter(
110            [
111                self.pel_l_o,
112                self.pel_l_i,
113                self.pel_r_o,
114                self.pel_r_i,
115                self.fem_l,
116                self.fem_r,
117            ]
118        )
119
120    def items(self) -> Dict[str, Tuple]:
121        return {
122            "pel_l_o": self.pel_l_o,
123            "pel_l_i": self.pel_l_i,
124            "pel_r_o": self.pel_r_o,
125            "pel_r_i": self.pel_r_i,
126            "fem_l": self.fem_l,
127            "fem_r": self.fem_r,
128        }.items()
129
130    def __setitem__(self, key: str, value: Tuple[int, int]):
131        # use setattr to avoid infinite recursion
132        setattr(self, key, value)

Landmarks for Hip X-Ray

:attr pel_l_o: The Outer Pelvis Landmark on the Left :attr pel_l_i: The Inner Pelvis Landmark on the Left :attr pel_r_o: The Outer Pelvis Landmark on the Right :attr pel_r_i: The Inner Pelvis Landmark on the Right :attr fem_l: The Femoral Landmark on the Left :attr fem_r: The Femoral Landmark on the Right

LandmarksXRay( pel_l_o: Tuple[float, float] = None, pel_l_i: Tuple[float, float] = None, pel_r_o: Tuple[float, float] = None, pel_r_i: Tuple[float, float] = None, fem_l: Tuple[float, float] = None, fem_r: Tuple[float, float] = None)
84    def __init__(
85        self,
86        pel_l_o: Tuple[float, float] = None,
87        pel_l_i: Tuple[float, float] = None,
88        pel_r_o: Tuple[float, float] = None,
89        pel_r_i: Tuple[float, float] = None,
90        fem_l: Tuple[float, float] = None,
91        fem_r: Tuple[float, float] = None,
92    ):
93        self.pel_l_o = pel_l_o
94        self.pel_l_i = pel_l_i
95        self.pel_r_o = pel_r_o
96        self.pel_r_i = pel_r_i
97
98        self.fem_l = fem_l
99        self.fem_r = fem_r
pel_l_o
pel_l_i
pel_r_o
pel_r_i
fem_l
fem_r
def items(self) -> Dict[str, Tuple]:
120    def items(self) -> Dict[str, Tuple]:
121        return {
122            "pel_l_o": self.pel_l_o,
123            "pel_l_i": self.pel_l_i,
124            "pel_r_o": self.pel_r_o,
125            "pel_r_i": self.pel_r_i,
126            "fem_l": self.fem_l,
127            "fem_r": self.fem_r,
128        }.items()
class HipDataXray:
135class HipDataXray:
136    """
137    Hip Data for X-Ray
138
139    :attr metrics: The Metrics
140    :attr dev_metrics: The Developer Metrics
141    :attr landmarks: The Landmarks
142    :attr frame_no: The Frame Number
143    :attr recorded_error: The Recorded Error
144    """
145
146    def __init__(self):
147        self.metrics: List[Metric2D] = []
148        self.dev_metrics: DevMetricsXRay = []
149        self.landmarks: LandmarksXRay = None
150        self.frame_no: int = None
151        self.recorded_error: RecordedError = RecordedError()
152
153    def json_dump(self, config, dev_metrics: DevMetricsXRay) -> Dict[str, Any]:
154        return {
155            "metrics": [
156                {metric.name: metric.value} for metric in self.metrics
157            ],
158            "keyphrase": config.name,
159            "dev_metrics": dev_metrics.json_dump(),
160        }

Hip Data for X-Ray

:attr metrics: The Metrics :attr dev_metrics: The Developer Metrics :attr landmarks: The Landmarks :attr frame_no: The Frame Number :attr recorded_error: The Recorded Error

dev_metrics: DevMetricsXRay
landmarks: LandmarksXRay
frame_no: int
def json_dump( self, config, dev_metrics: DevMetricsXRay) -> Dict[str, Any]:
153    def json_dump(self, config, dev_metrics: DevMetricsXRay) -> Dict[str, Any]:
154        return {
155            "metrics": [
156                {metric.name: metric.value} for metric in self.metrics
157            ],
158            "keyphrase": config.name,
159            "dev_metrics": dev_metrics.json_dump(),
160        }