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

12 statements  

« prev     ^ index     » next       coverage.py v7.1.0, created at 2024-07-26 20:12 +0000

1from typing import Optional 

2 

3import pandas as pd 

4 

5 

6def scale_sample_coordinates( 

7 samples: pd.DataFrame, 

8 coordinate_type: Optional[str], 

9 resolution: float, 

10 scale_xy: float, 

11 scale_z: float, 

12) -> pd.DataFrame: 

13 """ 

14 Scales sampled coordinates using to given coordinate type. 

15 

16 The "absolute" coordinate type scales sample index coordinate into absolute 

17 positions (in um). 

18 The "step" coordinate type scales sample index coordinates by step size. 

19 Otherwise, samples index coordinates are not modified. 

20 

21 Parameters 

22 ---------- 

23 samples 

24 Sample cell ids and coordinates. 

25 coordinate_type : {'absolute', 'step', None} 

26 The coordinate scaling type. 

27 resolution 

28 Distance between samples (um). 

29 scale_xy 

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

31 scale_z 

32 Resolution scaling in z (um/pixel). 

33 

34 Returns 

35 ------- 

36 : 

37 Sample cell ids and scaled coordinates. 

38 """ 

39 

40 if coordinate_type == "absolute": 

41 samples["x"] = samples["x"] * scale_xy 

42 samples["y"] = samples["y"] * scale_xy 

43 samples["z"] = samples["z"] * scale_z 

44 elif coordinate_type == "step": 

45 samples["x"] = (samples["x"] / round(resolution / scale_xy)).astype("int32") 

46 samples["y"] = (samples["y"] / round(resolution / scale_xy)).astype("int32") 

47 samples["z"] = (samples["z"] / round(resolution / scale_z)).astype("int32") 

48 

49 return samples