Skip to content

Commit 3651700

Browse files
committed
Start at step 3
1 parent 3716747 commit 3651700

5 files changed

Lines changed: 44 additions & 166 deletions

File tree

content/code/python/initial-version-with-mean.py

Lines changed: 0 additions & 47 deletions
This file was deleted.

content/code/python/initial-version-with-precipitation.py

Lines changed: 0 additions & 68 deletions
This file was deleted.

content/code/python/initial-version.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,17 @@
2424
color="red",
2525
)
2626

27+
values = january["air_temperature_celsius"].values
28+
mean_temp = sum(values) / len(values)
29+
30+
# mean temperature (as horizontal dashed line)
31+
ax.axhline(
32+
y=mean_temp,
33+
label=f"mean air temperature (C): {mean_temp:.1f}",
34+
color="red",
35+
linestyle="--",
36+
)
37+
2738
ax.set_title("air temperature (C) at Helsinki airport")
2839
ax.set_xlabel("date and time")
2940
ax.set_ylabel("air temperature (C)")
@@ -34,3 +45,24 @@
3445
fig.autofmt_xdate()
3546

3647
fig.savefig("2024-01-temperature.png")
48+
49+
fig, ax = plt.subplots()
50+
51+
# precipitation time series
52+
ax.plot(
53+
january.index,
54+
january["precipitation_mm"],
55+
label="precipitation (mm)",
56+
color="blue",
57+
)
58+
59+
ax.set_title("precipitation (mm) at Helsinki airport")
60+
ax.set_xlabel("date and time")
61+
ax.set_ylabel("precipitation (mm)")
62+
ax.legend()
63+
ax.grid(True)
64+
65+
# format x-axis for better date display
66+
fig.autofmt_xdate()
67+
68+
fig.savefig("2024-01-precipitation.png")

content/solution.md

Lines changed: 5 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,24 @@ Learners can also explore some of these steps in one of the exercise sessions.
1818
## Checklist
1919

2020
- Start with notebook
21-
- Add statistics (mean temperature)
22-
- Add precipitation
2321
- Generalize from January to also February and March data
2422
- Abstract code into functions
2523
- Move from notebook to script
2624
- From functions with side-effects towards stateless functions
2725
- Initialize git
2826
- Add `requirements.txt`
29-
- Add test
27+
- Add test (optional)
3028
- Add command line interface
3129
- Show how a workflow solution could look
3230
- Split into multiple files/modules
3331

3432

3533
## Our initial version
3634

37-
We imagine that we assemble a working script/code
38-
from various internet research/ AI chat
35+
The initial version of our script for this exercise plots a series of
36+
temperatures and precipitations for **January** as well as
37+
the **mean temperature** averaged over the month. Suppose that we
38+
assemble a working script from various internet research/AI chat
3939
recommendations and arrive at:
4040

4141
:::::{tabs}
@@ -55,47 +55,6 @@ recommendations and arrive at:
5555
- We test it out **in a notebook**.
5656

5757

58-
## We add a dashed line representing the mean temperature
59-
60-
This is still only the January data.
61-
62-
:::::{tabs}
63-
::::{group-tab} Python
64-
:::{literalinclude} code/python/initial-version-with-mean.py
65-
:language: python
66-
:emphasize-lines: 27-36
67-
:::
68-
::::
69-
70-
::::{group-tab} R
71-
Work in progress. You can
72-
[help us](https://github.com/coderefinery/modular-type-along/issues/40)
73-
by contributing or improving an R solution.
74-
::::
75-
:::::
76-
77-
78-
## We add another plot for the precipitation
79-
80-
As a first go, we achieve this by copy pasting the existing code and adjusting
81-
it for the precipitation column.
82-
83-
:::::{tabs}
84-
::::{group-tab} Python
85-
:::{literalinclude} code/python/initial-version-with-precipitation.py
86-
:language: python
87-
:emphasize-lines: 49-68
88-
:::
89-
::::
90-
91-
::::{group-tab} R
92-
Work in progress. You can
93-
[help us](https://github.com/coderefinery/modular-type-along/issues/40)
94-
by contributing or improving an R solution.
95-
::::
96-
:::::
97-
98-
9958
## Plotting also February and March data
10059

10160
- Copy-pasting very similar code 6 times would be too complicated to maintain.

content/starting-point.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@ under the Creative Commons Attribution 4.0 International license (CC BY 4.0):
2020

2121
## Our starting point
2222

23-
Our initial goal for this exercise is to plot a series of temperatures and
24-
precipitations for **January** and to compute and plot the **mean temperature**
25-
averaged over the month. Suppose that we assemble a working script from
26-
various internet research/AI chat recommendations and arrive at:
23+
Our starting point for this exercise is a script which plots a series of
24+
temperatures and precipitations for **January** as well as
25+
the **mean temperature** averaged over the month. Suppose that we
26+
assemble a working script from various internet research/AI chat
27+
recommendations and arrive at:
28+
2729
:::::{tabs}
2830
::::{group-tab} Python
2931
:::{literalinclude} code/python/initial-version.py
@@ -44,7 +46,7 @@ languages in its place. For the Python experts: we will not see the most
4446
elegant Python.
4547

4648

47-
## Further goals
49+
## Goals
4850

4951
- Once we get this working for **January**, our task changes to also
5052
plot the **February** and the **March** in two additional

0 commit comments

Comments
 (0)