JupyterLab
Unit 2
JupyterLab
It is time that we start introducing the coding environment we will use for programming during this course.
This series of terminal commands will open the coding environment JupyterLab for you. It is a web-based application that starts a new internet browser window. While JupyterLab is running out of your terminal, you won’t be able to use the terminal anymore for any other tasks. That is ok, though, because you will have plenty of options to work with using the JupyterLab graphical user interface in your browser.
We will now slowly start to get familiar with the capabilities that JupyterLab offers us by doing some exercises.
The terminal within JupyterLab
Writing and executing a python program with JupyterLab
Open a new python file by clicking on the blue button with a + on the top left and then select Python File.
- Rename the file using the GUI (graphical user interface) of JupyterLab:
solar_elev_angle_latitudes.py
. - Create a new directory (also using the GUI) and call it
02_unit
. - Move the python file into the new directory.
Now, we want to make use of a special feature that JupyterLab offers us. We can connect the python file with a python interpreter. To do so, click into the python file editor to activate it and then select File > Create Console for Editor.
A new popup window opens. You can just go ahead with the suggestion made by the window and start a Python 3 kernel.
In the following screenshot, I have copy-pasted our 4th version program of the solar elevation angle into the python file:
Move your cursor to the first line that imports numpy. Then press [Shift+Enter]
. The line gets executed by the python console below!
Similarly, if you highlight several lines of code and hit [Shift+Enter]
, the highlighted block of code gets executed.
In addition to executing commands from your python file, you can also use the prompt at the python console to execute commands. Analogously, use [Shift+Enter]
to execute a command.
We will get to advanced plotting of visuals in more detail later in the course. For now, though, try using the command plt.show()
instead of plt.savefig()
whenever you don’t want to save a PNG file, but when you want to display the figure within the python console in JupyterLab.
The input
function will always record user input into a string, even if the user types a number. If you asked for numeric input, make sure to convert the str
to int
or float
before you do any calculations.
Using JupyterLab through an FHV web interface
FHV provides a web interface for all students to run JupyterLab sessions with python and all standard libraries pre-installed. All you need is a FHV user account and either a FHV PC in one of the computer pools or your own laptop with an internet and VPN connection to the FHV network.
FHV web interface JupyterLab
You can access the FHV JupyterLab web instance at https://jupyter.labs.fhv.at. Use your username without the domain part to log in.
Connecting to the FHV VPN
To access the FHV JupyterLab web instance you need to be connected to the FHV network directly or via VPN. You can find instructions for how to establish a VPN connection here.
Learning checklist
- I know how to use Jupyter-lab as coding environment on my own computer or the FHV computer pool.
- I can access the terminal within Jupyter-lab, create a python file, and attach an ipython console to the current script. This allows me to interactively write and execute python code.