shyft.dashboard.time_series.data_utility
Functions
|
This function find all indices to reduce the data of a numpy array. |
|
Backward compatibility ONLY: Convert shyft time series into nummpy array |
|
This routine is about 30..100x faster than corresponding python code. |
|
|
|
Returns the index of the array value closest to input_value in the given array. |
|
Merges a list of ts_vectors and converts them to numpy arrays |
Exceptions
- shyft.dashboard.time_series.data_utility.calculate_dead_band_indices(ts_input: ndarray, eps: float | None = 0.0005)[source]
This function find all indices to reduce the data of a numpy array. The algorithm is a basic compression / dead band filter with eps being the dead band. It is tested for arrays with integer values.
e.g.
values: 1 1 1 2 3 3 3 3 4 3 3 3 3 3 indices: 0 1 2 3 4 5 6 7 8 9 10 11 12 13
- would return:
- np.array([[0, 2],
[4, 7], [9, 13]])
[3, 8]
- Parameters:
ts_input (np.ndarray which should be analysed for compression) –
eps (deadband for integer set to a low value) –
- Returns:
- a numpy array with all indices which can compress one value – e.g [[2,4]] meaning all values from index 2 to 4 can be compressed under the given eps
- a list of single value indices – e.g [5,6,7] meaning index 5 ,6, 7 cannot be compressed and are unique under the given eps
- shyft.dashboard.time_series.data_utility.data_to_patch_values(data1: ndarray, data2: ndarray, non_nan_slices: Iterable[slice] | None = None) List[ndarray] [source]
- Parameters:
data1 –
data2 –
non_nan_slices –
- Returns:
- shyft.dashboard.time_series.data_utility.convert_ts_to_plot_vectors(*, ts: TimeSeries, cal: Calendar, crop_nan: bool | None = False, interpret_point_interpretation: bool | None = False, time_scale: float | None = 1000.0) Tuple[ndarray, ndarray] [source]
This routine is about 30..100x faster than corresponding python code.
- Parameters:
ts – time-series to extract plot data from
cal – containing time-zone offsets to apply to the time-points
crop_nan – crop trailing nans from the time-series
interpret_point_interpretation – interpret ts.point_interpretation, and if POINT_AVERAGE_VALUE make stair-step curve (2x+1 in size)
time_scale – bokeh uses time as numbers in ms scale, so default multiply by 1000.0
- Returns:
tuple with times,values, where times is tz-offset with cal,and then multiplied by time-scale, values
- shyft.dashboard.time_series.data_utility.merge_convert_ts_vectors_to_numpy(*, ts_vectors: List[Quantity[TsVector]], time_scale: float | None = 1.0, cal: Calendar | None = None) Tuple[ndarray, List[ndarray]] [source]
Merges a list of ts_vectors and converts them to numpy arrays
- Parameters:
ts_vectors (list of ts_vectors to merge and convert) –
time_scale (default 1.0, return time-vectors in seconds (utc)) –
cal (Calendar, default None, specify if time-stamps should be tz-adjusted) –
- Returns:
aligned_time (Array of time points for the entire span of ts_vectors)
data_list (List of data for each time series in all ts_vectors. Example: a = data_list[i][j] is the numpy array with) – data of the time series j and vector i. The numpy array is filles with nan where a(t) does not have data.
- shyft.dashboard.time_series.data_utility.find_nearest(array: ndarray, input_value: float | int, smaller_equal: bool | None = True)[source]
Returns the index of the array value closest to input_value in the given array. The closest value will be chosen either the first one smaller_equal to input value if smaller_equal is True or larger equal if smaller_equal is False
Find index of nearest value in array to input_value smaller_equal: bool to decide if search value <= input_value or value >= input_value
- shyft.dashboard.time_series.data_utility.convert_ts_to_numpy(ts: TimeSeries, crop_nan: bool | None = False, interpret_point_interpretation: bool | None = False) Tuple[ndarray, ndarray] [source]
Backward compatibility ONLY: Convert shyft time series into nummpy array
- Parameters:
ts – shyft TimeSeries containing values and time points
crop_nan – if True, strip away trailing nans and shorten result accordingly
interpret_point_interpretation – interpret ts.point_interpretation, and if POINT_AVERAGE_VALUE make stair-step curve (2x+1 in size)
- Returns:
tuple of [ndarray, np.array] containing [time, values]