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-09-25 19:25 +0000

1from __future__ import annotations 

2 

3from typing import TYPE_CHECKING 

4 

5if TYPE_CHECKING: 

6 import pandas as pd 

7 

8 

9def scale_sample_coordinates( 

10 samples: pd.DataFrame, 

11 coordinate_type: str | None, 

12 resolution: float, 

13 scale_xy: float, 

14 scale_z: float, 

15) -> pd.DataFrame: 

16 """ 

17 Scale sampled coordinates using to given coordinate type. 

18 

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

20 positions (in um). 

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

22 Otherwise, samples index coordinates are not modified. 

23 

24 Parameters 

25 ---------- 

26 samples 

27 Sample cell ids and coordinates. 

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

29 The coordinate scaling type. 

30 resolution 

31 Distance between samples (um). 

32 scale_xy 

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

34 scale_z 

35 Resolution scaling in z (um/pixel). 

36 

37 Returns 

38 ------- 

39 : 

40 Sample cell ids and scaled coordinates. 

41 """ 

42 

43 if coordinate_type == "absolute": 

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

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

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

47 elif coordinate_type == "step": 

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

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

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

51 

52 return samples