poliastro / poliastro

poliastro - :rocket: Astrodynamics in Python
https://docs.poliastro.space
MIT License
870 stars 281 forks source link

Orbit propagate hangs for some r, v vectors around Earth; flips vectors around Moon #474

Closed TimothySHamilton closed 4 years ago

TimothySHamilton commented 5 years ago

🐞 Problem Orbit propagate hangs for some r, v vectors around Earth; flips vectors around Moon

When I propagate a orbit with certain initial r & v vectors around the Earth, the calculation hangs and will not let me stop it except by closing the terminal window. It seems to happen for velocity vectors that are at low speed (maybe <1 km/s or so) and pointing generally inward towards the Earth. For example, the following causes it to hang:

import numpy as np
import math
from astropy import units as u
from poliastro.bodies import Earth, Moon
from poliastro.twobody import Orbit

r=[8.e3, 1.e3, 0.]*u.km
v=[-0.5, -0.5, 0.]*u.km/u.s
orbit1=Orbit.from_vectors(Earth,r,v)
orbit2=orbit1.propagate(1.*u.h)

On the other hand, putting similar r, v vectors around the Moon doesn't hang, but propagation turns them in different directions. For example, given this r and v,

r= [ 61445.76498656  24827.93010168      0.        ] km
v= [-0.42581645 -0.18867869  0.        ] km / s

and defining an orbit around the moon:

orbit_moon_enter=Orbit.from_vectors(Moon,r,v)
r_confirm=orbit_moon_enter.r
v_confirm=orbit_moon_enter.v
print("r  =",r_confirm)
print("v  =",v_confirm)

gives

r  = [ 61445.76498656  24827.93010168      0.        ] km
v  = [-0.42581645 -0.18867869  0.        ] km / s

Now propagating it by time=0:

orbit_moon_pc_f=orbit_moon_enter.propagate(0.*u.h)
r_f=orbit_moon_pc_f.r
v_f=orbit_moon_pc_f.v
print("r=",r_f,"v=",v_f)

returns different vectors for r and v:

r= [ -6.59608255e+04   6.41698121e+03  -7.85853550e-13] km 
v= [  4.64795914e-01  -2.97331246e-02   3.64125759e-18] km / s

Interestingly, they have the same magnitude as the ones put into the orbit, but they point in different directions.

A couple of plots will make it a little clearer. I am using the propagation method to do patched conics for a physics classroom exercise to simulate the Apollo moon flights. I've plotted the Earth in green and the Moon in gray (small circle). The Moon's sphere of influence is the large gray circle. The spacecraft starts out in low earth orbit and moves out in a highly elliptical path (blue), where it enters the Moon's sphere of influence. I have transformed the final r and v into the Moon's frame (the Moon is not moving--I'm putting it at a fixed point), used them to define the new orbit around the Moon, and propatated it to pericynthion (red trajectory).

The first plot shows the entire scenario, and the second plot shows a close-up of the region around the Moon. Note that it's not a simple case of flipping the sign.

figure_1 figure_2

Is there a hack I can do myself to fix this temporarily?

🖥 Please paste the output of following commands

conda info -a

conda list

# Paste your output here:
     active environment : astroconda
    active env location : /Applications/miniconda3/envs/astroconda
            shell level : 1
       user config file : /Users/timhamilton/.condarc
 populated config files : /Users/timhamilton/.condarc
          conda version : 4.5.11
    conda-build version : not installed
         python version : 3.6.4.final.0
       base environment : /Applications/miniconda3  (writable)
           channel URLs : http://ssb.stsci.edu/astroconda/osx-64
                          http://ssb.stsci.edu/astroconda/noarch
                          https://repo.anaconda.com/pkgs/main/osx-64
                          https://repo.anaconda.com/pkgs/main/noarch
                          https://repo.anaconda.com/pkgs/free/osx-64
                          https://repo.anaconda.com/pkgs/free/noarch
                          https://repo.anaconda.com/pkgs/r/osx-64
                          https://repo.anaconda.com/pkgs/r/noarch
                          https://repo.anaconda.com/pkgs/pro/osx-64
                          https://repo.anaconda.com/pkgs/pro/noarch
          package cache : /Applications/miniconda3/pkgs
                          /Users/timhamilton/.conda/pkgs
       envs directories : /Applications/miniconda3/envs
                          /Users/timhamilton/.conda/envs
               platform : osx-64
             user-agent : conda/4.5.11 requests/2.18.4 CPython/3.6.4 Darwin/14.5.0 OSX/10.10.5
                UID:GID : 502:20
             netrc file : None
           offline mode : False

# conda environments:
#
base                     /Applications/miniconda3
astroconda            *  /Applications/miniconda3/envs/astroconda
iraf27                   /Applications/miniconda3/envs/iraf27

sys.version: 3.6.4 |Anaconda, Inc.| (default, Jan 16 ...
sys.prefix: /Applications/miniconda3
sys.executable: /Applications/miniconda3/bin/python
conda location: /Applications/miniconda3/lib/python3.6/site-packages/conda
conda-build: None
conda-env: /Applications/miniconda3/bin/conda-env
user site dirs: 

CIO_TEST: <not set>
CONDA_DEFAULT_ENV: astroconda
CONDA_EXE: /Applications/miniconda3/bin/conda
CONDA_PREFIX: /Applications/miniconda3/envs/astroconda
CONDA_PROMPT_MODIFIER: (astroconda) 
CONDA_PYTHON_EXE: /Applications/miniconda3/bin/python
CONDA_ROOT: /Applications/miniconda3
CONDA_SHLVL: 1
PATH: /Applications/miniconda3/envs/astroconda/bin:/Applications/miniconda3/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/local/MacGPG2/bin:/Library/TeX/texbin:/opt/local/bin:/opt/local/sbin
REQUESTS_CA_BUNDLE: <not set>
SSL_CERT_FILE: <not set>
WEBBPSF_PATH: /Applications/miniconda3/envs/astroconda/share/webbpsf-data

WARNING: could not import _license.show_info
# try:
# $ conda install -n root _license
(astroconda) MacBook-Pro-7:simulation timhamilton$ conda list
# packages in environment at /Applications/miniconda3/envs/astroconda:
#
# Name                    Version                   Build  Channel
acstools                  2.0.10                   py35_0    http://ssb.stsci.edu/astroconda
alabaster                 0.7.10           py35hb692fe1_0  
appnope                   0.1.0            py35hd172556_0  
asdf                      1.3.3                    py35_3    http://ssb.stsci.edu/astroconda
asn1crypto                0.24.0                   py35_0  
asteval                   0.9.11                   py35_0    http://ssb.stsci.edu/astroconda
astroimtools              0.1.1                    py35_2    http://ssb.stsci.edu/astroconda
astropy                   3.0.1            py35h917ab60_1  
astroquery                0.3.8                     <pip>
attrs                     17.4.0                   py35_0  
babel                     2.5.3                    py35_0  
basemap                   1.0.7               np113py35_0  
beautifulsoup4            4.6.3                     <pip>
blas                      1.0                         mkl  
bleach                    2.1.3                    py35_0  
bokeh                     0.12.14                  py35_0  
ca-certificates           2018.03.07                    0  
calcos                    3.3.4                    py35_0    http://ssb.stsci.edu/astroconda
certifi                   2018.8.24                py35_1  
cffi                      1.11.5           py35h342bebf_0  
cfitsio                   3.430                         1    http://ssb.stsci.edu/astroconda
chardet                   3.0.4            py35h16a84c2_1  
click                     6.7              py35hcc65ea6_0  
cloudpickle               0.5.2                    py35_1  
costools                  1.2.1                    py35_3    http://ssb.stsci.edu/astroconda
crds                      7.1.5                    py35_3    http://ssb.stsci.edu/astroconda
cryptography              2.1.4            py35hbbb57dc_0  
cubeviz                   0.0.2                    py35_1    http://ssb.stsci.edu/astroconda
curl                      7.58.0               ha441bb4_0  
cycler                    0.10.0           py35hb89929e_0  
cython                    0.27.3           py35h36d65b6_0  
cytoolz                   0.9.0.1          py35h1de35cc_0  
d2to1                     0.2.12                   py35_0    http://ssb.stsci.edu/astroconda
dask                      0.17.2                   py35_0  
dask-core                 0.17.2                   py35_0  
dbus                      1.12.2               h5243cc1_1  
decorator                 4.0.9                    py35_0    http://ssb.stsci.edu/astroconda
dill                      0.2.7.1          py35h803b68c_0  
distributed               1.21.4                   py35_0  
docopt                    0.6.2                    py35_0  
docutils                  0.14             py35hb13dbd9_0  
drizzlepac                2.1.22                   py35_1    http://ssb.stsci.edu/astroconda
ds9                       7.5                           1    http://ssb.stsci.edu/astroconda
entrypoints               0.2.3            py35h837ec6f_2  
expat                     2.2.5                hb8e80ba_0  
fftw                      3.3.4                         1    http://ssb.stsci.edu/astroconda
fitsblender               0.3.2                    py35_1    http://ssb.stsci.edu/astroconda
fitsverify                4.18                          4    http://ssb.stsci.edu/astroconda
freetype                  2.8                  h12048fb_1  
geos                      3.5.0                         0  
gettext                   0.19.8.1             h15daf44_3  
ginga                     2.7.0                    py35_0    http://ssb.stsci.edu/astroconda
glib                      2.53.6               h33f6a65_2  
glue-core                 0.12.0                   py35_0    http://ssb.stsci.edu/astroconda
glue-ginga                0.2                      py35_0    http://ssb.stsci.edu/astroconda
glue-vispy-viewers        0.9                      py35_0    http://ssb.stsci.edu/astroconda
glueviz                   0.12.0                        0    http://ssb.stsci.edu/astroconda
gwcs                      0.8.0                    py35_1    http://ssb.stsci.edu/astroconda
h5py                      2.7.1            py35he1c7800_0  
hdf5                      1.10.1               ha036c08_1  
heapdict                  1.0.0                    py35_2  
hstcal                    2.0.0                         0    http://ssb.stsci.edu/astroconda
htc_utils                 0.1.0                    py35_1    http://ssb.stsci.edu/astroconda
html5lib                  1.0.1            py35h2f9c1c0_0  
icu                       58.2                 h4b95b61_1  
idna                      2.6              py35h01aacb0_1  
imageio                   2.2.0            py35h805106e_0  
imagesize                 1.0.0                    py35_0  
imexam                    0.8.0                    py35_1    http://ssb.stsci.edu/astroconda
intel-openmp              2018.0.0                      8  
ipykernel                 4.8.2                    py35_0  
ipython                   6.2.1            py35h9470683_1  
ipython_genutils          0.2.0            py35hf129286_0  
ipywidgets                7.1.2                    py35_0  
jedi                      0.11.1                   py35_1  
jinja2                    2.10             py35h6ff70ae_0  
jpeg                      9b                   he5867d9_2  
jplephem                  2.8                       <pip>
jsonschema                2.6.0            py35h2dd9e4b_0  
jupyter_client            5.2.3                    py35_0  
jupyter_core              4.4.0            py35h4ad9194_0  
jwxml                     0.3.0                    py35_1    http://ssb.stsci.edu/astroconda
keyring                   15.1.0                    <pip>
kiwisolver                1.0.1            py35h219a9d8_0  
libcurl                   7.58.0               hf30b1f0_0  
libcxx                    4.0.1                h579ed51_0  
libcxxabi                 4.0.1                hebd6815_0  
libedit                   3.1                  hb4e282d_0  
libffi                    3.2.1                h475c297_4  
libgcc                    4.8.5               hdbeacc1_10  
libgfortran               3.0.1                h93005f0_2  
libiconv                  1.15                 hdd342a3_7  
libpng                    1.6.34               he12f830_0  
libsodium                 1.0.15               hd9e47c5_0  
libssh2                   1.8.0                h322a93b_4  
libtiff                   4.0.9                h0dac147_0  
libxml2                   2.9.7                hab757c2_0  
libxslt                   1.1.32               hb819dd2_0  
llvmlite                  0.25.0                    <pip>
locket                    0.2.0            py35h58cf053_1  
lockfile                  0.12.2                   py35_0  
lxml                      4.2.0            py35h7166777_0  
markupsafe                1.0              py35h9ba0a7f_1  
matplotlib                2.2.2            py35ha7267d0_0  
mistune                   0.8.3                    py35_0  
mkl                       2018.0.2                      1  
mosviz                    0.1.1                    py35_1    http://ssb.stsci.edu/astroconda
msgpack-python            0.5.5            py35h04f5b5a_0  
nbconvert                 5.3.1            py35h63fb950_0  
nbformat                  4.4.0            py35h41c2038_0  
ncurses                   6.0                  hd04f020_2  
networkx                  2.0              py35hb193ae4_0  
nictools                  1.1.3                    py35_2    http://ssb.stsci.edu/astroconda
nose                      1.3.7            py35h9ce1e3a_2  
notebook                  5.4.1                    py35_0  
numba                     0.40.1                    <pip>
numpy                     1.13.3           py35ha726252_3  
numpydoc                  0.7.0            py35h296b98c_0  
olefile                   0.45.1                   py35_0  
openssl                   1.0.2p               h1de35cc_0  
packaging                 17.1                     py35_0  
pandas                    0.22.0           py35h0a44026_0  
pandoc                    1.19.2.1             ha5e8f32_1  
pandocfilters             1.4.2            py35hff87490_1  
parsley                   1.3                      py35_0    http://ssb.stsci.edu/astroconda
parso                     0.1.1            py35hbda7c10_0  
partd                     0.3.8            py35h6fadee7_0  
pcre                      8.41                 hfb6ab37_1  
pexpect                   4.4.0                    py35_0  
photutils                 0.4                      py35_1    http://ssb.stsci.edu/astroconda
pickleshare               0.7.4            py35h9517181_0  
pillow                    5.0.0            py35hfcce615_0  
pip                       18.1                      <pip>
pip                       9.0.1                    py35_5  
pkg-config                0.29.2               h3efe00b_7  
pkgconfig                 1.2.2            py35h4e503cb_1  
plotly                    2.4.1                    py35_0  
plotly                    3.3.0                     <pip>
pluggy                    0.6.0            py35hf57b818_0  
poliastro                 0.11.0                    <pip>
poppy                     0.6.1                    py35_1    http://ssb.stsci.edu/astroconda
prompt_toolkit            1.0.15           py35h93950c5_0  
psutil                    5.4.3            py35h1de35cc_0  
ptyprocess                0.5.2            py35hfc37984_0  
purge_path                1.2.0                    py35_0    http://ssb.stsci.edu/astroconda
py                        1.5.2            py35h4d4d87d_0  
py-expression-eval        0.3.4                    py35_1    http://ssb.stsci.edu/astroconda
pycparser                 2.18             py35hab820b0_1  
pyds9                     1.9.0.dev61+g3761d7a          py35_2    http://ssb.stsci.edu/astroconda
pyfftw                    0.9.2                    py35_3    http://ssb.stsci.edu/astroconda
pygments                  2.2.0            py35h392a662_0  
pyopengl                  3.1.1a1             np113py35_0  
pyopenssl                 17.5.0           py35h4065cf8_0  
pyparsing                 2.2.0            py35h31fab04_0  
pyqt                      5.6.0            py35hbd126f6_6  
pyqtgraph                 0.10.0                   py35_0    http://ssb.stsci.edu/astroconda
pyregion                  2.0                      py35_0    http://ssb.stsci.edu/astroconda
pysocks                   1.6.8                    py35_0  
pysynphot                 0.9.9                    py35_0    http://ssb.stsci.edu/astroconda
pytest                    3.4.2                    py35_0  
pytest-arraydiff          0.2                      py35_0  
pytest-astropy            0.2.1                    py35_0  
pytest-doctestplus        0.1.2                    py35_0  
pytest-openfiles          0.2.0                    py35_0  
pytest-remotedata         0.2.0                    py35_0  
python                    3.5.5                hc167b69_1  
python-dateutil           2.7.0                    py35_0  
python.app                2                py35he4d1c94_7  
pytz                      2018.3                   py35_0  
pywavelets                0.5.2            py35h9dc8fb8_0  
pyyaml                    3.12             py35hf8cec8a_1  
pyzmq                     17.0.0           py35h1de35cc_0  
qt                        5.6.2               h9975529_14  
qtconsole                 4.3.1            py35hd6d667b_0  
qtpy                      1.4.0                    py35_0  
radio-beam                0.2                      py35_0    http://ssb.stsci.edu/astroconda
readline                  7.0                  hc1231fa_4  
reftools                  1.7.4                    py35_1    http://ssb.stsci.edu/astroconda
requests                  2.18.4           py35h0d65e6b_1  
retrying                  1.3.3                     <pip>
scikit-image              0.13.1           py35h1de35cc_1  
scikit-learn              0.19.1           py35h2b554eb_0  
scipy                     1.0.0            py35h8b35106_0  
semantic_version          2.6.0                    py35_0  
send2trash                1.5.0                    py35_0  
setuptools                38.5.1                   py35_0  
sextractor                2.19.5                        0    http://ssb.stsci.edu/astroconda
simplegeneric             0.8.1                    py35_2  
sip                       4.18.1           py35h79e1f92_2  
six                       1.11.0           py35h39a4c60_1  
snowballstemmer           1.2.1            py35hbb7be01_0  
sortedcontainers          1.5.9                    py35_0  
spectral-cube             0.4.1                    py35_0    http://ssb.stsci.edu/astroconda
specutils                 0.2.2                    py35_2    http://ssb.stsci.edu/astroconda
specviz                   0.4.4                    py35_1    http://ssb.stsci.edu/astroconda
spherical-geometry        1.0.12                   py35_1    http://ssb.stsci.edu/astroconda
sphinx                    1.7.1                    py35_0  
sphinxcontrib             1.0              py35h3eabf46_1  
sphinxcontrib-websupport  1.0.1            py35hcb4ca16_1  
sqlite                    3.22.0               h3efe00b_0  
stginga                   0.3                      py35_0    http://ssb.stsci.edu/astroconda
stistools                 1.1                      py35_2    http://ssb.stsci.edu/astroconda
stsci                     3.0.2                    py35_0    http://ssb.stsci.edu/astroconda
stsci-data-analysis       2.1.1                    py35_0    http://ssb.stsci.edu/astroconda
stsci-hst                 3.0.2                    py35_0    http://ssb.stsci.edu/astroconda
stsci.convolve            2.2.1                    py35_1    http://ssb.stsci.edu/astroconda
stsci.distutils           0.3.8                    py35_2    http://ssb.stsci.edu/astroconda
stsci.image               2.3.0                    py35_2    http://ssb.stsci.edu/astroconda
stsci.imagemanip          1.1.2                    py35_2    http://ssb.stsci.edu/astroconda
stsci.imagestats          1.4.1                    py35_2    http://ssb.stsci.edu/astroconda
stsci.ndimage             0.10.1                   py35_2    http://ssb.stsci.edu/astroconda
stsci.numdisplay          1.6.1                    py35_2    http://ssb.stsci.edu/astroconda
stsci.skypac              0.9.8                    py35_1    http://ssb.stsci.edu/astroconda
stsci.sphere              0.2                      py35_2    http://ssb.stsci.edu/astroconda
stsci.sphinxext           1.2.2                    py35_1    http://ssb.stsci.edu/astroconda
stsci.stimage             0.2.1                    py35_2    http://ssb.stsci.edu/astroconda
stsci.tools               3.4.12                   py35_0    http://ssb.stsci.edu/astroconda
stwcs                     1.4.0                    py35_1    http://ssb.stsci.edu/astroconda
tblib                     1.3.2            py35h1b9c5fd_0  
terminado                 0.8.1                    py35_1  
testpath                  0.3.1            py35hf8009f4_0  
tk                        8.6.7                h35a86e2_3  
toolz                     0.9.0                    py35_0  
tornado                   5.0                      py35_0  
traitlets                 4.3.2            py35hd3d1486_0  
typing                    3.6.4                    py35_0  
urllib3                   1.22             py35he002d57_0  
wcwidth                   0.1.7            py35hdd0c235_0  
webbpsf                   0.6.0                    py35_1    http://ssb.stsci.edu/astroconda
webbpsf-data              0.6.0                         1    http://ssb.stsci.edu/astroconda
webencodings              0.5.1            py35hcf8ebf9_1  
wfc3tools                 1.3.4                    py35_2    http://ssb.stsci.edu/astroconda
wfpc2tools                1.0.3                    py35_2    http://ssb.stsci.edu/astroconda
wheel                     0.30.0           py35h5c0b906_1  
widgetsnbextension        3.1.4                    py35_0  
xlrd                      1.1.0            py35h892fcf7_1  
xz                        5.2.3                h0278029_2  
yaml                      0.1.7                hc338f04_2  
zeromq                    4.2.3                h378b8a2_3  
zict                      0.1.3            py35h1ae85d2_0  
zlib                      1.2.11               hf3cbc9b_2  

pip freeze | grep astropy astropy==3.0.1 pytest-astropy==0.2.1

pip freeze | grep poliastro poliastro==0.11.0

python -c "import poliastro.testing; poliastro.testing.test()"

# Paste your output here:
python -c "import poliastro.testing; poliastro.testing.test()"
====================================== test session starts =======================================
platform darwin -- Python 3.5.5, pytest-3.4.2, py-1.5.2, pluggy-0.6.0
rootdir: /Applications/miniconda3/envs/astroconda/lib/python3.5/site-packages/poliastro, inifile:
plugins: remotedata-0.2.0, openfiles-0.2.0, doctestplus-0.1.2, arraydiff-0.2
collected 474 items                                                                              

../../../../../Applications/miniconda3/envs/astroconda/lib/python3.5/site-packages/poliastro/tests/test_bodies.py . [  0%]
.....                                                                                      [  1%]
../../../../../Applications/miniconda3/envs/astroconda/lib/python3.5/site-packages/poliastro/tests/test_coordinates.py . [  1%]
..                                                                                         [  1%]
../../../../../Applications/miniconda3/envs/astroconda/lib/python3.5/site-packages/poliastro/tests/test_frames.py . [  2%]
.........................                                                                  [  7%]
../../../../../Applications/miniconda3/envs/astroconda/lib/python3.5/site-packages/poliastro/tests/test_hyper.py . [  7%]
..........                                                                                 [  9%]
../../../../../Applications/miniconda3/envs/astroconda/lib/python3.5/site-packages/poliastro/tests/test_iod.py . [  9%]
........                                                                                   [ 11%]
../../../../../Applications/miniconda3/envs/astroconda/lib/python3.5/site-packages/poliastro/tests/test_jit.py . [ 11%]
..                                                                                         [ 12%]
../../../../../Applications/miniconda3/envs/astroconda/lib/python3.5/site-packages/poliastro/tests/test_maneuver.py . [ 12%]
.....                                                                                      [ 13%]
../../../../../Applications/miniconda3/envs/astroconda/lib/python3.5/site-packages/poliastro/tests/test_patched_conics.py . [ 13%]
...                                                                                        [ 14%]
../../../../../Applications/miniconda3/envs/astroconda/lib/python3.5/site-packages/poliastro/tests/test_plotting.py . [ 14%]
.........                                                                                  [ 16%]
../../../../../Applications/miniconda3/envs/astroconda/lib/python3.5/site-packages/poliastro/tests/test_plotting2d.py . [ 16%]
.......                                                                                    [ 18%]
../../../../../Applications/miniconda3/envs/astroconda/lib/python3.5/site-packages/poliastro/tests/test_plotting3d.py . [ 18%]
........                                                                                   [ 20%]
../../../../../Applications/miniconda3/envs/astroconda/lib/python3.5/site-packages/poliastro/tests/test_stumpff.py . [ 20%]
..                                                                                         [ 20%]
../../../../../Applications/miniconda3/envs/astroconda/lib/python3.5/site-packages/poliastro/tests/test_twobody.py . [ 20%]
.                                                                                          [ 21%]
../../../../../Applications/miniconda3/envs/astroconda/lib/python3.5/site-packages/poliastro/tests/test_util.py . [ 21%]
....                                                                                       [ 22%]
../../../../../Applications/miniconda3/envs/astroconda/lib/python3.5/site-packages/poliastro/tests/tests_neos/test_dastcom5.py . [ 22%]
........                                                                                   [ 24%]
../../../../../Applications/miniconda3/envs/astroconda/lib/python3.5/site-packages/poliastro/tests/tests_neos/test_neos_neows.py . [ 24%]
.....                                                                                      [ 25%]
../../../../../Applications/miniconda3/envs/astroconda/lib/python3.5/site-packages/poliastro/tests/tests_threebody/test_flybys.py . [ 25%]
.                                                                                          [ 25%]
../../../../../Applications/miniconda3/envs/astroconda/lib/python3.5/site-packages/poliastro/tests/tests_threebody/test_restricted.py . [ 25%]
                                                                                           [ 25%]
../../../../../Applications/miniconda3/envs/astroconda/lib/python3.5/site-packages/poliastro/tests/tests_twobody/test_angles.py . [ 26%]
.......................................................................................... [ 45%]
.......................................................................................... [ 64%]
..........................                                                                 [ 69%]
../../../../../Applications/miniconda3/envs/astroconda/lib/python3.5/site-packages/poliastro/tests/tests_twobody/test_decorators.py . [ 69%]
.                                                                                          [ 70%]
../../../../../Applications/miniconda3/envs/astroconda/lib/python3.5/site-packages/poliastro/tests/tests_twobody/test_orbit.py . [ 70%]
.......................x....................                                               [ 79%]
../../../../../Applications/miniconda3/envs/astroconda/lib/python3.5/site-packages/poliastro/tests/tests_twobody/test_perturbations.py . [ 79%]
xxxx........s.                                                                             [ 82%]
../../../../../Applications/miniconda3/envs/astroconda/lib/python3.5/site-packages/poliastro/tests/tests_twobody/test_propagation.py . [ 82%]
........................xs...                                                              [ 89%]
../../../../../Applications/miniconda3/envs/astroconda/lib/python3.5/site-packages/poliastro/tests/tests_twobody/test_sample.py . [ 89%]
.......................                                                                    [ 94%]
../../../../../Applications/miniconda3/envs/astroconda/lib/python3.5/site-packages/poliastro/tests/tests_twobody/test_states.py . [ 94%]
.........                                                                                  [ 96%]
../../../../../Applications/miniconda3/envs/astroconda/lib/python3.5/site-packages/poliastro/tests/tests_twobody/test_thrust.py . [ 96%]
s................                                                                          [100%]

======================================== warnings summary ========================================
tests/test_patched_conics.py::test_compute_soi
  /Applications/miniconda3/envs/astroconda/lib/python3.5/site-packages/poliastro/twobody/orbit.py:200: TimeScaleWarning:

  Input time was converted to scale='tdb' with value J2000.000. Use Time(..., scale='tdb') instead.

tests/test_patched_conics.py::test_compute_missing_body_soi_raises_error[missing_body0]
  /Applications/miniconda3/envs/astroconda/lib/python3.5/site-packages/poliastro/twobody/orbit.py:200: TimeScaleWarning:

  Input time was converted to scale='tdb' with value J2000.000. Use Time(..., scale='tdb') instead.

tests/test_patched_conics.py::test_compute_missing_body_soi_raises_error[missing_body1]
  /Applications/miniconda3/envs/astroconda/lib/python3.5/site-packages/poliastro/twobody/orbit.py:200: TimeScaleWarning:

  Input time was converted to scale='tdb' with value J2000.000. Use Time(..., scale='tdb') instead.

tests/test_plotting.py::test_plot_solar_system[True-8]
  /Applications/miniconda3/envs/astroconda/lib/python3.5/site-packages/poliastro/twobody/orbit.py:494: UserWarning:

  Frame <class 'astropy.coordinates.builtin_frames.icrs.ICRS'> does not support 'obstime', time values were not returned

tests/test_plotting.py::test_plot_solar_system[False-4]
  /Applications/miniconda3/envs/astroconda/lib/python3.5/site-packages/poliastro/twobody/orbit.py:494: UserWarning:

  Frame <class 'astropy.coordinates.builtin_frames.icrs.ICRS'> does not support 'obstime', time values were not returned

tests/test_plotting.py::test_plot_trajectory_sets_label
  /Applications/miniconda3/envs/astroconda/lib/python3.5/site-packages/poliastro/twobody/orbit.py:494: UserWarning:

  Frame <class 'astropy.coordinates.builtin_frames.icrs.ICRS'> does not support 'obstime', time values were not returned

tests/test_plotting2d.py::test_plot_trajectory_plots_a_trajectory
  /Applications/miniconda3/envs/astroconda/lib/python3.5/site-packages/poliastro/twobody/orbit.py:494: UserWarning:

  Frame <class 'astropy.coordinates.builtin_frames.icrs.ICRS'> does not support 'obstime', time values were not returned

tests/test_plotting2d.py::test_show_calls_prepare_plot
  /Applications/miniconda3/envs/astroconda/lib/python3.5/site-packages/poliastro/twobody/orbit.py:494: UserWarning:

  Frame <class 'astropy.coordinates.builtin_frames.icrs.ICRS'> does not support 'obstime', time values were not returned

tests/test_plotting2d.py::test_savefig_calls_prepare_plot
  /Applications/miniconda3/envs/astroconda/lib/python3.5/site-packages/poliastro/twobody/orbit.py:494: UserWarning:

  Frame <class 'astropy.coordinates.builtin_frames.icrs.ICRS'> does not support 'obstime', time values were not returned

tests/test_plotting3d.py::test_plot_trajectory_plots_a_trajectory
  /Applications/miniconda3/envs/astroconda/lib/python3.5/site-packages/poliastro/twobody/orbit.py:494: UserWarning:

  Frame <class 'astropy.coordinates.builtin_frames.icrs.ICRS'> does not support 'obstime', time values were not returned

tests/test_plotting3d.py::test_show_calls_prepare_plot
  /Applications/miniconda3/envs/astroconda/lib/python3.5/site-packages/poliastro/twobody/orbit.py:494: UserWarning:

  Frame <class 'astropy.coordinates.builtin_frames.icrs.ICRS'> does not support 'obstime', time values were not returned

tests/test_plotting3d.py::test_savefig_calls_prepare_plot
  /Applications/miniconda3/envs/astroconda/lib/python3.5/site-packages/poliastro/twobody/orbit.py:494: UserWarning:

  Frame <class 'astropy.coordinates.builtin_frames.icrs.ICRS'> does not support 'obstime', time values were not returned

tests/tests_twobody/test_propagation.py::test_long_propagations_kepler_agrees_mean_motion
  /Applications/miniconda3/envs/astroconda/lib/python3.5/site-packages/astropy/_erfa/core.py:118: ErfaWarning:

  ERFA function "taiutc" yielded 1 of "dubious year (Note 4)"

-- Docs: http://doc.pytest.org/en/latest/warnings.html
================ 465 passed, 3 skipped, 6 xfailed, 13 warnings in 437.49 seconds =================
(astroconda) MacBook-Pro-7:simulation timhamilton$ 

🎯 Goal

💡 Possible solutions

📋 Steps to solve the problem

astrojuanlu commented 5 years ago

Hi @TimothySHamilton, thanks for using poliastro and sorry for keeping you up late at night! I confirm I could reproduce both issues (which are in fact four, keep on reading) in my computer.

1. Propagator mean_motion hangs for some r, v vectors around Earth

Quick workaround: do

from poliastro.twobody.propagation import kepler
orbit2=orbit1.propagate(1.*u.h, method=kepler)

This will change the default propagation method from mean_motion to kepler, which is also analytic and similar in nature.

The rest of the details are in #475.

2. Orbit propagate "flips vectors around Moon"

I put "flips" between quotes because, as you noticed, this isn't just a sign change.

Quick workaround: do

from poliastro.twobody.propagation import cowell
orbit_moon_enter.propagate(0 * u.h, method=cowell)

The cowell propagator is a numerical one and does not suffer from this "flipping" issue. It just will be a bit slower.

I didn't have time to properly debug this issue yet, but I'm sure it's related to the hyperbolic branch of mean_motion, because this particular orbit has eccentricity of 1.00149526. When I have a proper analysis, I will open a separate issue.

Apart from the issue you experienced, while investigating it I also discovered #476 and #477.

astrojuanlu commented 5 years ago

@TimothySHamilton please keep us posted in case these workarounds do not work for you, or if you encounter further problems!

astrojuanlu commented 5 years ago

Hi @TimothySHamilton, would you confirm whether these workaround worked for you?

TimothySHamilton commented 5 years ago

Hi, @Juanlu001—sorry it's taken me a week and a half; I was catching up with other work. I have just tried out your solution for both the Earth-centered and the Moon-centered cases, and it works. It's not even noticeably slower. Thanks!

The patched conics work now in going from the Earth (green, left) to the Moon (gray, right, with larger circle for its sphere of influence): figure_1

By the way, I've been plotting the trajectories here by propagating through several steps and plotting their values. Is there a better or faster way to do this?

astrojuanlu commented 5 years ago

Awesome, glad to know it's working!

For the time being you could use the .sample method, which accepts a list of times among other things:

https://docs.poliastro.space/en/latest/safe.html#poliastro.twobody.orbit.Orbit.sample

However, except for the cowell method, this is essentially propagating in a loop. Also, this API is subject to change in the following release, so I would say it's fine to do what you're doing.

If you ever want to share your code we can publish it one of the examples of the documentation:

https://docs.poliastro.space/en/latest/jupyter.html

If not, we could as well publish a success story:

https://docs.poliastro.space/en/latest/index.html#success-stories

And if nothing of the above is possible, I hope at least you allow me to use this beautiful image in the social networks! :)

TimothySHamilton commented 5 years ago

@Juanlu001—I'd be honored to have it included as a code example, and you are also welcome to use it as a success story, and to use the image in the social networks. Thanks for the compliments! Let me clean up the code a little this weekend—given an input r & v near the Earth, it will output the spacecraft's r & v at pericynthion and draw a vector from the center of the moon to the spacecraft at that point. And I'll annotate the figure a little more.

If you'd like a bit more on the context, I'm making 3 or 4 programs using this code to plan out each leg of an Apollo 8-like flight, going from low earth orbit to lunar orbit and back. This is used for mission planning in the Apollo simulator that I've built for Shawnee State University, which the physics & engineering students are using in class. And we'll also use the state vectors it calculates to jump ahead in time during the simulation, skipping over the uneventful times in between maneuvers.

Where can I submit the code, an updated image, and any write-up on the context?

astrojuanlu commented 5 years ago

@TimothySHamilton thanks a lot, it sounds great! To publish the code you can use any service you want, although I would recommend https://github.com or https://gist.github.com/. We will then link it from here:

https://github.com/poliastro/poliastro/wiki/Projects-using-or-citing-poliastro

For the moment, I published your plot on Twitter :rocket:

https://twitter.com/poliastro_py/status/1059273149911629825

astrojuanlu commented 4 years ago

Hi @TimothySHamilton! It's been a long time, perhaps you moved on, but just wanted to let you know that, after getting bitten by this from time to time over the past two years, and finally after two tireless weeks of coding, we have fixed this issue :tada: Thanks again for reporting it back in the day, and I encourage you to keep an eye on the upcoming poliastro 0.14, which is going to be :rocket: awesome :rocket: