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

Ground Track Plotter #497

Closed
jorgepiloto opened this issue Nov 20, 2018 · 28 comments
Closed

Ground Track Plotter #497

jorgepiloto opened this issue Nov 20, 2018 · 28 comments
Labels
status:blocked Some other change is needed before working on this (see discussion) triaging:enhancement

Comments

@jorgepiloto
Copy link
Member

jorgepiloto commented Nov 20, 2018

🎯 Objective
Hi everyone,

I thought it would be interesting to include a "Ground Track Plotter" in the module of poliastro.plotting. It works in the same way as the other functions of this module: you just have to call a function called groundTrackthat takes as arguments an orbit, labelwith the possibility of using the dark mode.

🖥 Previous figure tries to plot the following orbit:

#PLOTING GROUND TRACK
from poliastro.plotting import groundTrack 

r = [-6045, -3490, 2500] * u.km
v = [-3.457, 6.618, 2.533] * u.km / u.s
ss = Orbit.from_vectors(Earth, r, v)

groundTrack(ss, dark=True)
plt.show()

Till here everything works as it should. However, once I pass the function an Orbitobject, I obtain really strange ground tracks:

pic

Notice that horizontal dashed lines are just for plotting Cancer and Capricorn Tropics.

💡 Possible solutions

If the idea is interesting for poliastro community, I will make a pull request but probably will need some help with the conversions between reference systems. I think the problem may be here, since if you try to plot just a latitude and longitude it works perfectly, showing that exact point on map.

Cape Canaveral Coordinates
lat = 28.396837
lon = -80.605659

plot

@astrojuanlu
Copy link
Member

Hi @IngenieroDeAviones, thanks a lot for the suggestion! I recommend you to check out this notebook of mine:

http://nbviewer.jupyter.org/github/Juanlu001/catching-asteroids-tracking-satellites/blob/master/Talk.ipynb#Plot-groundtrack

In particular, Cartopy will help you a lot projecting lat/lon data in the right way, avoiding all sorts of singularities.

Also, avoid basemap because it's abandoned: https://matplotlib.org/basemap/users/intro.html#cartopy-new-management-and-eol-announcement

And finally, to create a really cool 3D version:

https://plot.ly/python/lines-on-maps/#contour-lines-on-globe

@jorgepiloto
Copy link
Member Author

Wow! That was exactly the idea I had on my mind! Hope to finish this night the #491 API Docs 📓 and start reading in detail all the information in previous links to complete this plotting enhancement 😄

@jorgepiloto
Copy link
Member Author

Finally I was able to get a beautiful plot based on cartopy as @Juanlu001 suggested 👍 Next plot is a 24 hours track for the orbit satellite that I have simulated: 🛰️

plot

However, it should be shifting towards West due to Earth's rotation. May this be a good starting point for trying to improve the frames module by adding a body-fixed frame? 🌍

@astrojuanlu
Copy link
Member

astrojuanlu commented Nov 23, 2018

That's right @IngenieroDeAviones, we will need proper frame support for this. To clarify, there is already an Earth-rotating frame: ITRF. However, what we need in poliastro is two things (which can be done separately):

  1. Allow the user to define an orbit in any reference frame Allow the user to define an Orbit in any reference frame #434. There are some notes in the wiki about that, but the most important thing is that we must ensure Orbit.propagate does not give garbage results when the frame is rotating.
  2. Define the rest of body-centered reference frames Improve validation of planetary reference frames #109 and Planetary frames velocity transformations are untested #451. There are already some formulas in poliastro, but in the ideal case they would need some validation and also they would have to be turned into a proper Reference Frame object from Astropy.

With 1) we should be able to leverage ITRF already and produce correct groundtrack plots, but it has to be general enough to allow for 2). Are you up to the challenge? 😉

@astrojuanlu
Copy link
Member

See also #429.

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

Are you up to the challenge? I am up for it, Sir! 😄 I will try to work on #434 from now on, but before, I did the following:

To transform a GCRS frame orbit (after being propagated) into ITRF frame orbit:

from astropy.coordinates import ITRS

r = [-6045, -3490, 2500] * u.km
v = [-3.457, 6.618, 2.533] * u.km / u.s
ss_gcrs = Orbit.from_vectors(Earth, r, v) #Orbit in GCRS


t_span = np.linspace(0, 24, 24*60) * u.h #Time span for each minute within 24 hours

pos_gcrs = ss_gcrs.sample(t_span) #astropy.coordinates.builtin_frames.gcrs.GCRS
pos_itrs = pos_gcrs.transform_to(ITRS) #astropy.coordinates.builtin_frames.itrs.ITRS

coord_itrs = pos_itrs.spherical #Convert to spherical
lon, lat = coord_itrs.lon, coord_itrs.lat #Just calling atributes

However, I got this plot:

plot_1

A closer look:

plot_2

Not sure what is going on here, because propagation is done with GCRS. I am missing something.

@astrojuanlu
Copy link
Member

astrojuanlu commented Nov 24, 2018 via email

@astrojuanlu
Copy link
Member

I updated the status of this issue because a past comment of mine contained a mistake.

In particular, the two blockers are #109 and #451, which are kind of the same problem. At the moment, we could of course perform groundtrack plotting using ITRF as defined in Astropy, but in poliastro we try not to include features that apply only to the Earth, so we should take the planetary frames and properly define them using the astropy.coordinates machinery.

Also, @jorgepiloto already tried to build a prototype but something was not quite working, as can be seen in the plots above. For anyone willing to work on this issue, showing a proper groundtrack would be a good starting point.

@sakethramanujam
Copy link

@Juanlu001 As discussed in the email, I'm willing to work on this issue. Will update the comment upon reception of a positive result.
Currently understanding the math and what @jorgepiloto has done.

@astrojuanlu
Copy link
Member

I adjusted @jorgepiloto code and I seem to get a proper groundtrack:

Figure_1

Perhaps the key is using the right projection:

https://scitools.org.uk/cartopy/docs/latest/matplotlib/intro.html#adding-data-to-the-map

While working with Cartopy, please note that it can be challenging to install.

@jorgepiloto
Copy link
Member Author

Now that I feel more comfortable working with astropy.coordinates I decided to go back to this. I was able to make the ground-track in GCRS and ITRS. However the plot is not showing the shift in ITRS curve and it should appear...

track

@astrojuanlu
Copy link
Member

astrojuanlu commented May 4, 2019

However the plot is not showing the shift in ITRS curve and it should appear...

True! I got it in #497 (comment), can you share a https://gist.github.com?

@jorgepiloto
Copy link
Member Author

@astrojuanlu
Copy link
Member

I can reproduce this plot, but not exactly sure what changed. Investigating.

@astrojuanlu
Copy link
Member

Aha! You are missing the obstime :) The ITRS evolves with time! You have to do this:

    # Transform GCRS to ITRS
    ss_gcrs = ss.sample()
    ss_itrs = ss_gcrs.transform_to(coord.ITRS(obstime=ss_gcrs.obstime))

@jorgepiloto
Copy link
Member Author

Oh! I thought the conversion between GCRS and ITRS did not need any extra parameters, that everything has done by itself 🤔 Thank you so much!

Still working on this... 🚀

@jorgepiloto
Copy link
Member Author

Finally working! I also added the option for the user to plot the ground track for a given time of flight. Before making the corresponding pull request I would like to add more features related to plotting options. For example:

gndtrack = Groundtrack()
gndtrack.plot(iss, 12 * u.h, label='ISS')
gndtrack.plot(molniya, 24 * u.h, label='Molniya-1')

And it would show the ground-track with beautiful labels as other plotting utilities available in poliastro. What do you think about it?

Some images for the iss being tracked for the next 5 hours (directly taken from poliastro.examples):
iss_track

@astrojuanlu
Copy link
Member

I would call it GroundtrackPlotter for consistency :)

Some questions:

  • Cartopy, Plotly or both? The former is static (works everywhere) and has very beautiful output, but it's also difficult to install with pip (there's always Anaconda of course)
  • What happens if the user tries to plot orbits from different attractors?
  • Should we plot only coordinates, like OrbitPlotter.plot_trajectory does, instead of orbits?

@jorgepiloto
Copy link
Member Author

Sure, GroundtrackPlotter sounds better!

Related with different attractors, it is something I still have to deal with. I thought about imposing for the moment that the only valid attractor was Earth till I found a better solution.

When talking about plot only coordinates, you mean that user should do the propagation for sampling the orbit positions and then pass them to the GroundtrackPlotter?

@astrojuanlu
Copy link
Member

Regarding the attractors: sounds fair!

Regarding the API: yes, that was my thinking!

@astrojuanlu
Copy link
Member

@Sedictious is working on a complementary approach using Cesium in #739

@astrojuanlu
Copy link
Member

Going back to this, I think Plotly would be a compelling alternative to Cartopy in terms of ease of installation: https://plotly.com/python/lines-on-maps/

@priyanshurohilla
Copy link
Contributor

Hi @astrojuanlu , I am done with my exams now i can start working again on #953. Also this is based on plotly only ;).

@jorgepiloto
Copy link
Member Author

As discussed in official poliastro-earth chat, this feature might be placed under poliastro.earth.plotting sub-package since it is clearly focused on Earth capabilities.

@jorgepiloto
Copy link
Member Author

After two years, this feature has been implemented. I think this was one of my first issues at poliastro. Please, if you find any king of bug or would like to extend its functionalities, open an issue or contact developers through official channels 🚀

@priyanshurohilla
Copy link
Contributor

I am soo glad this has been implemented. 😃

@FrancescoColombi
Copy link

FrancescoColombi commented Sep 5, 2020

Sure, GroundtrackPlotter sounds better!

Related with different attractors, it is something I still have to deal with. I thought about imposing for the moment that the only valid attractor was Earth till I found a better solution.

When talking about plot only coordinates, you mean that user should do the propagation for sampling the orbit positions and then pass them to the GroundtrackPlotter?

Hi everyone,
First of all I would say that I love these plots of ground track.

I have an idea to generalize the reference attractor:
Giving as input the orientation of the Prime Meridian (e.g. the Prime Meridian Sidereal Time, PMST) at a desired reference epoch (e.g. reference JD) and the rotation rate of the attractor (e.g. omega_attractor), you can get the ground track of a given set of position in time.

@astrojuanlu
Copy link
Member

Hi @FrancescoColombi, glad you like this new feature! Using the orientation of the prime meridian and the rotation rate of the attractor sounds like a good idea for generalizing this, I'll open a new issue.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status:blocked Some other change is needed before working on this (see discussion) triaging:enhancement
Projects
None yet
Development

No branches or pull requests

5 participants