Getting started with Jupyter Notebooks#
Jupyter Notebooks have become a central tool of the scientific python ecosystem. The advantage of jupyter notebooks over traditional code scripts in text files is that they can include text, code, and plots in the same document. Notebooks are a fantastic tool to explore data or models and to communicate about science.
Notebooks are an ideal playground for learning python and write your homework, without having to jump between several documents! We will use notebooks for the entire class. In fact, this webpage (and all others in this book) are written in Jupyter Notebooks.
Running Notebooks for the climate class#
Testing the use of Jupyter online#
The simplest way to try using a notebook is to use the “Launch Binder” button on the top of each page. This will open an interactive session in your browser.
Warning
Interactive sessions on MyBinder are temporary. After 10 mins of inactivity or after closing the tab, you won’t be able to recover your changes.
For tutorials, this is perfect. For the exercises, I’d rather recommend to use your own laptop or the computer room.
Installing Jupyter on your computer#
If you did not follow my programming class last semester, follow these instructions to install python first. This will provide you with a (base)
environment with nothing but python installed.
Then, follow the instructions here to create a new environment called (climate)
. I’ll repeat the steps here:
mamba create -n climate
Which will create a new empty environment. Activate it with:
mamba activate climate
Once in this environment, install the packages we will need for this class:
mamba install jupyterlab numpy scipy matplotlib xarray netcdf4 cartopy
That’s it!
Installing Jupyter on your account in the computer room#
In the computer room, you will first have to request an account at ZiD. It can take some time (hours or days) to activate. Once you have an account, follow the instructions here.
Plan C#
If you are not able to run the notebooks on your laptop or on the computer room, I will give you access to an online platform that you can use for the rest of the semester.
Launching the Jupyterlab interface#
Jupyterlab is the most recent interface to write and run Jupyter Notebooks.
To start the jupyterlab interface, type the following command in a terminal window:
jupyter-lab
Jupyterlab runs in your browser. You can open a new notebook with the “launcher” button. You can explore files with the file explorer on the left.
Note
Do not close the terminal from which you started jupyterlab. This is where python is “actually” running: the browser only sends commands to this running instance of python in your terminal.
Download and run a notebook#
To run a notebook, you can:
click on the “download” button on the top right of each page and copy it in your working directory.
visit the book’s repository and download the files from there.
Then open the file either from notebook classic or jupyterlab.
What’s next#
You are now ready for the practicals! Head to the first notebook for your first steps.