@@ -29,8 +29,9 @@ def __init__(self, *, user_time=None, user_value=None):
2929 def get_value (
3030 self , time : Optional [np .ndarray ] = None
3131 ) -> tuple [np .ndarray , np .ndarray ]:
32- """Generate time and values based on the tendency. If a time array is provided,
33- the values will be linearly interpolated between the piecewise linear points.
32+ """Get the tendency values at the provided time array. If a time array is
33+ provided, the values will be linearly interpolated between the piecewise linear
34+ points.
3435
3536 Args:
3637 time: The time array on which to generate points.
@@ -39,14 +40,14 @@ def get_value(
3940 Tuple containing the time and its tendency values.
4041 """
4142 if time is None :
42- time = self .time
43+ return self .time , self . value
4344
4445 self ._validate_requested_time (time )
4546 interpolated_values = np .interp (time , self .time , self .value )
4647 return time , interpolated_values
4748
4849 def get_derivative (self , time : np .ndarray ) -> np .ndarray :
49- """Get the derivative values on the provided time array.
50+ """Get the values of the derivatives at the provided time array.
5051
5152 Args:
5253 time: The time array on which to generate points.
@@ -55,17 +56,14 @@ def get_derivative(self, time: np.ndarray) -> np.ndarray:
5556 numpy array containing the derivatives
5657 """
5758 self ._validate_requested_time (time )
58-
5959 derivatives = np .zeros_like (time )
6060
6161 for i , t in enumerate (time ):
62- # Find the segment for this particular time
6362 if t == self .time [- 1 ]:
6463 derivatives [i ] = (self .value [- 1 ] - self .value [- 2 ]) / (
6564 self .time [- 1 ] - self .time [- 2 ]
6665 )
6766 else :
68- # Find the two indices surrounding the time point (t)
6967 index = np .searchsorted (self .time , t )
7068 dv = self .value [index + 1 ] - self .value [index ]
7169 dt = self .time [index + 1 ] - self .time [index ]
@@ -74,6 +72,11 @@ def get_derivative(self, time: np.ndarray) -> np.ndarray:
7472 return derivatives
7573
7674 def _validate_requested_time (self , time ):
75+ """Check if the requested time data falls within the piecewise tendency.
76+
77+ Args:
78+ time: The time array on which to generate points.
79+ """
7780 if np .any (time < self .time [0 ]) or np .any (time > self .time [- 1 ]):
7881 raise ValueError (
7982 f"The provided time array contains values outside the valid range "
0 commit comments