def test_sample_closed_starts_and_ends_at_min_anomaly_if_in_range_and_no_max_given( min_nu, ecc ): result = sample_closed(min_nu, ecc) assert_quantity_allclose(result[0], min_nu, atol=1e-14 * u.rad) assert_quantity_allclose(result[-1], min_nu, atol=1e-14 * u.rad)
def sample(self, values=100, *, min_anomaly=None, max_anomaly=None): r"""Samples an orbit to some specified time values. .. versionadded:: 0.8.0 Parameters ---------- values : int Number of interval points (default to 100). min_anomaly, max_anomaly : ~astropy.units.Quantity, optional Anomaly limits to sample the orbit. For elliptic orbits the default will be :math:`E \in \left[0, 2 \pi \right]`, and for hyperbolic orbits it will be :math:`\nu \in \left[-\nu_c, \nu_c \right]`, where :math:`\nu_c` is either the current true anomaly or a value that corresponds to :math:`r = 3p`. Returns ------- positions: ~astropy.coordinates.CartesianRepresentation Array of x, y, z positions. Notes ----- When specifying a number of points, the initial and final position is present twice inside the result (first and last row). This is more useful for plotting. Examples -------- >>> from astropy import units as u >>> from poliastro.examples import iss >>> iss.sample() # doctest: +ELLIPSIS <CartesianRepresentation (x, y, z) in km ... >>> iss.sample(10) # doctest: +ELLIPSIS <CartesianRepresentation (x, y, z) in km ... """ if self.ecc < 1: nu_values = sample_closed( min_anomaly if min_anomaly is not None else self.nu, self.ecc, max_anomaly, values, ) else: nu_values = self._sample_open(values, min_anomaly, max_anomaly) n = nu_values.shape[0] rr, vv = coe2rv_many( np.tile(self.attractor.k, n), np.tile(self.p, n), np.tile(self.ecc, n), np.tile(self.inc, n), np.tile(self.raan, n), np.tile(self.argp, n), nu_values, ) cartesian = CartesianRepresentation( rr, differentials=CartesianDifferential(vv, xyz_axis=1), xyz_axis=1 ) return cartesian
def test_sample_closed_starts_at_min_anomaly_if_in_range(min_nu, ecc, max_nu): result = sample_closed(min_nu, ecc, max_nu) assert_quantity_allclose(result[0], min_nu, atol=1e-15 * u.rad)
def test_sample_closed_is_always_between_minus_pi_and_pi(min_nu, ecc, max_nu): result = sample_closed(min_nu, ecc, max_nu) assert ((-np.pi * u.rad <= result) & (result <= np.pi * u.rad)).all()