Temperatures¶
We have a number of temperatures measured on different dates for a set of automatic weather stations from Meteocat (Meteorological Service of Catalonia - meteocat.cat). For example:
>>> estL = ['Girona', 'Anglès', 'Olot', 'Farners']
>>> tempL = [
... ['09:01:2024', [(0.7, -6.4, 11.7), (3.3, -3.9, 10.2), (0.9, -6.7, 10.8), (2.6, -3.0, 11.3)]],
... ['08:01:2024', [(0.9, -7.2, 13.5), (2.3, -5.2, 13.0), (1.2, -6.1, 11.3), (3.3, -3.3, 13.0)]],
... ['07:01:2024', [(3.2, -4.8, 16.1), (3.9, -3.5, 14.5), (5.0, -1.9, 11.7), (4.8, -1.5, 17.4)]],
... ]
where we have two lists:
estLwhich is a list with the names of the station populations (str)
tempLwhich is a list of lists where each sublist contains two components:
Implement the following function in the tpt.py module (file tpt.py):
- tpt_sumup(estL, tempL)¶
such that
given
estL,tempLwhich arelistas described above,returns a
listwhere, for each date oftempLcontains a list with the following 4 data:
the date (
str)the average temperature (
float) of the average temperatures of all stations, rounded to 2 decimal places
tuple, with the minimum temperature of all minimums (float) and the station thestrcomes from. In the event that the minimum of the minimums has been given with more than one station, the first one that appears in the list must be returned.the same for the maximum temperature.
For example, given the input lists in the example above, the correct list to return would be:
>>> tmo_corr = [
... ['09:01:2024', 1.88, (-6.7, 'Olot'), (11.7, 'Girona')],
... ['08:01:2024', 1.92, (-7.2, 'Girona'), (13.5, 'Girona')],
... ['07:01:2024', 4.22, (-4.8, 'Girona'), (17.4, 'Farners')],
... ]
The doctests are available in tpt_sumup-test.txt.
Note
We recommend to implement and call an axiliar function such that, given a list of temperatures like the second component of tempL returns the following five data:
the average of all the temperature averages
the minimim of all the temperature minimums
the index of that minimum
the maximum of all the temperature maximums
the index of that maximum