Vectorized keplerlib.propagate#511
Conversation
Previously propagate was made to use 2 and 3 dimensional arrays internally. These would broadcast properly for the existing tests only because some dimensions were singletons, as soon as you tried to use multiple position/ velocity vectors the broadcasting wouldn't work properly. This commit fixes that.
brandon-rhodes
left a comment
There was a problem hiding this comment.
Thanks for working on this! I have made a few comments but the adjustments should be fairly minor — then we'll be ready to merge. As long as the new vector-loading starts with an underscore, your tests can come later, as long as we keep passing the tests for the single-comet case!
|
I edited the script to use |
brandon-rhodes
left a comment
There was a problem hiding this comment.
Oh, no! Why did GitHub not notify me about your update, and only add this to my notifications when you commented 6 hours ago? I didn't mean to leave you waiting several days. I wonder if I left the tab open and it updated it and so it thought I'd seen it?
In any case, I have two more quick comments!
|
And I'll now promptly close this tab in case leaving it open might eat notifications. Thanks for the work you're doing on this! |
I'm glad to be able to do something useful! |
In some places `np.copyto` can replace boolean indexing
|
I made a few other improvements also:
|
|
|
||
| x = amin(array([upper, amax(array([lower, (lower+upper)/2]), axis=0)]), axis=0) | ||
| x = copy(upper) | ||
| copyto(x, (upper+lower)/2, where=(lower<=upper)) |
There was a problem hiding this comment.
It took me a while, but I figured out that
upper if lower>upper else (lower+upper)/2
is equivalent to
min(upper, max(lower, (lower+upper)/2))
This also occurs further down.
|
I think this is good to go now. |
|
Is doing something similar for mpcorb_orbit in mpc.py hard? Because that's precisely what I would need and be happy to add. As I understand this allows for computation of positions from multiple orbits all at once? Can this approach be used with observe method? I'd like to check whether object is in FOV of telescope for large subsets of MPC. |
brandon-rhodes
left a comment
There was a problem hiding this comment.
Drat, I apparently made this comment a few days ago but instead of submitting it, it dangled as part of a review. Let me try hitting "Comment" and that should make it appear.
| p = 1 - e*e | ||
| parabolic = (e == 1.0) | ||
| p[parabolic] = rows.perihelion_distance_au.values[parabolic] * 2.0 | ||
| p[~parabolic] *= rows.perihelion_distance_au.values[~parabolic]/ (1.0 - e[~parabolic]) |
There was a problem hiding this comment.
One final idea, because it looks so painful to be creating those specially indexed copies of the Pandas columns:
parabolic = (e == 1.0)
p = (1 - e*e) / (1.0 - e + parabolic)
p[parabolic] += 2.0
p *= rows.perihelion_distance_au.values
Would that produce the same output, but without needing the special indexing?
There was a problem hiding this comment.
Nice! That's a clever way to avoid the division by 0. I added that in.
|
@JoshPaterson, I've added the URL for this pull request to my daily to-do list so that I keep looking at it whether GitHub shows it in my notifications or not; it looks like I keep missing comments from you, and I want to get it merged by cutting down the turn-around time. I hope it hasn't made your holidays too frustrating! |
Don't worry! I know we're all volunteers, so instant feedback is nice when it happens, but I don't expect it. Also maybe I should try to get in the habit of clicking the 'request review' button so it will be sure to show up on your dashboard. |
|
@xmichaelx Yes, asteroids will definitely be supported once this gets officially released. The changes in this PR are mostly limited to |
I have successfully vectorized
keplerlib.propagate! All of it's arguments can now be arrays. Just for testing purposes I added a function todata/mpc.pythat can take a comets dataframe and convert it into a_KeplerOrbitobject that represents multiple comets.At the moment
_KeplerOrbitobjects that represent multiple orbits don't play well with otherVectorFunctionobjects; I'm not sure what needs to change to fix that.I haven't added any tests yet since none of the official functions in
data/mpc.pycan handle multiple orbits at a time yet.Here's an example script:
Which generates this plot: