import numpy as np def fix_timestamps(tstmp, offsets=None): tstmp = tstmp.astype(np.int64) rollover, = np.where(np.diff(tstmp) < 0) if offsets is None: offsets = tstmp[rollover] for j, i in enumerate(rollover): tstmp[(i + 1):] = tstmp[(i + 1):] + offsets[j] # offsets[j:] += tstmp[i] cum_offsets = np.cumsum(offsets) return tstmp, offsets, cum_offsets