Coverage for src/signal_edges/signal/edges/definitions.py: 100%

31 statements  

« prev     ^ index     » next       coverage.py v7.4.3, created at 2024-04-21 11:16 +0000

1"""Definitions for signal edges.""" 

2 

3from enum import IntEnum, auto 

4from typing import TypedDict 

5 

6import numpy as np 

7import numpy.typing as npt 

8 

9from ..signal import Signal 

10from ..state_levels import StateLevelsMixin 

11 

12 

13class IntPointPolicy(IntEnum): 

14 """Policies that dictate how to calculate the intermediate point of edges. 

15 

16 By default, the intermediate point of any edge, both normal or runt edge, is the point within the edge 

17 the nearest to the intermediate value in the :class:`.StateLevels` provided by the user. 

18 

19 This behaviour can be modified by using intermediate point policies.""" 

20 

21 #: Use the data point in the edge, including ``begin`` and ``end``, that is nearest to the intermediate level. 

22 POLICY_0 = auto() 

23 #: Force use of ``begin`` for falling edges and ``end`` for rising edges. 

24 POLICY_1 = auto() 

25 #: Force use of ``end`` for falling edges and ``begin`` for rising edges. 

26 POLICY_2 = auto() 

27 

28 

29class Type(IntEnum): 

30 """Type of an edge. 

31 

32 The :class:`.StateLevels` provided for calculation of edges define the following logical areas for edges: 

33 

34 - The `high area`, ``high_a``, for values that satisfy `value > high`. 

35 - The `intermediate high area`, ``int_high_a``, for values that satisfy `intermediate < value <= high`. 

36 - The `intermediate low area`, ``int_low_a``, for values that satisfy `low < value <= intermediate`. 

37 - The `low area`, ``low_a``, for values that satisfy `value < low`. 

38 - The `runt low area`, ``runt_low_a``, for values that satisfy `low <= value <= high_runt`. 

39 - The `runt high area`, ``runt_high_a``, for values that satisfy `runt_low <= value <= high`. 

40 

41 The runt areas and the intermediate areas overlap between each other, and the high and low areas do 

42 not overlap with any other area. The type of an edge is defined by how it transitions between these 

43 areas. 

44 

45 Runt edges can only be found in pairs, since until a ``high`` or ``low`` logical level has been reached 

46 it is not possible to determine whether edges are truly runt edges or normal edges.""" 

47 

48 #: A normal falling edge, from ``high_a`` to ``low_a``. 

49 FALLING = auto() 

50 #: A runt falling edge, from ``high_a`` to ``runt_low_a`` or from ``runt_high_a`` to ``low_a``. 

51 FALLING_RUNT = auto() 

52 #: A normal rising edge, from ``low_a`` to ``high_a``. 

53 RISING = auto() 

54 #: A runt rising edge, from ``low_a`` to ``runt_high_a`` or from ``runt_low_a`` to ``high_a``. 

55 RISING_RUNT = auto() 

56 

57 

58class Edge(TypedDict): 

59 """Definition of an edge in a signal. 

60 

61 :param edge_type: The type of edge. 

62 :param ibegin: Index of the beginning of the edge in the signal. 

63 :param hbegin: Value of the horizontal axis of the signal at the beginning of the edge. 

64 :param vbegin: Value of the vertical axis of the signal at the beginning of the edge. 

65 :param iintermediate: Index of the intermediate point of the edge in the signal. 

66 :param hintermediate: Value of the horizontal axis of the signal at the intermediate of the edge. 

67 :param vintermediate: Value of the vertical axis of the signal at the intermediate of the edge. 

68 :param iend: Index of the end of the edge in the signal. 

69 :param hend: Value of the horizontal axis of the signal at the end of the edge. 

70 :param vend: Value of the vertical axis of the signal at the end of the edge.""" 

71 

72 # pylint: disable=too-few-public-methods 

73 

74 edge_type: Type 

75 ibegin: int 

76 hbegin: float 

77 vbegin: float 

78 iintermediate: int 

79 hintermediate: float 

80 vintermediate: float 

81 iend: int 

82 hend: float 

83 vend: float 

84 

85 

86class AreaSignal(StateLevelsMixin, Signal): 

87 """Definition of a signal used to calculate state levels in a delimited area of the original signal.""" 

88 

89 ## Private API ##################################################################################################### 

90 

91 ## Protected API ################################################################################################### 

92 

93 ## Public API ###################################################################################################### 

94 def load(self, hvalues: npt.NDArray[np.float_], vvalues: npt.NDArray[np.float_]) -> "AreaSignal": 

95 """Loads the values specified into the signal. 

96 

97 :param hvalues: The values for the horizontal axis. 

98 :param vvalues: The values for the vertical axis. 

99 :return: Instance of the class.""" 

100 self._hv = hvalues 

101 self._vv = vvalues 

102 

103 return self