From b952ff9a98ed28ff864f9d6b46332fd63f23d69e Mon Sep 17 00:00:00 2001 From: Dario Izzo Date: Tue, 7 Jan 2025 13:30:19 +0100 Subject: [PATCH] planet getters exposed as attributes too --- pykep/core.cpp | 16 ++++++++++++++++ pykep/trajopt/_mga.py | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/pykep/core.cpp b/pykep/core.cpp index 5843087..053bb6b 100644 --- a/pykep/core.cpp +++ b/pykep/core.cpp @@ -246,6 +246,22 @@ PYBIND11_MODULE(core, m) // NOLINT PYKEP3_EXPOSE_PLANET_GETTER(radius); PYKEP3_EXPOSE_PLANET_GETTER(safe_radius); +#undef PYKEP3_EXPOSE_PLANET_GETTER + +// We also support the various quantities as attributes for compatibility with pykep 2 +// and because its nicer syntax to have them as attributes. +#define PYKEP3_EXPOSE_PLANET_ATTRIBUTE(name) \ + planet_class.def_property_readonly( \ + #name, [](const kep3::planet &pl) { return pl.get_##name(); }, \ + pykep::planet_get_##name##_docstring().c_str()); + + PYKEP3_EXPOSE_PLANET_ATTRIBUTE(name); + PYKEP3_EXPOSE_PLANET_ATTRIBUTE(extra_info); + PYKEP3_EXPOSE_PLANET_ATTRIBUTE(mu_central_body); + PYKEP3_EXPOSE_PLANET_ATTRIBUTE(mu_self); + PYKEP3_EXPOSE_PLANET_ATTRIBUTE(radius); + PYKEP3_EXPOSE_PLANET_ATTRIBUTE(safe_radius); + #undef PYKEP3_EXPOSE_PLANET_GETTER planet_class.def( diff --git a/pykep/trajopt/_mga.py b/pykep/trajopt/_mga.py index f5ec384..7db2c2b 100644 --- a/pykep/trajopt/_mga.py +++ b/pykep/trajopt/_mga.py @@ -70,7 +70,7 @@ def __init__( *t0* (:class:`list` [:class:`float` or :class:`~pykep.epoch`]): lower and upper bounds for the launch epoch. When floats are used MJD2000 is assumed. - *tof* (``list`` or ``float``): defines the bounds on the time of flight. If *tof_encoding* is 'direct', this contains a list + *tof* (:class:`list` or :class:`float`): defines the bounds on the time of flight. If *tof_encoding* is 'direct', this contains a list of 2D lists defining the upper and lower bounds on each leg. If *tof_encoding* is 'alpha', this contains a 2D list with the lower and upper bounds on the total time-of-flight. If *tof_encoding* is 'eta' tof is a float defining an upper bound for the time-of-flight.