Skip to content

Commit

Permalink
lisa.trace: Add TraceBase.with_time_offset()
Browse files Browse the repository at this point in the history
FEATURE

Allow creating a TraceView that shifts all the timestamps by some
user-defined amount.
  • Loading branch information
douglas-raillard-arm committed Jan 8, 2024
1 parent b1003dd commit 4b3b14f
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions lisa/trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -2142,6 +2142,25 @@ def get_view(self, *args, **kwargs):
def _clear_cache(self):
pass

def with_time_offset(self, offset):
"""
Get a view on the trace with time shifted by ``offset``.
This can be convenient when trying to align mutliple traces coming from
repetition of the same experiment.
.. note:: Some analysis functions may not handle well negative
timestamps, so it might be a good idea to slice the trace to only
contain positive timestamps after this operation.
"""

def time_offset(event, df):
df = df.copy(deep=False)
df.index = df.index + offset
return df

return self.get_view(process_df=time_offset)

def __getitem__(self, window):
if not isinstance(window, slice):
raise TypeError("Cropping window must be an instance of slice")
Expand Down

0 comments on commit 4b3b14f

Please sign in to comment.