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

Allow hyperbolic orbits to stay within the bounds of a plot #111

Closed
astrojuanlu opened this issue Jan 24, 2016 · 22 comments
Closed

Allow hyperbolic orbits to stay within the bounds of a plot #111

astrojuanlu opened this issue Jan 24, 2016 · 22 comments

Comments

@astrojuanlu
Copy link
Member

After #19 was fixed plotting only one hyperbolic orbit looks okay, but there can be cases when one wants it to do something like this:

new_horizons

This plot needed a patch in _generate_vals (hence tagging it as a bug), but it only works for cases where there's a previous closed orbit plotted. The logic to handle both cases has to be more complex.

@astrojuanlu
Copy link
Member Author

I'm postponing this for the next release too.

@astrojuanlu astrojuanlu modified the milestones: 0.6, 0.5 Mar 5, 2016
@astrojuanlu astrojuanlu removed this from the 0.6 milestone Feb 5, 2017
@astrojuanlu astrojuanlu modified the milestone: 0.7 Feb 12, 2017
@astrojuanlu
Copy link
Member Author

Asking the algorithm to _adjust_to_bigger_bounded_orbit() magically is probably too much. I should give more control to the user. Postponing.

@astrojuanlu
Copy link
Member Author

Blocked on #218.

@astrojuanlu astrojuanlu added the status:blocked Some other change is needed before working on this (see discussion) label Sep 5, 2017
@astrojuanlu
Copy link
Member Author

This is no longer blocked.

@astrojuanlu astrojuanlu removed the status:blocked Some other change is needed before working on this (see discussion) label Nov 20, 2017
@astrojuanlu astrojuanlu removed this from the Future milestone Nov 20, 2017
@sudnadja
Copy link

sudnadja commented Jan 6, 2018

When plotting certain hyperbolic paths, the position plots of the objects appear incorrect.
For example, in July of 2015, New Horizons flew past pluto. Taking position data from horizons for both Pluto and New Horizons with 500@0 origin and "frame" as the fundamental plane, those objects are placed into poliastro with:

PlutoM = Orbit.from_vectors(Sun, [1.197648971483503E+09, -4.443903841678363E+09, -1.747653049536265E+09] * u.km , [5.382941983259522E+00, 8.185732351064959E-01, -1.389415786284875E+00] * u.km/u.s, Time('2015-07-14 07:59',scale='tdb') )
NewHorizonsM = Orbit.from_vectors(Sun, [1.197659243752796E+09, -4.443716685978071E+09, -1.747610548576734E+09] * u.km , [5.540549267188614E+00, -1.251544669134140E+01, -4.848892572767733E+00] * u.km/u.s, Time('2015-07-14 07:59',scale='tdb') )

New Horizons is nearly on top of Pluto at that point, however the plot places New Horizons much earlier on its path:

new horizons pluto encounter

And a notebook exhibiting this behavior:

New+Horizons+Pluto+Encounter.zip

@astrojuanlu
Copy link
Member Author

I confirm I can reproduce this using both 0.8.0 and latest master version. Working on it

@astrojuanlu
Copy link
Member Author

With 0.7.0, it was also wrong but in a different way

png image 754 x 712 pixels

@astrojuanlu
Copy link
Member Author

astrojuanlu commented Jan 6, 2018

Forget about the old behavior, it's gone anyway.

Doing some quick experiments, it seems that the "first" point in the sampling is used as the "dot" where the spacecraft is. Specifically, these lines:

# Plot current position
l, = self.ax.plot(x[0].to(u.km).value, y[0].to(u.km).value,

Clearly, for hyperbolic orbits the assumption "the first point is the original Orbit" is wrong.

@astrojuanlu
Copy link
Member Author

astrojuanlu commented Jan 6, 2018

The reason why is that sampling values for the elliptic case start at zero:

if self.ecc < 1:
nu_values = np.linspace(0, 2 * np.pi, values) * u.rad

whereas for hyperbolas, start at the limit value:

else:
# Select a sensible limiting value for non-closed orbits
# This corresponds to r = 3p
nu_limit = np.arccos(-(1 - 1 / 3.) / self.ecc)
nu_values = np.linspace(-nu_limit, nu_limit, values)

The fix is trivial: adding an offset of +nu_limit to nu_values. is easy, but adding an offset won't work (see discussion in #321) Therefore, the original problem stated in #111 (comment) stands: it should be easy to let hyperbolic orbits escape the bounds of a plot instead of redefining them.

@astrojuanlu astrojuanlu added this to the 0.9 milestone Jan 6, 2018
@astrojuanlu astrojuanlu changed the title Improve handling of hyperbolic orbits Allow hyperbolic orbits to stay within the bounds of a plot Jan 6, 2018
@astrojuanlu
Copy link
Member Author

I created a new issue #295

@shreyasbapat
Copy link
Member

Is this problem still there?

@astrojuanlu
Copy link
Member Author

Probably, because we did not change anything related to that :) But as usual I failed to provide code to reproduce the issue. Would you like to try? This plot comes from this notebook, which unfortunately is in Spanish:

http://nbviewer.jupyter.org/github/Pybonacci/notebooks/blob/master/Explorando%20el%20Planeta%20Nueve%20con%20Python%20usando%20poliastro.ipynb

@shreyasbapat
Copy link
Member

Yeah Surely, I would try. I will just copy the code cells. And use google for Spanish!

@astrojuanlu
Copy link
Member Author

I stumbled upon this again while running the notebook I mentioned above. This is the code to reproduce with the current master:

ss_hyp = Orbit.from_vectors(
    Sun,
    [ -9.77441841e+07,  1.01000539e+08,  4.37584668e+07] * u.km,
    [ 23.75936985,-43.09599568, -8.7084724 ] * u.km / u.s,
)
ss_big = Orbit.from_vectors(
    Sun,
    [  4.62521605e+10,  1.55496163e+11, -4.18874038e+10] * u.km,
    [-0.46461615, 0.20385617, 0.24373322] * u.km / u.s
)

Plotting each of them separately works:

hyp big

(notice the slight bug in the hyperbolic one?)

However, plotting them together shows only the big, elliptic orbit (regardless of the order):

frame = OrbitPlotter()

frame.plot(ss_big)
frame.plot(ss_hyp)

together

Therefore, it's not enough to compute the limit nu_values for hyperbolic orbits inside the sample method: the plotting code should set them, depending on the bounds of the plot or some other parameter. Still not sure how to fix this.

@astrojuanlu
Copy link
Member Author

And by the way, this is the changes I had to made back in the day to properly plot this:

9899f5a

diff --git a/src/poliastro/plotting.py b/src/poliastro/plotting.py
index c30f610..937801b 100644
--- a/src/poliastro/plotting.py
+++ b/src/poliastro/plotting.py
@@ -156,8 +156,8 @@ def _generate_vals(self, state):
 
         if state.ecc >= 1:
             # Select a sensible limiting value for non-closed orbits
-            # This corresponds to r = 3p
-            nu_limit = Angle(np.arccos(-(1 - 1 / 3.) / state.ecc))
+            # This corresponds to r = infinity
+            nu_limit = Angle(np.arccos(-1 / state.ecc))
             nu_invalid = ((nu_vals > nu_limit) &
                           (nu_vals < (-nu_limit).wrap_at('360d')))
             nu_vals[nu_invalid] = np.nan

@astrojuanlu
Copy link
Member Author

I'm blocking this issue until we have #274 working. That one is easier and will give us hints on how to fix this.

@astrojuanlu astrojuanlu added the status:blocked Some other change is needed before working on this (see discussion) label Mar 1, 2018
@astrojuanlu
Copy link
Member Author

This is not blocked anymore.

@astrojuanlu astrojuanlu added triaging:enhancement and removed status:blocked Some other change is needed before working on this (see discussion) labels Mar 4, 2018
@shreyasbapat
Copy link
Member

What exactly is the problem ? Is it like the hyperbolic plot goes till the edge of the plot or something else?

@astrojuanlu
Copy link
Member Author

the problem is that if you plot a "small" hyperbolic orbit and a big elliptic orbit, the hyperbolic one won't be shown, and if you plot a "big" hyperbolic orbit, it will push the boundaries of the plot and you won't be able to see anything. Not sure if this is an easily solvable problem, since in general plotting closed (elliptical) orbits of very different sizes will always showcase this problem as well. The current behavior treats hyperbolic orbits as closed orbits, and I wonder if we can do better.

@astrojuanlu
Copy link
Member Author

It's not actually clear what to do with this, and also the thread is confusing because we mixed the original problem with other bugs. For the moment, I'm removing the milestone.

@astrojuanlu astrojuanlu removed this from the 0.9 milestone Apr 18, 2018
@shreyasbapat
Copy link
Member

shreyasbapat commented Mar 13, 2019

What has to be done for this?

the problem is that if you plot a "small" hyperbolic orbit and a big elliptic orbit, the hyperbolic one won't be shown, and if you plot a "big" hyperbolic orbit, it will push the boundaries of the plot and you won't be able to see anything.

This requires some extra efforts in plotting module! I think we restrict our plotting module to plot very few things. Do you think so?

@astrojuanlu
Copy link
Member Author

Perhaps it's not really something we can solve. Our current APIs allow you to clip the axis and change its limits, so perhaps that's enough. I'm closing this.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants