Since last week you have learned two important new concepts: unit testing and exceptions handling. In today's assignment we will revisit last week's code in order to properly test it and make it more robust.
In exercise #03-02 we will learn the basics of numpy and matplotlib in order to display live meteorological data.
Note: for these exercises you are allowed to use the numpy and matplotlib libraries only! No external module is allowed (with the exception of the standard library of course).
test_*.py
file per module). The test suite must contain unit tests for each function you programmed (I myself wrote 4 functions for exercise #02-01 and 3 for exercise #02-02).numpy and matplotlib are two fundamental pillars of the scientific python stack. You will find numerous tutorials for both libraries online. I am asking you to learn the basics of both tools by yourself, at the pace that suits you. Personally I recommend to follow these two tutorials from the Scipy Lecture Notes for a start:
The institute website provides live visualization of meteorological data: http://acinn.uibk.ac.at/current-weather/innsbruck-university . The raw data used for the plots are available in a live feed at the following addresses:
The data for the other stations are available, per analogy:
The data is shared by ACINN under a Creative Commons Attribution-ShareAlike 4.0 International License.
The data is provided in the json format, often used for web applications. Fortunately, this is very easy to read in python:
from urllib.request import Request, urlopen
import json
url = 'http://acinn.uibk.ac.at/innsbruck/3'
# Parse the given url
req = urlopen(Request(url)).read()
# Read the data
data = json.loads(req.decode('utf-8'))
Now I will help you to parse the timestamp of the data:
from datetime import datetime, timedelta
data['time'] = [datetime(1970, 1, 1) + timedelta(milliseconds=ds) for ds in data['datumsec']]
And make a first plot to get you started:
%matplotlib inline
import matplotlib.pyplot as plt
plt.plot(data['time'], data['tl']);
Your main task is to write a script that accepts three arguments: station name, variable name, and a number of days (3 or 7, defaults to 3). The variable name might be of: ['temperature', 'dewpoint_temperature', 'relative_humidity', 'windspeed', 'winddirection', 'pressure', 'precipitation', 'sunshine_duration']
. The script then displays a plot of the desired variable. The plot must contain the following information: variable name, variable description, unit. If the variable is not available, the script must print a warning and exit.
Here are some hints to get you started:
'description'
and 'units'
. A possible way to organize your data would be with the help of nested dictionaries.Based on the data from exercise #03-02, write a function that prints the following information in the terminal:
At station XXX, over the last 3 days, the dominant wind direction was XX (xx% of the time). The second most dominant wind direction was XX (xx% of the time), the least dominant wind direction was XX (xx% of the time). The maximum wind speed was XX m/s, while the strongest wind speed averaged over an hour was XX m/s.
With the wind directions being of 8 classes: N, NW, W, SW, S, SE, E, NE.
Back to the table of contents