Skip to content

Commit

Permalink
Merge pull request #137 from zackdrescher/maskSample
Browse files Browse the repository at this point in the history
Added masking capability to TimeSeries.sample()
  • Loading branch information
stringertheory authored Feb 5, 2024
2 parents a568b17 + e7e2b2a commit a9b2768
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions traces/timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,16 +425,23 @@ def sample(
"""Sampling at regular time periods."""
start, end, mask = self._check_boundaries(start, end)

sampling_period = self._check_regularization(
start, end, sampling_period
)
sampling_period = \
self._check_regularization(start, end, sampling_period)

if isinstance(mask, TimeSeries):
mask = mask.to_domain()

distribution_mask = Domain([start, end])
if mask:
distribution_mask &= mask

result = []
current_time = start
while current_time <= end:
value = self.get(current_time, interpolate=interpolate)
result.append((current_time, value))
current_time += sampling_period
for start, end in distribution_mask.intervals():
current_time = start
while current_time <= end:
value = self.get(current_time, interpolate=interpolate)
result.append((current_time, value))
current_time += sampling_period
return result

def moving_average( # noqa: C901
Expand Down

0 comments on commit a9b2768

Please sign in to comment.