Skip main navigation

New offer! Get 30% off one whole year of Unlimited learning. Subscribe for just £249.99 £174.99. New subscribers only. T&Cs apply

Find out more

CATE from Jupyter notebooks

Accessing Cate functionality from within Jupyter notebooks
© University of Twente

In the previous step, you learnt what CATE is. In this article, you will learn how to install the Jupyter notebook and call CATE functionalities from it and customise your processing chain if needed.

The Cate toolbox is built upon a python module and can be directly used from within Python. This allows CATE functionality to be called from so-called Jupyter notebooks which can be run and then viewed from any capable browser.

In this section, we will introduce Jupyter notebooks and show you how to install and run a notebook on your computer.

What are Jupyter notebooks?

A Jupyter notebook integrates code and its output into a single document that combines visualisations, narrative text, mathematical equations, and other rich media and separates them into so-called cells. It is a single document where you can run code, display the output, and also add explanations, formulas, charts, and make your work more transparent, understandable, repeatable, and shareable.

Jupyter notebooks and dashboards are web applications.

There are two items in the main menu that you should notice: cells and kernels. These are key to understanding Jupyter and to what makes it more than just a word processor.

A kernel is a “computational engine” that executes the code contained in a notebook document. A cell is a container for text to be displayed in the notebook or code to be executed by the notebook’s kernel. Cells form the body of a notebook. There are two main cell types:

  • A Code cell contains code to be executed in the kernel. When the code is run, the notebook displays the output below the code cell that generated it.
  • A Markdown cell contains text formatted using markdown and displays its output in-place when the cell is run. Your notebook essentially takes the markdown code and converts it into a snippet of HTML which your browser displays.

The difference between Code and Markdown cells is that code cells have a label on the left and Markdown cells do not. The “In” part of the label is simply short for “Input,” while the label number indicates when the cell was executed on the kernel. In a Jupyter Notebook, there is always one “active” cell highlighted with a border whose colour denotes its current mode:

  • Green outline — cell is in “edit mode”
  • Blue outline — cell is in “command mode”

To run a cell, press the Shift + Enter keys simultaneously, or select the cell and press the triangular play button on the dashboard. There are plenty of other commands we can use. The best way to use them is with keyboard shortcuts. Keyboard shortcuts are a very popular aspect of the Jupyter environment because they facilitate a speedy cell-based workflow. Many of these are actions you can carry out on the active cell when it’s in command mode.

Below, you’ll find a list of some of Jupyter’s keyboard shortcuts. You do not need to memorize them, but this list should give you a good idea of what’s possible.

  • Toggle between edit and command mode with Esc and Enter, respectively.
  • Once in command mode:
    • Scroll up and down your cells with your Up and Down keys.
    • Press ‘a’ or ‘b’ to insert a new cell above or below the active cell.
    • ‘m’ will transform the active cell to a Markdown cell.
    • ‘y’ will set the active cell to a code cell.
    • ‘d’ + ‘d’ (d twice) will delete the active cell.
    • ‘z’ will undo cell deletion.
    • Hold Shift and press Up or Down to select multiple cells at once. With multiple cells selected, Shift + ‘m’ will merge your selection.
  • Ctrl + Shift + -, in edit mode, will split the active cell at the cursor. If your keyboard has more than one key corresponding to -, and one zooms out instead of splitting cells, try using the other key.
  • You can also click and Shift + Click in the margin to the left of your cells to select them.

From the “Help” menu also additional information about the various keyboard shortcuts can be obtained.

Markdown is a lightweight and popular markup language which is a writing standard for data scientists and analysts. It is often converted into the corresponding HTML by the Markdown processor which allows it to be displayed in browsers and apps that understand HTML. One of the advantages of Markdown is that it’s plain text, and that, even when it’s not converted to HTML is still easily understandable and human-readable. For additional information on Markdown, see:

Behind every notebook runs a kernel. When you run a code cell, that code is executed within this kernel. Any output is returned to the cell to be displayed. The kernel’s state persists over time and between cells — it pertains to the document as a whole and not individual cells. This also means that the order of executing cells matters!

Most of the time when you create a notebook, the flow will be top-to-bottom. But it is common to go back to make changes. You can determine the order of execution by inspecting the label to the left of each cell, such as ‘In [6]’ (in front of a cell), which can help diagnose problems by seeing what order the cells have run in.

And if we ever wish to reset things, there are several useful options from the Kernel menu:

  1. Restart: restarts the kernel, thus clearing all the variables etc. that were defined.
  2. Restart & Clear Output: same as above but will also wipe the output displayed below your code cells.
  3. Restart & Run All: same as above but will also run all your cells in order from first to last.

If your kernel is ever stuck on computation and you wish to stop it, you can choose the Interrupt option.

Depending on the type of installation, Jupyter provides the option to change the kernel – programming languages. Many other languages, in addition to Python, may be used in the notebook. By creating a new notebook from the dashboard menu, by selecting Python, you are actually choosing which kernel to use. Note that, in this tutorial, we only consider Python notebooks.

Up next

In the next exercise, using your browser you will access, visualise and analyse climate records of satellite data using CATE SaaS.

© University of Twente
This article is from the free online

Understanding Climate Change using Satellite Data

Created by
FutureLearn - Learning For Life

Reach your personal and professional goals

Unlock access to hundreds of expert online courses and degrees from top universities and educators to gain accredited qualifications and professional CV-building certificates.

Join over 18 million learners to launch, switch or build upon your career, all at your own pace, across a wide range of topic areas.

Start Learning now