perda.utils.resampling#

perda.utils.resampling.apply_time_offset(di, offset_s, source_time_unit=Timescale.MS)[source]#

Shift signals in time by a fixed offset, but keeping the same timestamp list.

Shifts the values, not the timestamps. Create a new time series with the same values offset_s away, then re-interpolate the original timestamps onto this series.

Parameters:
  • di (DataInstance | list[DataInstance]) – Input signal(s). Lists are processed independently.

  • offset_s (float) – Time shift in seconds (positive shifts the signal later).

  • source_time_unit (Timescale, optional) – Timestamp unit of di.timestamp_np. Default is Timescale.MS.

Returns:

New DataInstance(s) with time-shifted value_np on the original timestamp grid.

Return type:

DataInstance | list[DataInstance]

Examples

>>> di_aligned = apply_time_offset(gps_speed_di, offset_s=-0.08)
>>> a, b = apply_time_offset([di_a, di_b], offset_s=0.05)
perda.utils.resampling.resample_to_freq(di, freq_hz, timestamp_divisor, method=ResampleMethod.LINEAR)[source]#

Resample a DataInstance onto a uniform frequency grid.

Parameters:
  • di (DataInstance) – Source DataInstance

  • freq_hz (float) – Target sampling frequency in Hz

  • timestamp_divisor (float) – Raw timestamp units per second (e.g. 1e6 for microseconds)

  • method (ResampleMethod, optional) – Interpolation method. Default is LINEAR.

Returns:

New DataInstance with values resampled onto a uniform timestamp grid

Return type:

DataInstance