A Docker image with everything you need to run the astroML python module. astroML was written by Vanderplas et al, proc. of CIDU, pp. 47-54, 2012.
- Introduction
- What's in the Docker image
- Making the textbook figures
- Quick start with a jupyter notebook
- Quick start with jupyter lab
- Building the image yourself
astroML is python module with many of the tools one needs to apply machine learning and data mining techniques to astronomical datasets and questions.
The astroML module was developed to accompany the textbook Statistics, Data Mining, and Machine Learning in Astronomy and provides all of the code needed to reproduce the figures in the textbook. Recreating these figures is a good way to learn how to use astroML and how to use jupyter notebooks through Docker.
The base of this Docker image is the jupyter datascience notebook. This provides pandas, matplotlib, scipy, seaborn, scikit-learn, scikit-image, sympy, cython, patsy, statsmodel, cloudpickle, dill, numba, bokeh, and a number of other useful packages. On top of this software we also install astropy, pyMC, healpy, astroML, astroML_addons, and LaTex, giving you the complete environment needed to run the astroML plotting examples right out of the box.
This section will walk through exactly how to run a Docker container that will allow you to create the textbook figures through a jupyter botebook.
- Clone the github repository with the source code for the figures on to your local machine and change into that directory.
git clone https://github.com/astroML/astroML_figures
cd astroML_figures
- Run a Docker container based of the Docker iamge
oboberg/astroml
. Make sure you are running this command from theastroML_figures
directory you just downloaded.
docker run -it --rm \
-p 8888:8888 \
-v $PWD:/home/jovyan/work \
oboberg/astroml
The docker image will be automatically pulled from the Docker Hub if you do not already have it locally.
- After running the command in step
2
you will see the familiar jupyter notebook dialog and will be asked to copy and paste a URL into your local browser. Here is an example, not a command. Make sure you do not have any thing else running on port 8888.
Copy/paste this URL into your browser when you connect for the first time,
to login with a token:
http://localhost:8888/?token=sometoken
Copy and paste the URL you are given into a browser on your local machine and you will see the jupyter notebook home page.
-
Create a new jupyter notebook by clicking the
New
dropdown menu in the upper right hand corner and then selectPython3
. This should atomically open a new notebook calledUntitled
in a new browser tab. -
In a blank cell try running the following command, included the
%
.
In [1]: %run book_figures/chapter1/fig_moving_objects_multicolor.py
If the figure does not show up run the cell a second time. You can see this
uses the jupyter magic command %run
. This because the script to create the
plot is a plain python script, not a jupyter notebook.
- To actually see and modify the code we can use the jupyter magic command
%load
, which will populate a notebook cell with the contents of a python script.
In [2]: %load book_figures/chapter1/fig_moving_objects_multicolor.py
This command only populates the cell so it will still need to be executed with
a shift+enter
.
- You can now create what ever figures you would like from the book, or make up
your own. Any of the new jupyter notebooks you create will be saved to your
local directory because it was mounted in the container during the run command
in step
2
. The option-v $PWD:/home/jovyan/work
mounts the$PWD
of your local machine (in this exampleastroML_figures
) inside the container as/home/jovyan/work
.
docker run -it --rm \
-p 8888:8888 \
-v $PWD:/home/jovyan/work \
oboberg/astroml
docker run -it --rm \
-p 8888:8888 \
-v $PWD:/home/jovyan/work \
oboberg/astroml start.sh jupyter lab
To build the Docker image yourself do the following after cloning this repository.
$ docker build -t "astroml" .
When the Docker image is finished building, run the following command to start
a docker container and a jupyter notebook. Note that the $PWD
where this
command is run will mounted inside the docker container.
$ docker run -it --rm \
-p 8888:8888 \
-v $PWD:/home/jovyan/work \
astroml