Skip to content

Commit

Permalink
Merge pull request #50 from darioizzo/mit
Browse files Browse the repository at this point in the history
Mit
  • Loading branch information
darioizzo authored Feb 3, 2025
2 parents 80b074d + c878bd1 commit f9500cf
Show file tree
Hide file tree
Showing 17 changed files with 951 additions and 105 deletions.
3 changes: 2 additions & 1 deletion doc/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
API
#######

pykep API is designed to maximize its usability. Let us know what you think about it!
pykep API is striving to maximize its usability. Let us know what you think about it!

.. toctree::
:maxdepth: 2
Expand All @@ -23,4 +23,5 @@ pykep API is designed to maximize its usability. Let us know what you think abou
trajopt
gym
plot
utils

33 changes: 1 addition & 32 deletions doc/notebooks/primer_vector.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"In this notebook we revisit the primer vector theory from Lawden from the lens of first order variations. We then construct manually, for a specific test case, the state transition matrices needed to call {func}`pykep.trajopt.primer_vector` and show\n",
"its use. The same plot can also be obtained, without having to go through the math intensive developments, using the {func}`pykep.trajopt.pl2pl_N_impulses.plot_primer_vector` method of the Multiple Impulse Transfer UDP `pykep.trajopt.pl2pl_N_impulses`\n",
"\n",
"Classically, the result of the primer vector is derived using Pontryagin maximum principle, here we present an original derivation building on the work from Bauregard et al. {cite:p}`beauregard`, which allows also to extend the primer vector to new, previously untreated, cases (see the notebook [A primer vector surrogate](<./primer_vector_surrogate.ipynb>)).\n",
"Classically, the result of the primer vector is derived using Pontryagin maximum principle, here we present an original derivation building on the work from Bauregard, Acciarini and Izzo {cite:p}`beauregard`, which allows also to extend the primer vector to new, previously untreated, cases (see the notebook [A primer vector surrogate](<./surrogate_primer_vector.ipynb>)).\n",
"\n",
":::{note}\n",
" The developments are here shown in details as they can be extended to more generic cases that use different dynamics and number of impulses. The user must in that case provide the state ransition matrices and DVs on a time grid as constructed below.\n",
Expand Down Expand Up @@ -275,37 +275,6 @@
"#posvels[-1][1] = [a + b for a, b in zip(posvels[-1][1], DV3)]\n"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[ 1.12807793e+01, 1.80447033e+01, 6.65907703e-03,\n",
" -9.08505426e+07, 5.95064147e+07, 1.92133860e+06],\n",
" [-1.28990875e+00, -1.31576055e+00, -3.66387114e-02,\n",
" 1.15887081e+07, -5.09339048e+06, 2.07784246e+05],\n",
" [-3.36261520e-01, -3.88616536e-01, 6.55461044e-01,\n",
" 2.34553875e+06, -9.85626328e+05, 1.43519303e+06],\n",
" [ 3.35679528e-07, 8.01570626e-07, -1.32855560e-08,\n",
" -2.43465805e+00, 2.52926261e+00, 2.17349840e-01],\n",
" [ 3.32734693e-06, 5.70909432e-06, -6.71155865e-09,\n",
" -2.83015440e+01, 1.97666678e+01, 5.07564715e-01],\n",
" [ 2.55788135e-08, 2.62452949e-08, -1.13916259e-07,\n",
" -2.42108745e-01, 9.65279820e-02, 1.26130568e+00]])"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"stms[-1]"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down
529 changes: 529 additions & 0 deletions doc/notebooks/surrogate_primer_vector.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion doc/notebooks/udp_pl2pl.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.9"
"version": "3.13.1"
},
"orig_nbformat": 4
},
Expand Down
41 changes: 22 additions & 19 deletions doc/notebooks/udp_pl2pl_N_impulses.ipynb

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions doc/trajopt.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ amenable to evolutionary techniques.
.. autoclass:: mga
:members: pretty, plot, to_planet

.. autoclass:: mga_1dsm
:members: pretty, plot, to_planet

.. autoclass:: pl2pl_N_impulses
:members: pretty, plot, plot_primer_vector

Utilities
*********
In order to facilitate the use of the classes in this module, some utilities are provided.
Expand All @@ -59,5 +65,7 @@ In order to facilitate the use of the classes in this module, some utilities are

.. autofunction:: primer_vector

.. autofunction:: primer_vector_surrogate

.. autoclass:: _launchers
:members: atlas501, atlas551, soyuzf, ariane5
3 changes: 2 additions & 1 deletion doc/tut_trajopt.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ Trajectory Optimization
notebooks/udp_mga
notebooks/udp_mga_1dsm
notebooks/udp_pl2pl_N_impulses
notebooks/primer_vector
notebooks/primer_vector
notebooks/surrogate_primer_vector
49 changes: 49 additions & 0 deletions doc/utils.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
.. _utils:

Utils
###############################################################################

.. currentmodule:: pykep.utils

Spice Utils
###############################################################################

.. autofunction:: spice_version

.. autofunction:: load_spice_kernels

.. autofunction:: unload_spice_kernels

.. autofunction:: inspect_spice_kernel

.. autofunction:: name2naifid

.. autofunction:: framename2naifid

.. autofunction:: rotation_matrix

.. Autofunction:: naifid2name

.. currentmodule:: pykep

Encoding Utils
###############################################################################

.. autofunction:: alpha2direct

.. autofunction:: direct2alpha

.. autofunction:: eta2direct

.. autofunction:: direct2eta

.. currentmodule:: pykep.utils

.. autofunction:: uvV2cartesian

.. autofunction:: cartesian2uvV

Miscellanea
###############################################################################

.. autofunction:: planet_to_keplerian
9 changes: 8 additions & 1 deletion pykep/plot/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
set(PYKEP_PLOT_PYTHON_FILES __init__.py _planet.py _lambert.py _ballistic.py _sf_leg.py)
set(PYKEP_PLOT_PYTHON_FILES
__init__.py
_planet.py
_lambert.py
_ballistic.py
_sf_leg.py
_mit.py)

install(FILES ${PYKEP_PLOT_PYTHON_FILES} DESTINATION ${_PYKEP_INSTALL_DIR}/plot)
2 changes: 1 addition & 1 deletion pykep/plot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from ._ballistic import add_ballistic_arc
from ._sf_leg import add_sf_leg
from ._sf_leg import add_sf_hf_leg
from ._mit import add_mit

def make_3Daxis(**kwargs):
"""Constructs and returns a 3D axis. All kwargs are forwarded to the call to `figure()` in matplotlib.
Expand All @@ -31,7 +32,6 @@ def add_sun(ax, **kwargs):
"""
kwargs.setdefault("c", "y")
kwargs.setdefault("s", 30)
kwargs.setdefault("label", "Sun")

ax.scatter(0, 0, 0, **kwargs)
return ax
Expand Down
68 changes: 68 additions & 0 deletions pykep/plot/_mit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import pykep as _pk
import numpy as _np

def add_mit(ax,
mit,
mu,
units=_pk.AU,
N=60,
c_segments=["royalblue", "indianred"],
figsize=(5, 5),
**kwargs
):
"""
Plot a Multiple Impulse Trajectory (mit) stored in the mit format:
mit = [ [[r,v], DV, DT], ... ]
Args:
*mit* (:class:`list`): The decision vector in the correct tof encoding.
*mu* (:class:`float`): The gravitational parameter
*ax* (:class:`mpl_toolkits.mplot3d.axes3d.Axes3D`, optional): The 3D axis to plot on. Defaults to None.
*units* (:class:`float`, optional): The unit scale for the plot. Defaults to pk.AU.
*N* (:class:`int`, optional): The number of points to use when plotting the trajectory. Defaults to 60.
*c_segments* (:class:`list`, optional): The colors to alternate the various trajectory segments (inbetween DSMs). Defaults to ["royalblue", "indianred"].
*figsize* (:class:`tuple`): The figure size (only used if *ax* is None and axis have to be created.), Defaults to (5, 5).
*\\*\\*kwargs*: Additional keyword arguments to pass to the trajectory plot (common to Lambert arcs and ballistic arcs)
Returns:
:class:`mpl_toolkits.mplot3d.axes3d.Axes3D`: The 3D axis where the trajectory was plotted.
"""
if ax is None:
ax = _pk.plot.make_3Daxis(figsize=figsize)

DVs = [_np.linalg.norm(node[1]) for node in mit]
maxDV = max(DVs)
DVs = [s / maxDV * 30 for s in DVs]

# 3 - We loop across grid nodes
for i, node in enumerate(mit):
ax.scatter(
node[0][0][0] / units,
node[0][0][1] / units,
node[0][0][2] / units,
color="k",
s=DVs[i],
)

r_after_dsm = node[0][0]
v_after_dsm = [a + b for a, b in zip(node[0][1], node[1])]
_pk.plot.add_ballistic_arc(
ax,
[r_after_dsm, v_after_dsm],
node[2],
mu,
N=N,
units=units,
c=c_segments[i % len(c_segments)],
**kwargs
)
return ax
3 changes: 2 additions & 1 deletion pykep/trajopt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ set(PYKEP_TRAJOPT_PYTHON_FILES
__init__.py
_direct_point2point.py
_direct_pl2pl.py
_mga.py _mga_1dsm.py
_mga.py _mga_1dsm.py
_min_Bu_bu.py
_launchers.py
_pl2pl_N_impulses.py
_primer_vector.py)
Expand Down
3 changes: 2 additions & 1 deletion pykep/trajopt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
from ._pl2pl_N_impulses import pl2pl_N_impulses

# MIT (multiple Impulse Trajectories)
from ._primer_vector import primer_vector
from ._primer_vector import primer_vector, primer_vector_surrogate
from ._min_Bu_bu import minBu_bu_p, minBu_bu

# The launchers models
from ._launchers import _launchers
Expand Down
Loading

0 comments on commit f9500cf

Please sign in to comment.