Skip to content

Commit 96b3766

Browse files
committed
Optimize resampling
1 parent 87d4e31 commit 96b3766

1 file changed

Lines changed: 15 additions & 15 deletions

File tree

oem/components/segment.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from lxml.etree import SubElement
2+
from itertools import chain
23

34
from oem import CURRENT_VERSION
45
from oem.base import ConstraintSpecification, Constraint
@@ -244,22 +245,21 @@ def resample(self, step_size, in_place=False):
244245
EphemerisSegment: Resampled EphemerisSegment. Output is
245246
an indepdent instance if in_place is True.
246247
"""
247-
# TODO: Optimize this
248+
if not self._interpolator:
249+
self._init_interpolator()
250+
251+
epochs = time_range(
252+
self.useable_start_time, self.useable_stop_time, step_size
253+
)
254+
248255
if in_place:
249-
if self.has_accel:
250-
states = (
251-
(
252-
state.epoch,
253-
*state.position,
254-
*state.velocity,
255-
*state.acceleration
256-
) for state in self.steps(step_size)
257-
)
258-
else:
259-
states = (
260-
(state.epoch, *state.position, *state.velocity)
261-
for state in self.steps(step_size)
262-
)
256+
states = (
257+
(
258+
epoch, *chain.from_iterable(
259+
self._interpolator(epoch)[:2 + self.has_accel]
260+
)
261+
) for epoch in epochs
262+
)
263263
self._state_data = tuple(zip(*states))
264264
else:
265265
segment = self.copy().resample(step_size, in_place=True)

0 commit comments

Comments
 (0)