Assignment #06#
Exercise #06-01: ACINN meteorological data#
This exercise will give you a glimpse of working with pandas. Pandas can be a rather powerful tool with many more functionalities, just have a look at the documentation.
We are going to analyze a dataset downloaded from the ACINN department database. The one-month long dataset is from the automatic weather station TAWES UIBK. Here you can find a description of the variable names.
You can access the dataset at the URL shown below. Data downloaded from the department database are formatted as csv files, which we can read in easily using pandas. You may want to read the documentation of read_csv to see what all the arguments do.
from urllib.request import Request, urlopen
from io import BytesIO
import pandas as pd
url = 'https://raw.githubusercontent.com/manuelalehner/scientific_programming/master/data/data_Ibk_Jul2026.csv'
# Parse the given url
req = urlopen(Request(url)).read()
# Read the data
data = pd.read_csv(BytesIO(req), sep=';', header=1, index_col=0, parse_dates=True)
The data are read into a so-called DataFrame, which can be very useful for time series analysis, e.g., from weather stations. Let’s explore this DataFrame somewhat to get you started.
data.columns # list all the column headers
Index(['tl', 'tl2', 'ts', 'tb1', 'tb2', 'tb3', 'tp', 'rf', 'rf2', 'rr', 'rrm',
'p', 'som', 'glom', 'ffamm', 'ffm', 'ddm', 'ffxm', 'ddxm'],
dtype='str')
data['som'] # access the data column 'som' (sunshine duration)
rawdate
2026-07-01 00:00:00 0.0
2026-07-01 00:01:00 0.0
2026-07-01 00:02:00 0.0
2026-07-01 00:03:00 0.0
2026-07-01 00:04:00 0.0
...
2026-07-31 23:55:00 0.0
2026-07-31 23:56:00 0.0
2026-07-31 23:57:00 0.0
2026-07-31 23:58:00 0.0
2026-07-31 23:59:00 0.0
Name: som, Length: 44598, dtype: float64
data.index # access the datetime index
DatetimeIndex(['2026-07-01 00:00:00', '2026-07-01 00:01:00',
'2026-07-01 00:02:00', '2026-07-01 00:03:00',
'2026-07-01 00:04:00', '2026-07-01 00:05:00',
'2026-07-01 00:06:00', '2026-07-01 00:07:00',
'2026-07-01 00:08:00', '2026-07-01 00:09:00',
...
'2026-07-31 23:50:00', '2026-07-31 23:51:00',
'2026-07-31 23:52:00', '2026-07-31 23:53:00',
'2026-07-31 23:54:00', '2026-07-31 23:55:00',
'2026-07-31 23:56:00', '2026-07-31 23:57:00',
'2026-07-31 23:58:00', '2026-07-31 23:59:00'],
dtype='datetime64[us]', name='rawdate', length=44598, freq=None)
Write a script that allows the user to provide the variable (e.g., air temperature, wind speed, …) as a command-line argument and that prints the following information in the terminal. This time use the argparse package to parse the command-line arguments.
If the variable is wind direction:
The dominant wind direction was {XX} ({XX}% of the time). The least dominant wind direction was {XX} ({XX}% of the time).
If it is any other variable:
The maximum {VARIABLE} was {XX} {UNITS} ({DATE/TIME}), while the strongest {VARIABLE} averaged over an hour was {XX} {UNITS} ({DATE/TIME}).")
Hint 1: You can use either NumPy to determine, for example, the maximum values or you can work directly with the DataFrame. (e.g., calculating the maximum). To convert a column of the DataFrame to a NumPy array, you can use
temp = data['som'].to_numpy()
Hint 2: Calculating time averages is easy using the pandas resample method.
Hint 3: For wind direction, use the following eight wind direction classes: N, NW, W, SW, S, SE, E, NE.
Hint 4: To output the datetime index in a specific format, you can use the strftime method.
Excercise #06-02: Coding with the help of AI#
Using the same dataset as in #06-01, now write a Python module that reads in the csv file and calculates and plots the median diurnal cycle of user-specified variables and their inter-quartile range. The user should again be able to specify the variables as command-line arguments.
For this one exercise, you are encouraged to use AI as much as you like. The idea is that you use a chatbot (so no subscription necessary), but you are allowed to also use agentic coding if you have a subscription. If you don’t know what to use, you can try Academic AI, which is hosted in a data-secure environment.
You can decide how exactly you want to work with the AI agent, but try to document your workflow somewhat and think about the following questions:
How much of the result is your work and how much is the AI’s work?
Does the code do what it is supposed to do? How did you verify that?
Are there some special cases that the AI-generated code may have missed?
Does the AI-generated code add things that are unnecessary?
Do you fully understand the resulting code and what it does?
How much time did you spend on producing this code compared to, e.g., #06-01?