Introduction to JupyterLab on CopPhil

JupyterLab on CopPhil gives you access to a Linux instance on which JupyterLab is running. There, you can, among others:

  • execute Python commands found in Jupyter notebooks,

  • edit text files,

  • temporarily store data

In this article, we will cover how to get started with JupyterLab on CopPhil.

Prerequisites

No. 1 Account

You need a CopPhil account. See Register and create a new account on CopPhil

No. 2 Access to JupyterLab

JupyterLab used in this article is available here: https://jupyter.infra.copphil.philsa.gov.ph/hub/login?next=%2Fhub%2F.

What We Are Going To Cover

  • Accessing JupyterLab

  • Creating a Python Jupyter notebook from Launcher

  • Using cells in a Jupyter notebook

    • Entering Markdown text

    • Running sample Python code

  • Reopening the Launcher

  • Accessing file browser

  • Using Linux terminal

  • Installing packages from pip

  • Restarting Jupyter kernel

  • Lifecycle of JupyterLab instances and storage

    • What is kept?

    • What is deleted?

Accessing JupyterLab

Navigate to https://jupyter.infra.copphil.philsa.gov.ph/hub/login?next=%2Fhub%2F. You are greeted with the following screen:

../_images/Screenshot_20241108_122242.png

Click on Access JupyterLab. Enter you credentials for CopPhil site:

../_images/Screenshot_20241108_122445.png

You should be prompted to choose size of server which you want to use:

../_images/introduction-to-jupyterlab-01_copphil.png

Click Click to start verification to pass the captcha test.

Depending on your quota, you might see more flavor(s) here.

Either way, for now choose the smallest server size possible and click Start:

../_images/introduction-to-jupyterlab-28_copphil.png

Wait up to a couple of minutes until your server starts.

../_images/introduction-to-jupyterlab-29_copphil.png

Eventually, you should see the interface of JupyterLab.

../_images/introduction-to-jupyterlab-02v2-1.png

By default, only one tab should be opened - the Launcher which includes functionality such as creating a new notebook or starting a Linux terminal.

Creating a Python Jupyter notebook from Launcher

To create a Python notebook, click Python 3 (ipykernel) in the Launcher.

../_images/introduction-to-jupyterlab-03_copphil.png

This should create a file named Untitled.ipynb:

../_images/introduction-to-jupyterlab-04_copphil.png

.ipynb is the standard extension for Python Jupyter notebooks.

To rename the file and save its contents, click floppy disk icon:

../_images/introduction-to-jupyterlab-05_copphil.png

Enter the name of your choice, for example Data processing.ipynb and press Rename:

../_images/introduction-to-jupyterlab-06_copphil.png

Click this floppy disk icon each time you want to save your file.

Using cells in Jupyter notebook

Python Jupyter notebooks consist of cells. Each cell can have one of the following data types:

Code

The default type. Allows you to enter code which can then be executed and its output displayed in that cell.

Markdown

Allows you to write text and format it using Markdown. You can even use LaTeX for mathematical formulas. Useful for providing comments and explanations to the code and its output.

Raw

Plain text cells. They cannot be executed but are useful to store notes or raw content. They are rarely used, and therefore we will concentrate on Markdown and Code cells in the remainder of this article.

Entering Markdown text

The toolbar contains a drop-down menu which allows you to choose type of the chosen cell. To write Markdown text, choose Markdown from that drop-down menu:

../_images/introduction-to-jupyterlab-24_copphil.png

You can now write Markdown code, for example:

../_images/introduction-to-jupyterlab-25_copphil.png

To apply Markdown formatting, press Shift+Enter on your keyboard. Alternatively, you can click the play icon on the toolbar.

../_images/introduction-to-jupyterlab-26_copphil.png

Either way, the text should be formatted:

../_images/introduction-to-jupyterlab-27_copphil.png

Running sample Python code

Below that Markdown text you’ve just added another cell appeared. By default, it is of type Code. Let’s use it to verify that Python works.

Click on that cell and enter an example command, for example:

print("Hello world")
../_images/introduction-to-jupyterlab-07_copphil.png

Again, press Shift+Enter on your keyboard or click the play icon on the toolbar to execute that code.

../_images/introduction-to-jupyterlab-23_copphil.png

The notebook should display the output of command:

../_images/introduction-to-jupyterlab-08_copphil.png

Reopening the Launcher

To reopen the Launcher (for example to open another file), click the plus icon near the top left corner of the website:

../_images/introduction-to-jupyterlab-09_copphil.png

Accessing file browser

The left bar has the following functions:

  • File Browser

  • Running Terminals and Kernels

  • Table of Contents

  • Extension Manager

The first button corresponds to File Browser:

../_images/introduction-to-jupyterlab-10_copphil.png

You should now see the contents of your home directory.

../_images/introduction-to-jupyterlab-11_copphil.png

The path from your home folder to your current working directory should be displayed below the text field Filter files by name

To navigate to a folder, double-click on it:

../_images/introduction-to-jupyterlab-12_copphil.png ../_images/introduction-to-jupyterlab-13_copphil.png

To open an existing file in new tab, double-click on it:

../_images/introduction-to-jupyterlab-14_copphil.png ../_images/introduction-to-jupyterlab-15_copphil.png

Using Linux terminal

You can also access the Linux terminal which is running on the JupyterLab instance you are using.

It can be used, among others, for:

  • file management

  • git and version control

  • downloading files with wget

  • running scripts

  • installing pip packages

From the Launcher, in section Other, click Terminal:

../_images/introduction-to-jupyterlab-16_copphil.png

You should now see the terminal:

../_images/introduction-to-jupyterlab-17_copphil.png

To test it, you can execute the command ls:

../_images/introduction-to-jupyterlab-18_copphil.png

Installing packages from pip

You can install packages using pip either from the terminal or from your notebook.

In both cases, you can install them with a command like this:

pip install packagename

where packagename is the name of package you want to install. See section Restarting Jupyter kernel to learn more.

If the package is not visible after installation, restart Jupyter kernel.

Example 1: Installing package in terminal

In this example, we install pandas, which is a Python library used in data analysis.

../_images/introduction-to-jupyterlab-19_copphil.png

Example 1: Installing package in notebook

In this example, we install boto3, which is a Python library used to, among others, interact with S3 storage.

../_images/introduction-to-jupyterlab-20_copphil.png

Restarting Jupyter kernel

The term kernel here does not refer to the kernel of the operating system you are using, but to piece of software which runs commands from your notebooks.

Restarting that kernel means that you lose all variables you set.

To restart Jupyter kernel, first make sure that you are in a file which uses that Kernel. Then, from menu Kernel found on top of the web site click Restart Kernel…

../_images/introduction-to-jupyterlab-21_copphil.png

You should get question similar to this:

../_images/introduction-to-jupyterlab-22_copphil.png

Click Restart to confirm.

Lifecycle of JupyterLab instances and storage

On CopPhil, each JupyterLab instance remains running while the user is active on it, as well as an additional 8 hours.

After that, you need to create another JupyterLab instance.

What is kept?

All data stored in folder mystorage which is located in your home directory is kept for 15 days after last login. They will be available on your next instance.

What is deleted?

All files outside of mystorage folder are deleted. This includes any packages installed with pip - you will need to reinstall them on the new instance.

What To Do Next

Additional details about JupyterLab environment:

Python 3 kernel and Geo science kernel in JupyterLab on CopPhil

Using tokens for API access to JupiterLab on CopPhil

To learn how to access EODATA using Python, check Download satellite data using API on CopPhil

Use CopPhil JupyterLab and Python to find all Sentinel 2 products over Manila in 2024