Executable Notebooks (Data Explorers)
Contents
Executable Notebooks (Data Explorers)¶
Welcome to the executable IPython notebook environment! We will be using the IPython notebooks for our lab class in neurophysiology. The IPython notebook is a very convenient way to interact with data using python.
Executable notebooks are ones that contain python scripts and functions that enable you to interact with and process the data you collect in lab. Some executable notebooks in this course (like this one) are tutorials that do not depend on collected data.
You will be interacting with these notebooks using Google’s Colaboratory server. Use the Open in Colab buttons to open the notebook in Colab.
Table of Contents¶
Setup¶
Throughout this course, most (probably all!) executable notebooks contain a section of setup cells. These cells will import the required Python packages (e.g., Pandas, NumPy); set global or environment variables, and load in helper functions for things like plotting.
Be sure to run all of the cells in the setup section. Feel free to expand them and have a look at what you are loading in, but you should be able to fulfill the learning objectives of every tutorial without having to look at these cells.
If you start building your own projects on this code base, you should look at them in more detail.
Form Fields¶
Some code cells contain forms with editable fields.
For example, the following code cell asks for your name. However, the form field will only be formatted correctly when you open it in Colab.
After filling in the form fields, running the code cell assigns each entries as a value to each variable (In this case, your name would be stored in the variable called name)
#@markdown This is a form field.
name = "insert your name between the quotation marks" #@param
Often, form fields will be hidden in the html version of the notebook on the course website.
For example, on the course website, you can only see the contents of the following form field if you click the “click to show” button.
#@title { display-mode: "form" }
#@markdown This is a form field.
name = "insert your name between the quotation marks" #@param
Code Cell Tasks¶
As described in Hidden Executable Scripts, some code cells contain scripts that are used to process your data and make calculations for results. You don’t need to look at the actual python scripts (but can if you want to by double clicking on the code cell). Instead, you are given tasks that say “run this code cell” or “enter information in this form field”. Follow these instructions and run the code cells as required.
Interactive Plots¶
Visually examining your data is a critical step in interpreting it. The executable notebooks in this course use plotly to produce plots with “zoom, pan, and save” buttons as well as pop-up information when the mouse hovers over the data. If you have this notebook open in Colab, you can execute the code cell below to try it out.
#@title { display-mode: "form" }
#@markdown Run this code cell to generate an example interactive plot.
import plotly.express as px
df = px.data.iris()
fig = px.scatter(df, x="sepal_width", y="sepal_length", color="species",
size='petal_length', hover_data=['petal_width'])
fig.show()
Written by Dr. Krista Perks for courses taught at Wesleyan University.