Coverage for src/recon3d/constants.py: 100%

19 statements  

« prev     ^ index     » next       coverage.py v7.8.0, created at 2025-04-02 00:06 +0000

1""" 

2This module stores constant values in a single location for recon3d. 

3 

4This module defines various constants and conversion factors that are used  

5throughout the recon3d application. It provides a centralized location for  

6these constants, making the code more maintainable and easier to understand. 

7 

8Classes 

9------- 

10Constants 

11 Creates all constants used in this module. 

12 

13Conversions 

14 Unit conversions. 

15 

16SkimageConnectivity 

17 Connectivity level to be used with skimage.measure.label function in 3D. 

18 

19CC3DConnectivity 

20 Connectivity level to be used with cc3d.connected_components function in 3D. 

21 

22Attributes 

23---------- 

24MODULE_NAME : str 

25 The name of the module. 

26""" 

27 

28from typing import NamedTuple, Final 

29import numpy as np 

30 

31MODULE_NAME: Final[str] = "recon3d" 

32 

33 

34class Constants(NamedTuple): 

35 """ 

36 Creates all constants used in this module. 

37 

38 This class defines a set of constants that are used throughout the module. 

39 It utilizes the `NamedTuple` from the `typing` module to create immutable 

40 constants. 

41 

42 Attributes 

43 ---------- 

44 YML_SCHEMA_VERSION : float 

45 The version of the YAML schema. 

46 module_short_name : str 

47 The short name of the module. 

48 module_prompt : str 

49 The prompt string for the module. 

50 KNUD_THOMSEN_FACTOR : float 

51 The Knud Thomsen factor for the surface area of a scalene ellipsoid. 

52 """ 

53 

54 YML_SCHEMA_VERSION: float = 1.0 

55 module_short_name: str = MODULE_NAME 

56 module_prompt: str = MODULE_NAME + ">" 

57 KNUD_THOMSEN_FACTOR: float = 1.6075 # for surface area of scalene ellipsoid 

58 

59 # def __init__(self) -> None: 

60 # self.YML_SCHEMA_VERSION = 1.0 # Good 

61 

62 

63class Conversions(NamedTuple): 

64 """ 

65 Unit conversions. 

66 

67 This class defines constants for converting between radians and degrees. 

68 It utilizes the `NamedTuple` from the `typing` module to create immutable 

69 constants. 

70 

71 Attributes 

72 ---------- 

73 RAD_TO_DEG : float 

74 Conversion factor from radians to degrees. 

75 DEG_TO_RAD : float 

76 Conversion factor from degrees to radians. 

77 """ 

78 

79 RAD_TO_DEG: float = 180 / np.pi 

80 DEG_TO_RAD: float = 1 / RAD_TO_DEG 

81 

82 

83class SkimageConnectivity(NamedTuple): 

84 """ 

85 Connectivity level to be used with skimage.measure.label function in 3D. 

86 

87 This class defines constants for different levels of connectivity that can 

88 be used with the `skimage.measure.label` function in 3D image processing. 

89 It utilizes the `NamedTuple` from the `typing` module to create immutable 

90 constants. 

91 

92 Attributes 

93 ---------- 

94 FACE_NEIGHBORS : int 

95 Connectivity level with 6 face neighbors. 

96 FACE_EDGE_NEIGHBORS : int 

97 Connectivity level with 6 face neighbors and 12 edge neighbors. 

98 FACE_EDGE_VERTEX_NEIGHBORS : int 

99 Connectivity level with 6 face neighbors, 12 edge neighbors, and 8 vertex neighbors. 

100 """ 

101 

102 FACE_NEIGHBORS = 1 

103 FACE_EDGE_NEIGHBORS = 2 

104 FACE_EDGE_VERTEX_NEIGHBORS = 3 

105 

106 

107class CC3DConnectivity(NamedTuple): 

108 """ 

109 Connectivity level to be used with cc3d.connect_components function in 3D. 

110 

111 This class defines constants for different levels of connectivity that can 

112 be used with the `cc3d.connected_components` function. 

113 It utilizes the `NamedTuple` from the `typing` module to create immutable 

114 constants. 

115 

116 Attributes 

117 ---------- 

118 FACE_NEIGHBORS : int 

119 Connectivity level with 6 face neighbors. 

120 FACE_EDGE_NEIGHBORS : int 

121 Connectivity level with 6 face neighbors and 12 edge neighbors. 

122 FACE_EDGE_VERTEX_NEIGHBORS : int 

123 Connectivity level with 6 face neighbors, 12 edge neighbors, and 8 vertex neighbors. 

124 """ 

125 

126 FACE_NEIGHBORS = 6 

127 FACE_EDGE_NEIGHBORS = 18 

128 FACE_EDGE_VERTEX_NEIGHBORS = 26