Coverage for physped/core/digitizers.py: 100%

8 statements  

« prev     ^ index     » next       coverage.py v7.6.12, created at 2025-04-01 09:28 +0000

1import numpy as np 

2 

3 

4def digitize_coordinates_to_lattice( 

5 coordinates: np.ndarray[float], lattice_bins: np.ndarray[float] 

6) -> np.ndarray[np.int_]: 

7 """Digitizes the given coordinates to the specified lattice bins. 

8 

9 Boundary conditions: 

10 - Coordinates outside the lattice return -1. 

11 Note: it is not possible to return nan because the output is an 

12 array of integers. 

13 

14 Args: 

15 coordinates: The coordinates in one dimension to be digitized. 

16 lattice_bins: The bin edges in one dimension defining the 

17 lattice cells. 

18 

19 Returns: 

20 The array with integer lattice indices associated with the 

21 coordinates. 

22 """ 

23 indices = np.digitize(coordinates, lattice_bins) - 1 

24 smallest_index = 0 

25 biggest_index = len(lattice_bins) - 2 

26 indices = np.where(indices < smallest_index, -1, indices) 

27 indices = np.where(indices > biggest_index, -1, indices) 

28 return indices