Coverage for src/abm_initialization_collection/sample/get_sample_indices.py: 100%

18 statements  

« prev     ^ index     » next       coverage.py v7.1.0, created at 2024-09-25 19:25 +0000

1from abm_initialization_collection.coordinate.make_grid_coordinates import ( 

2 make_hex_grid_coordinates, 

3 make_rect_grid_coordinates, 

4) 

5 

6 

7def get_sample_indices( 

8 grid: str, 

9 bounds: tuple[int, int, int], 

10 resolution: float, 

11 scale_xy: float, 

12 scale_z: float, 

13) -> list: 

14 """ 

15 Get sample indices with given bounds for selected grid type. 

16 

17 Parameters 

18 ---------- 

19 grid : {'rect', 'hex'} 

20 Type of grid. 

21 bounds 

22 Sampling bounds in the x, y, and z directions. 

23 resolution 

24 Distance between samples (um). 

25 scale_xy 

26 Resolution scaling in x/y (um/pixel). 

27 scale_z 

28 Resolution scaling in z (um/pixel). 

29 

30 Returns 

31 ------- 

32 : 

33 List of sample indices. 

34 """ 

35 

36 if grid == "rect": 

37 return get_rect_sample_indices(bounds, resolution, scale_xy, scale_z) 

38 

39 if grid == "hex": 

40 return get_hex_sample_indices(bounds, resolution, scale_xy, scale_z) 

41 

42 message = f"invalid grid type {grid}" 

43 raise ValueError(message) 

44 

45 

46def get_rect_sample_indices( 

47 bounds: tuple[int, int, int], 

48 resolution: float, 

49 scale_xy: float, 

50 scale_z: float, 

51) -> list: 

52 """ 

53 Get list of (x, y, z) sample indices for rect grid. 

54 

55 Parameters 

56 ---------- 

57 bounds 

58 Sampling bounds in the x, y, and z directions. 

59 resolution 

60 Distance between samples (um). 

61 scale_xy 

62 Resolution scaling in x/y. 

63 scale_z 

64 Resolution scaling in z. 

65 

66 Returns 

67 ------- 

68 : 

69 List of sample indices. 

70 """ 

71 

72 increment_z = round(resolution / scale_z) 

73 increment_xy = round(resolution / scale_xy) 

74 

75 sample_coordinates = make_rect_grid_coordinates(bounds, increment_xy, increment_z) 

76 return [(round(x), round(y), z) for x, y, z in sample_coordinates] 

77 

78 

79def get_hex_sample_indices( 

80 bounds: tuple[int, int, int], 

81 resolution: float, 

82 scale_xy: float, 

83 scale_z: float, 

84) -> list: 

85 """ 

86 Get list of (x, y, z) sample indices for hex grid. 

87 

88 Sample indices are offset in sets of three z slices to form a 

89 face-centered cubic (FCC) packing. 

90 

91 Parameters 

92 ---------- 

93 bounds 

94 Sampling bounds in the x, y, and z directions. 

95 resolution 

96 Distance between samples (um). 

97 scale_xy 

98 Resolution scaling in x/y. 

99 scale_z 

100 Resolution scaling in z. 

101 

102 Returns 

103 ------- 

104 : 

105 List of sample indices. 

106 """ 

107 

108 increment_z = round(resolution / scale_z) 

109 increment_xy = round(resolution / scale_xy) 

110 

111 sample_coordinates = make_hex_grid_coordinates(bounds, increment_xy, increment_z) 

112 return [(round(x), round(y), z) for x, y, z in sample_coordinates]