Lab Notebook - Example
Alan DeWeerd (1/2/17)
Notes
You can also enter a superset of HTML in a "Markdown" cell, which gives more control over formatting and tends to look better. (See basic commands and syntax). Double-click this cell to edit it.
Headings
Headings are very useful for labeling sections. There are no longer "Heading" cells. To make a heading (like above), use a "Markdown" cell and start with "#" for a top level heading, "##" for a second level heading, etc. Note that you must leave a space between "#" and the heading text.
Equations
Equations can also be included using LaTeX commands. There is a brief tutorial on typesetting math with LaTeX, which has a link to more documentation. In a "Markdown" cell, LaTeX commands between dollar signs ($) appear inline with text and LaTeX commands between pairs of dollar signs ($$) appear on a separate line (called a display equation). When you run the cell to display the equation, the latex command is hidden. The LaTeX commands can be edited by double clicking on the cell.
An example of an inline equation is , and a display equation is
Images
If you import the "Image" function (only needs to be done once), it can be used to include .jpg or .png files. Image files should be in the same folder as the notebook. The "width" argument can be used to adjust the size of the image.
You can using a drawing program, such as "Paint" on Windows, to make simple notations on a figure before including it.
Calculations
You can use "Code" cells to perform calculations. This works well because it shows how you did the calculation. For example:
For calculations, you should:
Data Tables
If you import the "panda" package (only needs to be done once), you can read an ASCII data file and display the contents in a table.
The default for pandas is comma seperated values. The first line should contain headers (also comma separated) for the columns on the lines below. The file "test.dat" contains the following:
# t (s), V (mV) 0.1, 1 0.2, 2 0.3, 4
You can make the "read_csv" command ignore the number symbol (#) using the "escapechar" argument. The "#" at the start of the header line is useful because it is easy to make the "loadtxt" command (see the graphing example below) treat it as a comment. The row numbers (starting with zero) always appear in the first column of the table.
Often data is seperated by spaces, not commas. The file "test2.dat" contains the following:
# t(s) V(mV) 0.1 1 0.2 2 0.3 4
In this case, the "read_csv" has to be told that the separators are spaces. It's simpler to leave the spaces out of the column headers.
You should give your files more descriptive names. You can also add extra comment lines at the top of file and have "read_csv" ignore them using the "skiprows" arugment. The file "test3.dat" contains the following:
\# Measurements for charging a capacitor in an RC circuit
\# The time is measured from when the switch was closed
\# R = 0.97 k-ohm, C = 0.1 micro-F
\# t(s) V(mV)
0.1 1
0.2 2
0.3 4
Graphs
Often, you'll want to make a plot of data that you've taken. There are tutorials on reading data files and making plots with Python.
The example below shows how to read in data and make a scatter plot of it. Note that the "loadtxt" command, which is part of the "numpy" library, expects spaces between entries as in "test2.dat". It also ignores all lines that start with "#". The graphing commands in the "pylab" library.
For the comma separated values in "test.dat", the "delimiter" argument must be used to make the "loadtxt" command treat commas as the separators. Note that you don't really need to import the libraries a second time in a Jupyter notebook.
It is often useful to plot data points and a theoretical funciton in the same figure as shown below. Suppose that you expect that data to be described by the equation The following example plots both the data, as a scatter plot, and the theoretical equation, as a curve.