Coverage for local_installation_linux/mumott/core/probed_coordinates.py: 100%

19 statements  

« prev     ^ index     » next       coverage.py v7.3.2, created at 2024-08-11 23:08 +0000

1from dataclasses import dataclass, field 

2import numpy as np 

3 

4from .hashing import list_to_hash 

5 

6 

7def _default_vector(): 

8 """ Factory function needed by dataclass """ 

9 return np.array([1., 0., 0.]).reshape(1, 1, 1, 3) 

10 

11 

12def _default_offset_vector(): 

13 """ Factory function needed by dataclass """ 

14 return np.array([0., 0., 0.]).reshape(1, 1, 1, 3) 

15 

16 

17@dataclass 

18class ProbedCoordinates: 

19 """ A small container class for probed coordinates for the 

20 :class:` BasisSet <mumott.methods.BasisSet>`. 

21 

22 Parameters 

23 ---------- 

24 vector : NDArray[float] 

25 The coordinates on the sphere probed at each detector segment by the 

26 experimental method. Should be structured ``(N, M, I, 3)`` where ``N`` 

27 is the number of projections, ``M`` is the number of detector segments, 

28 ``I`` is the number of points on the detector to be integrated over, 

29 and the last index gives the ``(x, y, z)`` components of the coordinates. 

30 ``I`` can be as small as ``1``, but the array still needs to be structured 

31 in this way explicitly. 

32 By default, the value will be ``np.array([1., 0., 0.]).reshape(1, 1, 1, 3)``. 

33 

34 great_circle_offset : np.ndarray[float] 

35 The vector which offsets the probed coordinate vectors from lying on a 

36 great circle. Must have the same number of dimensions as :attr:`vector`, and be 

37 broadcastable (dimensions where the value would be repeated may be ``1``). 

38 This vector is used when interpolating coordinates that lie on a small circle. 

39 

40 """ 

41 vector: np.ndarray[float] = field(default_factory=_default_vector) 

42 great_circle_offset: np.ndarray[float] = field(default_factory=_default_offset_vector) 

43 

44 def __hash__(self) -> int: 

45 return int(list_to_hash([self.vector, self.great_circle_offset]), 16) 

46 

47 @property 

48 def to_spherical(self) -> tuple: 

49 """ Returns spherical coordinates of :attr:`vector`, in the order 

50 ``(radius, polar angle, azimuthal angle)``. """ 

51 r = np.linalg.norm(self.vector, axis=-1) 

52 theta = np.arccos(self.vector[..., 2] / r) 

53 phi = np.arctan2(self.vector[..., 1], self.vector[..., 0]) 

54 return (r, theta, phi)