Using Jupyter Notebooks

How to use a Jupyter notebook

Executing code in a Notebook: Jupyter notebooks provide “cells” within which is typed either Python code or markdown language (for formatted text). Choose the cell to execute by clicking in it with the mouse (the cursor must be in the desired cell). Hold down the shift key and press either enter or return (depending on keyboard type), or click the ‘Play’ button in the notebook toolbar, and the contents of the cell will be executed. If the cell type is code, and the cell contains python code, the code will be executed. If the cell type is markdown, then it will be rendered upon execution to yield nicely formatted text. There is a user guide for markdown cells in the Jupyter Notebooks documentation.

See these instructions to create a new notebook with the LSST kernel.

Jupyter notebook cells can be executed out of order. This provides a degree of flexibility in executing Jupyter notebooks, but could also lead to errors if, for instance, a cell is executed before prior cells that define necessary functions and/or variables. If you’ve executed a notebook’s cells out of order and are concerned about having caused potential issues in doing so, you can restart the notebook’s kernel.

This image is a screenshot of a Rubin tutorial notebook. The notebook has been scrolled down to Section 3.3, which contains both markdown text and code cells which have been executed. The last code cell has produced a grayscale sky image.

A screenshot from an executed Rubin/LSST tutorial notebook. Multiple notebooks can be opened in separate tabs. You can monitor memory usage by checking the numbers listed after “Mem:” along the bottom gray bar of the RSP window.

Opening Multiple Notebooks: Multiple notebooks and terminals can be open at a time. Notebooks and/or terminal windows can be arranged next to or on top of each other by dragging the notebook or terminal around by the top bar. Arranging the windows can be convenient when working in both a terminal and notebook at the same time, or when using another notebook as a reference.

JupyterLab Autosaves Notebooks: Note that JupyterLab autosaves notebooks at a default interval of 2 minutes unless working in the directory “notebooks/tutorial-notebooks/”, which is read-only (see How to use the Tutorial Notebooks).

The JupyterLab Notebooks documentation has more information on creating and using notebooks.

How-to guides