energy_fault_detector.data_splitting.data_gap_handler
- class DataGapHandler(timestamps, freq)[source]
Bases:
objectHandle data gaps in a time series given a target sampling frequency.
Data gaps are identified wherever the difference between consecutive timestamps exceeds the target frequency. The handler then exposes convenience methods to check whether a timestamp or interval lies within a gap and to retrieve the next gap after a given timestamp.
- freq
Target frequency as a
np.timedelta64.
- data_gaps
Optional array of shape (n_gaps, 2) with (gap_start, gap_end) timestamps, or None if no gaps.
Initialize the DataGapHandler.
- Parameters:
timestamps (
ndarray) – 1D NumPy array of time stamps (e.g. dtypedatetime64[ns]) sorted in ascending order.freq (
timedelta64) – Target sampling frequency as anp.timedelta64.
- get_next_gap_after(start_timestamp)[source]
Get the next data gap following a given timestamp.
- Parameters:
start_timestamp (
datetime64) – Reference timestamp. The first gap withgap_start > start_timestampis returned.- Return type:
Optional[Tuple[datetime64,datetime64]]- Returns:
A tuple
(gap_start, gap_end)if a next gap exists, otherwise None.
- has_data_gaps(start, end)[source]
Check whether any data gap overlaps with a given time interval.
- Parameters:
start (
datetime64) – Start of the interval (inclusive).end (
datetime64) – End of the interval (inclusive).
- Return type:
bool- Returns:
True if at least one data gap overlaps the interval, False otherwise.
- shift_array(arr, num, fill_value=None)[source]
Shift a NumPy array by a given number of positions. Elements shifted out of the array are replaced with
fill_value.- Parameters:
arr (
ndarray) – Input NumPy array to shift.num (
int) – Number of positions to shift: *num > 0shifts to the right, *num < 0shifts to the left, *num == 0returns the array unchanged.fill_value – Value used to fill the newly created positions. Defaults to None.
- Return type:
ndarray- Returns:
A new NumPy array with the same shape as
arrcontaining the shifted values.