Skip to content
This repository has been archived by the owner on Oct 14, 2023. It is now read-only.

Commit

Permalink
Restore all Orbit.sample use cases, fix #328
Browse files Browse the repository at this point in the history
  • Loading branch information
astrojuanlu committed Sep 19, 2018
1 parent fb99755 commit 73a3290
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/poliastro/twobody/orbit.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,17 +472,24 @@ def sample(self, values=None, method=mean_motion):
elif hasattr(values, "unit") and values.unit in ('rad', 'deg'):
values = self._generate_time_values(values)

elif isinstance(values, time.Time):
values = values - self.epoch

elif isinstance(values, list):
# A list of Times is assumed
values = [(value - self.epoch).sec for value in values] * u.s

return self._sample(values, method)

def _sample(self, time_values, method=mean_motion):
positions = method(self, (time_values - self.epoch).to(u.s).value)
positions = method(self, time_values.to(u.s).value)

data = CartesianRepresentation(positions[0] * u.km, xyz_axis=1)

# If the frame supports obstime, set the time values
kwargs = {}
if 'obstime' in self.frame.frame_attributes:
kwargs['obstime'] = time_values
kwargs['obstime'] = self.epoch + time_values
else:
warn("Frame {} does not support 'obstime', time values were not returned".format(self.frame.__class__))

Expand All @@ -497,7 +504,7 @@ def _generate_time_values(self, nu_vals):
ecc = self.ecc.value
nu = self.nu.to(u.rad).value
M_vals = [nu_to_M_fast(nu_val, ecc) - nu_to_M_fast(nu, ecc) for nu_val in nu_vals.to(u.rad).value] * u.rad
time_values = self.epoch + (M_vals / self.n).decompose()
time_values = (M_vals / self.n).decompose()
return time_values

def apply_maneuver(self, maneuver, intermediate=False):
Expand Down

0 comments on commit 73a3290

Please sign in to comment.