Python code to discover the nearest planet to Earth. R code to plot it
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore
LICENCE
README.md
planets.py
planets.r
requirements.txt

README.md

Python script to calculate the distance from Earth to Mercury, Venus, and Mars, and an R script to plot that data. Inspired by an episode of the BBC's More or Less. See my blog post Which planet is closest to Earth? for the full details.

The Python script uses the Skyfield package and the Jet Propulsion Laboratory's DE432 ephemeris to calculate the planets' distance from Earth between 1950 and 2050. The calculations are dumped to a CSV file, and then used as input for the R script.

To collect the data, run:

pip3 install -r requirements.txt
python3 planets.py > planets.csv

Then open the planets.r script in RStudio to plot the data. (Make sure to set the working directory: Session → Set Working Directory → To Source File Location.)