Skip to content

Commit

Permalink
Optimize resampling
Browse files Browse the repository at this point in the history
  • Loading branch information
bradsease committed Nov 26, 2023
1 parent 87d4e31 commit 96b3766
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions oem/components/segment.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from lxml.etree import SubElement
from itertools import chain

from oem import CURRENT_VERSION
from oem.base import ConstraintSpecification, Constraint
Expand Down Expand Up @@ -244,22 +245,21 @@ def resample(self, step_size, in_place=False):
EphemerisSegment: Resampled EphemerisSegment. Output is
an indepdent instance if in_place is True.
"""
# TODO: Optimize this
if not self._interpolator:
self._init_interpolator()

epochs = time_range(
self.useable_start_time, self.useable_stop_time, step_size
)

if in_place:
if self.has_accel:
states = (
(
state.epoch,
*state.position,
*state.velocity,
*state.acceleration
) for state in self.steps(step_size)
)
else:
states = (
(state.epoch, *state.position, *state.velocity)
for state in self.steps(step_size)
)
states = (
(
epoch, *chain.from_iterable(
self._interpolator(epoch)[:2 + self.has_accel]
)
) for epoch in epochs
)
self._state_data = tuple(zip(*states))
else:
segment = self.copy().resample(step_size, in_place=True)
Expand Down

0 comments on commit 96b3766

Please sign in to comment.