A quick overview of why to use and how to set up iPython notebooks for research

55
ipython notebook from scratch. for realsies.

description

A quick overview of why to use and how to set up iPython notebooks for research in the Amaral lab. Example notebook is a gist at: http://nbviewer.ipython.org/gist/anonymous/f8e6d8985d2ea0e4bab1

Transcript of A quick overview of why to use and how to set up iPython notebooks for research

Page 1: A quick overview of why to use and how to set up iPython notebooks for research

ipython notebookfrom scratch. for realsies.

Page 2: A quick overview of why to use and how to set up iPython notebooks for research

Some basic information to start withiPython notebook is a part of the iPython package (iPython is an improved command line interpreter)

Page 3: A quick overview of why to use and how to set up iPython notebooks for research

Some basic information to start withiPython notebook is a part of the iPython package (iPython is an improved command line interpreter)

iPython notebook is young, it’s at v2.1 right now.

Page 4: A quick overview of why to use and how to set up iPython notebooks for research

Some basic information to start withiPython notebook is a part of the iPython package (iPython is an improved command line interpreter)

iPython notebook is young, it’s at v2.1 right now.

Only 1 year ago, iPython notebook was at v0.11

Page 5: A quick overview of why to use and how to set up iPython notebooks for research

Some basic information to start withiPython notebook is a part of the iPython package (iPython is an improved command line interpreter)

iPython notebook is young, it’s at v2.1 right now.

Only 1 year ago, iPython notebook was at v0.11

In any case iPython notebook has pretty much become *the* tool for data analysis and analysis sharing on the inter webs

Page 6: A quick overview of why to use and how to set up iPython notebooks for research

Why is that?

Page 7: A quick overview of why to use and how to set up iPython notebooks for research

Why is that?Easy - Like using the interactive interpreter but now there is the ability to edit, fix, and refactor code.!

Page 8: A quick overview of why to use and how to set up iPython notebooks for research

Why is that?Easy - Like using the interactive interpreter but now there is the ability to edit, fix, and refactor code.!

Shareable - Easily exported, results are in-line with the page so that it’s easy to see how code turns out.!

Page 9: A quick overview of why to use and how to set up iPython notebooks for research

Why is that?Easy - Like using the interactive interpreter but now there is the ability to edit, fix, and refactor code.!

Shareable - Easily exported, results are in-line with the page so that it’s easy to see how code turns out.!

Documented - The code and results are both there without necessitating that someone else run it first!

Page 10: A quick overview of why to use and how to set up iPython notebooks for research

Why is that?Easy - Like using the interactive interpreter but now there is the ability to edit, fix, and refactor code.!

Shareable - Easily exported, results are in-line with the page so that it’s easy to see how code turns out.!

Polyglot - Something works better with bash? R? Ruby? Perl? No problem, run it from iPython notebook!

Documented - The code and results are both there without necessitating that someone else run it first!

Page 11: A quick overview of why to use and how to set up iPython notebooks for research

Interactive demo time

Page 12: A quick overview of why to use and how to set up iPython notebooks for research

The basics with an assumption of pyenv

We’ll assume you have the basics, now do: $  pyenv  virtualenv  2.7.6  notebook  $  pyenv  global  notebook  $  pip  install  ipython  pyzmq  tornado    

(Using pip then using ipython will install notebook too!)

Page 13: A quick overview of why to use and how to set up iPython notebooks for research

The basics with an assumption of pyenv

We’ll assume you have the basics, now do: $  pyenv  virtualenv  2.7.6  notebook  $  pyenv  global  notebook  $  pip  install  ipython  pyzmq  tornado    

(Using pip then using ipython will install notebook too!)

Or follow this handy blog post:

http://amaral-lab.org/blog/i-wish-i-knew-then-what-i-know-now-lab-notebooks-a

Page 14: A quick overview of why to use and how to set up iPython notebooks for research

So how can I use this…Start me up on the command line now $  ipython  notebook  

Page 15: A quick overview of why to use and how to set up iPython notebooks for research

So how can I use this…Start me up on the command line now $  ipython  notebook  

Navigate to localhost:8888 in your preferred web browser

Page 16: A quick overview of why to use and how to set up iPython notebooks for research

So how can I use this…Start me up on the command line now $  ipython  notebook  

Navigate to localhost:8888 in your preferred web browser

VOILA!

Page 17: A quick overview of why to use and how to set up iPython notebooks for research

So how can I use this…From the web interface you can create a new notebook

Page 18: A quick overview of why to use and how to set up iPython notebooks for research

So how can I use this…From the web interface you can create a new notebook

Page 19: A quick overview of why to use and how to set up iPython notebooks for research

So how can I use this…From the web interface you can create a new notebook

Folders have to be created on the filesystem (terminal or nautilus/finder)

Page 20: A quick overview of why to use and how to set up iPython notebooks for research

So what is the best way to use this?

Data Exploration

Page 21: A quick overview of why to use and how to set up iPython notebooks for research

So what is the best way to use this?

Data Exploration

Learning new libraries/techniques

Page 22: A quick overview of why to use and how to set up iPython notebooks for research

So what is the best way to use this?

Data Exploration

Learning new libraries/techniques

Documenting code/workflow/results

Page 23: A quick overview of why to use and how to set up iPython notebooks for research

So what is the best way to use this?

Data Exploration

Learning new libraries/techniques

Trying different visualizations

Documenting code/workflow/results

Page 24: A quick overview of why to use and how to set up iPython notebooks for research

So what is the best way to use this?

Data Exploration

Learning new libraries/techniques

Trying different visualizations

Documenting code/workflow/results

Looking at small/modular parts

Page 25: A quick overview of why to use and how to set up iPython notebooks for research

What is not a good way to use it?

Greater than 15-20 images in a single notebook

Page 26: A quick overview of why to use and how to set up iPython notebooks for research

What is not a good way to use it?

Greater than 15-20 images in a single notebook

Poor programming practices(i.e. no functions or modules)

Page 27: A quick overview of why to use and how to set up iPython notebooks for research

What is not a good way to use it?

Greater than 15-20 images in a single notebook

Poor programming practices(i.e. no functions or modules)

Extensive amounts of *production* code (Think hundreds or thousands of lines)

Page 28: A quick overview of why to use and how to set up iPython notebooks for research

So how can I set this up…

Holy crap! So many ways!

Page 29: A quick overview of why to use and how to set up iPython notebooks for research

So how can I set this up…

Holy crap! So many ways!

As a one-off as described!

Page 30: A quick overview of why to use and how to set up iPython notebooks for research

So how can I set this up…

Holy crap! So many ways!

As a one-off as described!

As a server!

Page 31: A quick overview of why to use and how to set up iPython notebooks for research

So how can I set this up…

Holy crap! So many ways!

As a one-off as described!

As a server!

As a constantly updating resource!

Page 32: A quick overview of why to use and how to set up iPython notebooks for research

Initial caveats first

iPython notebook currently has no method of handling two individuals editing the same notebook simultaneously

Page 33: A quick overview of why to use and how to set up iPython notebooks for research

As a one-offSimply do: $  ipython  notebook  

Page 34: A quick overview of why to use and how to set up iPython notebooks for research

As a one-offSimply do: $  ipython  notebook  

The cool thing is that iPython notebook can now traverse directories

Page 35: A quick overview of why to use and how to set up iPython notebooks for research

As a one-offSimply do: $  ipython  notebook  

The cool thing is that iPython notebook can now traverse directories

So *ANY* directory that is a child of the directory where you start the service you can reach it!

Page 36: A quick overview of why to use and how to set up iPython notebooks for research

As a one-offSimply do: $  ipython  notebook  

The cool thing is that iPython notebook can now traverse directories

So *ANY* directory that is a child of the directory where you start the service you can reach it!

But! While iPython notebook can create notebooks from the web page it can’t create folders

Page 37: A quick overview of why to use and how to set up iPython notebooks for research

As a one-off

So this is pretty simple then, you can embed the ipython notebooks in your project directories and navigate to them from your project root $  cd  ~  

$  nohup  ipython  notebook  &  

!

Now navigate to the project code in the browser

Page 38: A quick overview of why to use and how to set up iPython notebooks for research

But I have to keep switching computers

…and I can’t remember to keep committing repositories.

Page 39: A quick overview of why to use and how to set up iPython notebooks for research

But I have to keep switching computers

…and I can’t remember to keep committing repositories.

BAM! Solution!

Page 40: A quick overview of why to use and how to set up iPython notebooks for research

But I have to keep switching computers

…and I can’t remember to keep committing repositories.

BAM! Solution!

Make one folder for ipython notebooks in dropbox!

Page 41: A quick overview of why to use and how to set up iPython notebooks for research

But I have to keep switching computers

…and I can’t remember to keep committing repositories.

BAM! Solution!

Make one folder for ipython notebooks in dropbox!

But how do I have ipython notebook start in dropbox?

Page 42: A quick overview of why to use and how to set up iPython notebooks for research

Creating a custom startup directory

Create your profile $  ipython  profile  create  

$  vi  ~/.ipython/profile_default/ipython_notebook_config  

Change line 551 from: #c.NotebookManager.notebook_dir  =  u’’  

to: c.NotebookManager.notebook_dir  =  \     u’/home/staff/$USER/Dropbox/Notebooks/’  

Page 43: A quick overview of why to use and how to set up iPython notebooks for research

Kick it up a notch

What if I told you about a world where you could always access your programming environment so long as you had internet?

Page 44: A quick overview of why to use and how to set up iPython notebooks for research

Kick it up a notch

What if I told you about a world where you could always access your programming environment so long as you had internet?

Or refer to your graphs?

Page 45: A quick overview of why to use and how to set up iPython notebooks for research

Kick it up a notch

What if I told you about a world where you could always access your programming environment so long as you had internet?

Or refer to your graphs?

Or show your partners/collaborators?

Page 46: A quick overview of why to use and how to set up iPython notebooks for research

Make a server!

Okay, but hold on there. Here is the HUGE

NUMBER

ONE

RULE

Page 47: A quick overview of why to use and how to set up iPython notebooks for research

Make a server!

YOU MUST PASSWORD PROTECT IT!

Page 48: A quick overview of why to use and how to set up iPython notebooks for research

Make a server!

YOU MUST PASSWORD PROTECT IT!

AND NOT WITH YOUR USER PASSWORD!

Page 49: A quick overview of why to use and how to set up iPython notebooks for research

Make a server!

YOU MUST PASSWORD PROTECT IT!

AND NOT WITH YOUR USER PASSWORD!

MAKE IT A VERYYYY LONG PASSPHRASE

Page 50: A quick overview of why to use and how to set up iPython notebooks for research

So let’s make a password

Open iPython from your command line (NOT the regular python interpreter!) $  ipython

From Thomas Sileo’s blog

Page 51: A quick overview of why to use and how to set up iPython notebooks for research

So let’s make a password

Open iPython from your command line (NOT the regular python interpreter!) $  ipython

From Thomas Sileo’s blog

Page 52: A quick overview of why to use and how to set up iPython notebooks for research

Now set up the profile WITH the password

From Thomas Sileo’s blog

Page 53: A quick overview of why to use and how to set up iPython notebooks for research

Now set up the profile WITH the password

From Thomas Sileo’s blog

Page 54: A quick overview of why to use and how to set up iPython notebooks for research

And start that baby up!

Neat idea:Use the server with the notebook directory in your dropbox.

Page 55: A quick overview of why to use and how to set up iPython notebooks for research

And start that baby up!

Neat idea:Use the server with the notebook directory in your dropbox.

Just copy new data files into dropbox and bam! instant transfer and analysis.