An event is a threshold decision a scientist must defend. Today the code learns to decide.
| File | Source | Coverage | Used for |
|---|---|---|---|
| iowa_city_weather_daily.csv | Iowa Environmental Mesonet, station IOW | Daily, 2019–2025, 2,549 rows | Wet, hot and cold day labels; dry spells |
| iowa_streamflow_daily.csv | USGS NWIS, site 05454500, Iowa River at Iowa City | Daily, 2015–2025, 4,018 rows | Counting high-flow days by month |
An if/elif/else chain runs exactly one branch, and the order decides which.
Python
rain_mm = 12.0
if rain_mm >= 10:
label = "wet"
elif rain_mm > 0:
label = "damp"
else:
label = "dry"
print(label) # wetPython
# A day with 15 mm rain AND a 33 deg C maximum:
if row["precipitation_mm"] >= 10:
label = "wet" # <- evaluation stops here
elif row["temp_max_c"] >= 32:
label = "hot" # never reached for this day
else:
label = "ordinary"A counter carries state from one iteration to the next.
Python
longest = 0
current = 0
for precip in precip_values:
if precip < 1.0:
current = current + 1
longest = max(longest, current)
else:
current = 0 # forget this line and see the next slide?
Without the reset, the code reports a 900-day dry spell in a 7-year record of an Iowa town. What single check exposes the answer as absurd?
for each row: if hot and humid: count = count + 1
((temp_max >= 30) & (humidity >= 70)).sum()
The counts must match. Agreement between independent implementations is the lab's built-in test.
The number you pick is a scientific claim you have to defend.
5 mm wets the topsoil: a useful rain.
25 mm in a day starts mattering downstream.
1 mm separates a wet day from a dry one in many indices.
Every event count in this lab depends on a threshold somebody chose.
Part B continues the Lab 2 notebook you started in Week 2. Restart the kernel and run from the top.
| This week | Next week | Bridge idea |
|---|---|---|
| Decisions inside loops | Functions and debugging | Package the decision so it can be named, reused, and tested |
?
Name a threshold from your own field and the reason behind the number. Who chose it, and what would change if it moved?