Creating a Movie with Data from Outer Space in R

Source: Wikimedia

The Rosetta mission of the European Space Agency (ESA) is one of the greatest (yet underappreciated) triumphs of humankind: it was launched in 2004 and landed the spacecraft Philae ten years later on a small comet, named 67P/Churyumov–Gerasimenko (for the whole timeline of the mission see here: Timeline of Rosetta spacecraft).

ESA provided the world with datasets of the comet which we will use to create an animated gif in R… so read on!

The only prerequisites that we need is the rgl package (on CRAN) and an installed version of ImageMagick: http://www.imagemagick.org/script/download.php.

The script itself is very short due to the powerful functions of the rgl package, the dataset is loaded directly from the internet site of ESA:

library(rgl)
comet <- readOBJ(url("http://sci.esa.int/science-e/www/object/doc.cfm?fobjectid=54726")) # may take some time to load

open3d()
## wgl 
##   1

rgl.bg(color = c("black"))
shade3d(comet, col = ("gray"))
movie3d(spin3d(axis = c(0, 0, 1)), duration = 12, dir = getwd())
## Writing 'movie000.png'
## Writing 'movie001.png'
## Writing 'movie002.png'
## Writing 'movie003.png'
[...]
## Writing 'movie118.png'
## Writing 'movie119.png'
## Writing 'movie120.png'
## Loading required namespace: magick

system("cmd.exe", input = paste("cd", getwd(), "&& convert -loop 0 movie.gif philae.gif")) # change GIF animation cycles to inf
Microsoft Windows [Version 10.0.17134.706]
(c) 2018 Microsoft Corporation. All rights reserved.

C:\Users\Holger\[...]>cd C:/Users/Holger/[...] && convert -loop 0 movie.gif philae.gif

C:\Users\Holger\[...]>

The result is quite impressive:

I also used the dataset to create a 3D printout which is now on my desk in the office at my university:

What a symbol of the power of science to have a 3D printout of a cosmic roamer on your desk and an animated image of it on your computer!

10 thoughts on “Creating a Movie with Data from Outer Space in R”

  1. Was excited about your article. Installed rgl package, etc. as recommended. However, I got various error messages -see below.

    > library(rgl)
    Error: package or namespace load failed for ‘rgl’ in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]):
    there is no package called ‘Rcpp’
    In addition: Warning message:
    package ‘rgl’ was built under R version 3.5.3

    I also installed package Rcpp.

    I use R version 3.5.2 (2018-12-20) — "Eggshell Igloo". Is that the reason why it does not work?

    NB. I'm a relatively novice R user.

  2. In this code you have to add the library “magick”, then it works:

    library(magick)

      1. Hello,
        My code don’t work without these library:
        magick: Advanced Graphics and Image-Processing in R
        Bindings to ‘ImageMagick’: the most comprehensive open-source image processing library available.
        Could be the R version 3.5.1 ?
        ## Warning message:
        ## package ‘rgl’ was built under R version 3.5.3
        I don’t know.

        1. Could be the issue ? :

          The Rgl package was built to use the convert.exe file from Imagemagick. The problem is that the version of IM currently available for Windows does not contain this file, it uses the magick.exe instead.

          What solved the problem for me was actually quite simple: go to the Imagemagick library in Program Files (or the place you installed it), find the ‘magick.exe’ file, and rename it to ‘convert.exe’. 🙂

  3. From stackoverflow:
    The Rgl package was built to use the convert.exe file from Imagemagick. The problem is that the version of IM currently available for Windows does not contain this file, it uses the magick.exe instead.

    What solved the problem for me was actually quite simple: go to the Imagemagick library in Program Files (or the place you installed it), find the ‘magick.exe’ file, and rename it to ‘convert.exe’. 🙂

    1. Definitely it works !!!!!

      If you use windows there are two options:

      1) Add the r magick library and you get the movie.gif file (not the philae.gif )
      2) Rename the magick.exe file to convert.exe and get also the philae.gif file.

Leave a Reply to Arie van Dongen Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.