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

Add M_to_nu_elliptic #1398

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

MLopez-Ibanez
Copy link
Contributor

No description provided.

@codecov
Copy link

codecov bot commented Nov 13, 2021

Codecov Report

Merging #1398 (6e29a81) into main (778ef36) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #1398   +/-   ##
=======================================
  Coverage   91.96%   91.96%           
=======================================
  Files          82       82           
  Lines        4342     4346    +4     
  Branches      362      362           
=======================================
+ Hits         3993     3997    +4     
  Misses        259      259           
  Partials       90       90           
Impacted Files Coverage Δ
src/poliastro/core/angles.py 95.74% <100.00%> (+0.14%) ⬆️
src/poliastro/core/propagation/farnocchia.py 79.16% <100.00%> (-0.29%) ⬇️
src/poliastro/twobody/angles.py 93.44% <100.00%> (+0.33%) ⬆️
src/poliastro/twobody/orbit.py 87.93% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 778ef36...6e29a81. Read the comment docs.

Copy link
Member

@astrojuanlu astrojuanlu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about what to do with this pull request, for the reasons stated below.

On one hand, as I stated in #1013, we don't have generic "M from/to nu" on purpose since, as I painfully discovered in #908 (comment), the mean anomaly is far from being a well-defined quantity with a clear geometrical or physical meaning for all eccentricity regimes. Having a M_to_nu_elliptic invites the question of "why not having M_to_nu_{parabolic,hyperbolic} as well. In any case, we need to document this better, both for users and for potential contributors.

On the other hand, M_to_nu_elliptic is not a generic converter, but is only meant to be used for elliptic orbits. There is no eccentricity check though.

And finally, you mention that this is "slightly faster" than calling E_to_nu(M_to_E()), probably because of similar reasons as the ones you stated in #1360 (comment). But can we have a measurement of how much faster it is, so we can have an idea of the performance gain?

If we were to merge this, I'd vote to:

  • Move a function to a different module, like poliastro.util, to make it clear that this is a convenience function.
  • Add a short sentence to the docstring pointing out that parabolic and hyperbolic versions are not provided on purpose, and linking to Add docs on converting mean anomaly to true anomaly #1013
  • Make it raise a ValueError if the eccentricity is out of range.

What do you think?

@MLopez-Ibanez
Copy link
Contributor Author

from poliastro.twobody.angles import M_to_nu_elliptic, E_to_nu, M_to_E
from astropy import units as u
%timeit [ M_to_nu_elliptic(M=x * u.deg, ecc=0.1 * u.one) for x in range(0,180)]
%timeit [ E_to_nu(M_to_E(M=x * u.deg, ecc=0.1 * u.one), ecc=0.2 * u.one)  for x in range(0,180)]
In [2]: %timeit [ M_to_nu_elliptic(M=x * u.deg, ecc=0.1 * u.one) for x in range(0,180)]
52.8 ms ± 3.1 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

In [3]: %timeit [ E_to_nu(M_to_E(M=x * u.deg, ecc=0.1 * u.one), ecc=0.2 * u.one)  for x in range(0,180)]
117 ms ± 19.6 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)

@MLopez-Ibanez
Copy link
Contributor Author

I didn't provide them because I didn't use them. But I noticed that poliastro itself does convert from M to nu for parabolic and hyperbolic in at least two places:

@astrojuanlu
Copy link
Member

Yep, we are forced to do that because 2 public NASA APIs use M as the anomaly for potentially parabolic and hyperbolic objects as well. I'm sure there's a good reason for it, but I'm not sure which.

@astrojuanlu
Copy link
Member

Ah sorry, that belongs to the propagator itself (didn't have my morning coffee yet).

I wonder if the performance gain also happens if the caller is also jitted?

@astrojuanlu
Copy link
Member

Yep, we are forced to do that because 2 public NASA APIs use M as the anomaly for potentially parabolic and hyperbolic objects as well. I'm sure there's a good reason for it, but I'm not sure which.

To be clear, the ambiguity appears mainly in the near-parabolic region (not so uncommon for comets), and my beef is with calling M "an angle" for non-elliptic orbits.

@MLopez-Ibanez
Copy link
Contributor Author

I wonder if the performance gain also happens if the caller is also jitted?

I would assume that if numba does inlining (or when numba does inlining), then there should not be any measurable difference when using just the core versions. But the caller code in orbit.py is not using the core versions.

@MLopez-Ibanez
Copy link
Contributor Author

* Move a function to a different module, like `poliastro.util`, to make it clear that this is a convenience function.

Sure. Should the core version also move to poliastro.core.util ?

* Add a short sentence to the docstring pointing out that parabolic and hyperbolic versions are not provided on purpose, and linking to #1013

What should the sentence say?

* Make it raise a `ValueError` if the eccentricity is out of range.

What would be an acceptable range? This is something that could be done for the non-core version for extra safety. However, note that M_to_E does not have such a check (nor any other M_to_X function).

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

Successfully merging this pull request may close these issues.

None yet

2 participants