Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 0 additions & 47 deletions content/code/python/initial-version-with-mean.py

This file was deleted.

68 changes: 0 additions & 68 deletions content/code/python/initial-version-with-precipitation.py

This file was deleted.

32 changes: 32 additions & 0 deletions content/code/python/initial-version.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@
color="red",
)

values = january["air_temperature_celsius"].values
mean_temp = sum(values) / len(values)

# mean temperature (as horizontal dashed line)
ax.axhline(
y=mean_temp,
label=f"mean air temperature (C): {mean_temp:.1f}",
color="red",
linestyle="--",
)

ax.set_title("air temperature (C) at Helsinki airport")
ax.set_xlabel("date and time")
ax.set_ylabel("air temperature (C)")
Expand All @@ -34,3 +45,24 @@
fig.autofmt_xdate()

fig.savefig("2024-01-temperature.png")

fig, ax = plt.subplots()

# precipitation time series
ax.plot(
january.index,
january["precipitation_mm"],
label="precipitation (mm)",
color="blue",
)

ax.set_title("precipitation (mm) at Helsinki airport")
ax.set_xlabel("date and time")
ax.set_ylabel("precipitation (mm)")
ax.legend()
ax.grid(True)

# format x-axis for better date display
fig.autofmt_xdate()

fig.savefig("2024-01-precipitation.png")
51 changes: 5 additions & 46 deletions content/solution.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,24 @@ Learners can also explore some of these steps in one of the exercise sessions.
## Checklist

- Start with notebook
- Add statistics (mean temperature)
- Add precipitation
- Generalize from January to also February and March data
- Abstract code into functions
- Move from notebook to script
- From functions with side-effects towards stateless functions
- Initialize git
- Add `requirements.txt`
- Add test
- Add test (optional)
- Add command line interface
- Show how a workflow solution could look
- Split into multiple files/modules


## Our initial version

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

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


## We add a dashed line representing the mean temperature

This is still only the January data.

:::::{tabs}
::::{group-tab} Python
:::{literalinclude} code/python/initial-version-with-mean.py
:language: python
:emphasize-lines: 27-36
:::
::::

::::{group-tab} R
Work in progress. You can
[help us](https://github.com/coderefinery/modular-type-along/issues/40)
by contributing or improving an R solution.
::::
:::::


## We add another plot for the precipitation

As a first go, we achieve this by copy pasting the existing code and adjusting
it for the precipitation column.

:::::{tabs}
::::{group-tab} Python
:::{literalinclude} code/python/initial-version-with-precipitation.py
:language: python
:emphasize-lines: 49-68
:::
::::

::::{group-tab} R
Work in progress. You can
[help us](https://github.com/coderefinery/modular-type-along/issues/40)
by contributing or improving an R solution.
::::
:::::


## Plotting also February and March data

- Copy-pasting very similar code 6 times would be too complicated to maintain.
Expand Down
14 changes: 8 additions & 6 deletions content/starting-point.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ under the Creative Commons Attribution 4.0 International license (CC BY 4.0):
:::


## Our initial goal
## Our starting point

Our starting point for this exercise is a script which plots a series of
temperatures and precipitations for **January** as well as
the **mean temperature** averaged over the month. Suppose that we
assemble a working script from various internet research/AI chat
recommendations and arrive at:

Our initial goal for this exercise is to plot a series of temperatures and
precipitations for **January** and to compute and plot the **mean temperature**
averaged over the month. We imagine that we assemble a working script from
various internet research/ AI chat recommendations and arrive at:
:::::{tabs}
::::{group-tab} Python
:::{literalinclude} code/python/initial-version.py
Expand All @@ -44,7 +46,7 @@ languages in its place. For the Python experts: we will not see the most
elegant Python.


## Further goals
## Goals

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