Assignment #01
Workshop 1
Assignment until next short online meeting (26.09.2024)
Carefully review the course material from today’s workshop. Ensure that conda, python, and our conda environment scipro2024
are installed and properly working on your laptop. Create a directory for our course, where you will put all the code and exercises (I refer to this directory as $SCIPRO
in the lecture material). Do the exercises embedded in the slide decks, if you haven’t done so in class.
In addition, do the following exercises until our workshop next week. No need to hand them in, but be prepared to present your code.
#01-01: conda
- Create a new conda environment
testenv
without specifying a python version for it, and also install the packagesipython
andnumpy
into the environment. Do not yet activate it. - Run
conda --help
in the terminal and examine the available conda commands. - Run
conda info --help
and read the documentation. - Use
conda info
to display a list of all environments currently installed on your computer.- How many environments are there?
- Where are they installed?
- Activate
testenv
. - Find out which version of python was installed in
testenv
. Useconda --help
to find the correct command! - Deactivate
testenv
. Make sure that no environment is activated anymore (i.e., no parentheses with an environment name are displayed before your command line). - Remove
testenv
by runningconda remove -n testenv --all
.
#01-02: The solar elevation angle
Write a program and save it as .py
file in the directory $SCIPRO/01_workshop/
. The program should compute and print the solar elevation angles 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 2 of our second program (in the slide deck First steps in python) to guide you. Use https://www.online-python.com/ to execute and test your program.
Assignment until workshop 2 (03.10.2024)
Group presentations
Starting to learn python comes with a steep learning curve. The concepts might be entirely new to you, and there’s a lot of them all at once! To get you up to speed, we will divide and conquer:
Form 4 groups. Each group will work on a set of tasks and prepare a 10-minute presentation. We will listen to the presentations during the second workshop. Please upload your presentation files to the ILIAS folder Abgaben/01_workshop
.
The goal of this exercise is for you to work in-depth on the tasks assigned to your group and elicit the most important take-home messages. Everyone will have to work through all the material eventually, but with your peer’s presentation to guide you this will be a lot faster and more effective!
Group 1: Variables, expressions, and statements
- Work through the online course Python for Everybody (PY4E) on Variables, expressions, ….
- Read Section 2.2.9 in the book by Linge and Langtangen (2020).
Group 2: Intro, conditional execution (part 1)
- Read the first half of the Introduction of the online course Python for Everybody (PY4E).
- From the beginning up to and including Computer hardware architecture, plus the Glossary
- Read the Python Syntax tutorial on indentation.
- Work through the PY4E chapter on Conditional execution.
- From the beginning up to and including Nested conditionals, plus the Glossary
- Read Sections 1.8.3–1.8.5 in the book by Linge and Langtangen (2020).
Group 3: Intro, conditional execution (part2)
- Read the second half of the Introduction of the online course Python for Everybody (PY4E).
- From Understanding programming up to and including the Glossary
- Read the Python Syntax tutorial on indentation.
- Work through the PY4E chapter on Conditional execution.
- From Catching exceptions … up to and including the Glossary
- Read Section 2.1 in the book by Linge and Langtangen (2020).
Group 4: Numpy arrays, strings
- Work through Section 2.3 in the book by Linge and Langtangen (2020).
- Read Sections 8.1, 8.2, 8.4, 8.5, 8.8, 8.9 in the e-book by Downey (2012).
Learning checklist
- I have a foundational understanding of variables, expressions, and math operations.
- I am aware of round-off errors when working with floating point numbers.
- I know the building blocks of programs.
- I have a strategy for debugging code that produces errors.
- I know that indentation plays a crucial role in coding python, and I know when and where to indent.
- I can use boolean expressions to test and compare variables.
- I can enchain boolean expressions using logical operators.
- I can handle exceptions gracefully using
try...except
statements. - I can implement conditional expressions using
if..elif..else
statements. - I can use guardian patterns to make my
if
statements more robust. - I can work with numpy arrays, particularly extracting elements by indexing and slicing.
- I can work with strings, particularly extracting elements similarly to arrays.
- I got to know some string methods and understand the difference between functions and methods.
- I know that I can apply methods with the dot notation.
- I know how to create a new conda environment and install packages into it. This will be particularly useful for setting up the correct environment for other classes and projects.