# Map the solar system to a place near you –A NatGeo’s MARS inspired Shiny web app

So I went to try and understand what these coordinate systems actually are.

No quick wins here.

(Solar) Ecliptic coordinate systemA visualisation of the Earth ecliptic coordinate system.

Thanks to Wikipedia, I learned that an ecliptic coordinate system can have its “origin […] be the center of either the Sun or Earth, its primary direction is towards the vernal (northward) equinox, and it has a right-hand convention.

” For those of us, including me, that do not know what “vernal (northward) equinox” means, it’s the moment when the plane that one could imagine through the Earth’s equator passes through the Sun’s center in spring (remember that the Earth’s axis is tilted at the Sun).

This happens again in September and is then called the southward equinox.

This image from Wikipedia made things clearer for me:Heliographic Inertial coordinate systemThis is a coordinate system that’s basically like our latitude and longitude system here on earth, but mapped to the Sun.

If you’re interested about reading more, you can find information from NASA here or here.

I quickly discarded using it (because I couldn’t wrap my head around it quickly enough) but feel free to explore this as well.

The moonsun R packageBefore doing any reading in of data, I decided to do at least one quick check if there are any R packages available for planetary plotting.

Luckily, it turns out there is one, called moonsun by Lukasz Komsta.

Bingo!After walking down a blind alley initially (see the outtakes), it proved to allow me to do just what I wanted, providing me with all of the solar system’s planets’ longitude data in Earth ecliptic coordinates and based on a given date, as well as a planet’s distance.

Since the plan is to map the planets to a flat (strike that — see outtakes) spherical surface, I am ignoring the latitude in the ecliptic coordinates of planets.

This way, I am left with everything that’s needed to map the locations for all eight planets, plus Pluto and the Sun.

#Getting ecliptic latitude and longitude coordinates from a call to the planets() function in the moonsun package and its outputplanets_today <- data.

frame( as.

ecc(planets(show.

moon = FALSE)), dist = planets(show.

moon = FALSE)\$dist )planets_today#Output:# long lat dist# 2018-11-24-Sun 241* 41' 2'' 0* 0' 0'' 0.

99# 2018-11-24-Mercury 247* 55' 57'' -1* 54' 26'' 0.

69# 2018-11-24-Venus 205* 59' 15'' 0* 12' 2'' 0.

37# 2018-11-24-Mars 333* 46' 13'' -2* 35' 33'' 0.

97# 2018-11-24-Jupiter 242* 51' 16'' 0* 39' 57'' 6.

35# 2018-11-24-Saturn 276* 35' 28'' 0* 32' 55'' 10.

87# 2018-11-24-Uranus 29* 49' 35'' -1* 27' 12'' 19.

05# 2018-11-24-Neptune 342* 42' 11'' -1* 1' 54'' 29.

77# 2018-11-24-Pluto 280* 46' 14'' 2* 28' 57'' 33.

38Mapping the coordinates of planets to earth’s surfaceNow, based on an angular direction as well as a distance measure, the goal is to find the coordinates where planets were to be located here on earth, given some kind of downscaling factor.

To do this, I stumbled upon the geosphere package that includes a function for doing just that.

The destpoint() function takes as inputs a starting location, directional angle with reference to 0 degrees north and a distance in meters and returns the coordinates where this will land you.

Voila!#Pick the location of Earth as a starting point, e.

g.

the Mojave desertstartingLocationLng <- -115.

7863069startingLocationLat <- 35.

0992539#Get angles between Earth and the planets as seen from a top-down-view from the ecliptic north to south poleplanetsAngles <- (-1) * (as.

numeric(as.

ecc(planets(show.

moon = FALSE))\$lat) – 360)#Get the distances (in AU and converted to 1 AU = 1,000 m)planetsDistances <- planets(show.

moon = FALSE)\$dist * 1000newCoords <- destPoint(c(startingLocationLng, startingLocationLat), planetsAngles, planetsDistances)The Solar System Mapper appHaving the core components available, all that was needed was to weave things together in a basic Shiny web application using R and RStudio.

A screenshot of the final app can be seen below.

The Solar System Mapper web application, built with R & Shiny.

The app offers the following functionality:Set the date of the observationSelect the position for your EarthChoose a scale for translating celestial distances into earthly onesBased on these inputs, it will then calculate the positions of the celestial objects on the map.

It will also provide you with the “raw” data (like coordinates and planet sizes in cm) that you would need to actually go out into the world like Ben Sawyer and his dad.

A fun side note: Based on the size of the Earth, as well as Saturn, that Ben Sawyer and his dad used in their model on TV, my app tells me that they would have needed to drive approximately 2 kilometers from Earth to Saturn and applied a scale of 1 AU = 0.

18 km.

This is based on assuming their Earth is roughly 1.

53 cm in diameter and Saturn being roughly 14.

50 cm in diameter.

As a date, I picked November 21, 2016, the day the episode first aired in 2016.

Go ahead and try the app for yourself: https://pdwarf.

shinyapps.

io/solar-system-mapper/The code is available via GitHub here.

OuttakesAs this project was foremost a learning journey for me, I think it’s fun to look at the actual process that included some very blind alleys which I walked down.

In total, I took two really wrong turns during the course of this project:Wrong turn #1: Misinterpreting the Horizontal coordinate systemIn the documentation for the moonsun R package, I saw that it lets you convert coordinates to something called Horizontal coordinates.

I (too) briefly read up on that and thought I had found just what I needed.

For once, Wikipedia was not my best source.

I misread the image you can see below completely.

To me, back then, the image looked like what the Ecliptic coordinate system later turned out to be.

I guess that I mistook the horizon in the image as the equator of Earth.

I thought that I would just use the azimuth and distance and could use that the way I later used the Ecliptic longitude vairable.

So I set out to write a function that would transform azimuth measures and distances into x-y-coordinates on a plane.

This function worked something like this:AzimuthToXY <- function(azimuth, distance) { if(azimuth > 0 && azimuth < 90) { Y = sin(NISTdegTOradian(azimuth)) * distance X = cos(NISTdegTOradian(azimuth)) * distance } else if(azimuth == 90) { Y = distance X = 0 } else if(azimuth > 90 && azimuth < 180) { Y = sin(NISTdegTOradian(azimuth – 90)) * distance X = -1 * cos(NISTdegTOradian(azimuth – 90)) * distance } else if(azimuth == 180) { Y = 0 X = distance } else if(azimuth > 180 && azimuth < 270) { Y = -1 * sin(NISTdegTOradian(azimuth – 180)) * distance X = -1 * cos(NISTdegTOradian(azimuth – 180)) * distance } else if(azimuth == 270) { Y = -1 * distance X = 0 } else if(azimuth > 270 && azimuth < 360) { Y = -1* sin(NISTdegTOradian(-1 * azimuth + 360)) * distance X = cos(NISTdegTOradian(-1 * azimuth + 360)) * distance } else if(azimuth == 360 | azimuth == 0) { Y = 0 X = distance } return(data.

frame(X, Y))}But when I plotted the output (see below), it did not feel quite right to me and I read some more.

Finally, the image below, which is not as beautiful as the one on Wikipedia, but clearer, helped me figure things out.

The Horizontal coordinate system explained.

Source: Swinburne University (2018).

The Horizontal coordinate system is useful if you’re interested in where to look at the sky at a certain point in time to locate a given celestial object.

It is always based on the observer’s location on Earth whereas the Ecliptic coordinate system is based on Earth itself.

Wrong turn #2: Assuming the world is flatI briefly hinted at this error above.

Basically, I thought I would get some x-y-coordinates in a plane with respect to a 0/0 point where Earth is located and then overlay that plane onto a map.

See the code and exemplary output below:coords <- map2_df(azimuth, distance, AzimuthToXY)plot(coords)text(x = coords\$X, y = coords\$Y, labels = planetNames, pos = 1)My first idea of plotting the planets to a flat Earth.

So, after googling how to get destination coordinates from my AzimuthToXY() hustle, I stumbled upon this Stackoverflow thread titled “How can I find out a Latitude or Longitude at a distance of X from another latitude or Longitude?”.

It opened my eyes in two ways:The world isn’t flat, it’s spherical!.????‍There is a package called geosphere that includes a function which will render my hard work on the AzimuthToXY() function useless.

And that’s how I ended up on the right track, as you can see in the post above.

What a fun project — I certainly learned a lot.

And maybe that app will actually be useful to me at some point in the future!PS: This project was also done as part of the online course “Developing Data Products” by John Hopkins University on Coursera.

It is course 9/10 in the Data Science Specialization that I am close to finishing.

I will share a review of that experience once I’m 10 for 10.