energy_fault_detector.data_splitting.data_gap_handler

class DataGapHandler(timestamps, freq)[source]

Bases: object

Handle 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. dtype datetime64[ns]) sorted in ascending order.

  • freq (timedelta64) – Target sampling frequency as a np.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 with gap_start > start_timestamp is 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.

is_in_gap(timestamp)[source]

Check whether a single timestamp lies within any detected data gap.

Parameters:

timestamp (datetime64) – Timestamp to check.

Return type:

bool

Returns:

True if the timestamp is inside at least one gap, 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 > 0 shifts to the right, * num < 0 shifts to the left, * num == 0 returns 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 arr containing the shifted values.