optional start,end in times_in_range

This commit is contained in:
Philip Eisenlohr 2022-04-21 15:56:17 -04:00
parent 730bd8ae34
commit b5f9d524d7
1 changed files with 9 additions and 11 deletions

View File

@ -263,28 +263,26 @@ class Result:
self.incs[-1] if end is None else end)) self.incs[-1] if end is None else end))
return [i for i in self.incs if s <= i <= e] return [i for i in self.incs if s <= i <= e]
def times_in_range(self,start,end): def times_in_range(self,start=None,end=None):
""" """
Get all increments within a given time range. Get all increments within a given time range.
Parameters Parameters
---------- ----------
start : float start : float, optional
Time of start increment. Time of start increment. Defaults to first.
end : float end : float, optional
Time of end increment. Time of end increment. Defaults to last.
Returns Returns
------- -------
times : list of float times : list of float
Simulation time of all increments within the given bounds. Time of each increment within the given bounds.
""" """
selected = [] s,e = (self.times[ 0] if start is None else start,
for i,time in enumerate(self.times): self.times[-1] if end is None else end)
if start <= time <= end: return [t for t in self.times if s <= t <= e]
selected.append(self.times[i])
return selected
def view(self,*, def view(self,*,