Code
= input("Enter your name: ")
user_name print("How's it, " + user_name + "!")
Unit 2
It is time that we start introducing the coding environment we will use for programming during this course.
cd $SCIPRO
conda activate scipro2025
jupyter-lab
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.
testenv
without specifying a python version for it, and also install the packages ipython
and numpy
into the environment. Do not yet activate it.conda --help
in the terminal and examine the available conda commands.conda info --help
and read the documentation.conda info
to display a list of all environments currently installed on your computer.
testenv
.testenv
. Use conda --help
to find the correct command!testenv
. Make sure that no environment is activated anymore (i.e., no parentheses with an environment name are displayed before your command line).testenv
by running conda remove -n testenv --all
.Open a new python file by clicking on the blue button with a + on the top left and then select Python File.
solar_elev_angle_latitudes.py
.02_unit
.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.
Write a program that computes and plots the solar elevation angle for Sept 16, 2023 at noon true local time (i.e., tau = 0
, delta = 2.86
) for all latitudes from the equator to the north pole in 5\(^\circ\) intervals. Use version 3 of our second program (in the slide deck First steps in python) to guide you.
Execute your program line-by-line using the python interpreter (python console) in JupyterLab. Then execute your program from the terminal in JupyterLab.
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.
Write a program that uses the input
function to prompt a user for their name, record it in a variable called user_name
, and then welcome them. The output should look like
Enter your name: Florian
How's it, Florian!
Since this program requires interactive user input, I suggest you execute it from the terminal in JupyterLab. Afterwards, also try to run it in an ipython session, and try to execute it with a console attached to your .py
script.
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.
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.
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.
While connected to FHV network or VPN, you can access the FHV JupyterLab web instance at https://jupyter.labs.fhv.at. Use your username without the domain part to log in.