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

19 statements  

« prev     ^ index     » next       coverage.py v7.1.0, created at 2024-07-26 20:12 +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 raise ValueError(f"invalid grid type {grid}") 

43 

44 

45def get_rect_sample_indices( 

46 bounds: tuple[int, int, int], 

47 resolution: float, 

48 scale_xy: float, 

49 scale_z: float, 

50) -> list: 

51 """ 

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

53 

54 Parameters 

55 ---------- 

56 bounds 

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

58 resolution 

59 Distance between samples (um). 

60 scale_xy 

61 Resolution scaling in x/y. 

62 scale_z 

63 Resolution scaling in z. 

64 

65 Returns 

66 ------- 

67 : 

68 List of sample indices. 

69 """ 

70 

71 increment_z = round(resolution / scale_z) 

72 increment_xy = round(resolution / scale_xy) 

73 

74 sample_coordinates = make_rect_grid_coordinates(bounds, increment_xy, increment_z) 

75 sample_indices = [(round(x), round(y), z) for x, y, z in sample_coordinates] 

76 

77 return sample_indices 

78 

79 

80def get_hex_sample_indices( 

81 bounds: tuple[int, int, int], 

82 resolution: float, 

83 scale_xy: float, 

84 scale_z: float, 

85) -> list: 

86 """ 

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

88 

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

90 face-centered cubic (FCC) packing. 

91 

92 Parameters 

93 ---------- 

94 bounds 

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

96 resolution 

97 Distance between samples (um). 

98 scale_xy 

99 Resolution scaling in x/y. 

100 scale_z 

101 Resolution scaling in z. 

102 

103 Returns 

104 ------- 

105 : 

106 List of sample indices. 

107 """ 

108 

109 increment_z = round(resolution / scale_z) 

110 increment_xy = round(resolution / scale_xy) 

111 

112 sample_coordinates = make_hex_grid_coordinates(bounds, increment_xy, increment_z) 

113 sample_indices = [(round(x), round(y), z) for x, y, z in sample_coordinates] 

114 

115 return sample_indices