Skip to content

Commit

Permalink
Add tufts-weather benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
vagos committed Sep 11, 2024
1 parent 3a181ea commit 1f94d72
Show file tree
Hide file tree
Showing 7 changed files with 6,829 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tuft-weather/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.png
*.txt
2 changes: 2 additions & 0 deletions tuft-weather/clean.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
rm *.txt
rm *.png
6,749 changes: 6,749 additions & 0 deletions tuft-weather/input

Large diffs are not rendered by default.

Empty file added tuft-weather/inputs.sh
Empty file.
30 changes: 30 additions & 0 deletions tuft-weather/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env bash

input="input"

cat "$input" \
| grep -v "\-99" \
| sort -n \
| awk '{ printf "%02d-%02d %s %s\n", $1, $2, $3, $4 }' > formatted.txt

input="formatted.txt"

# Get max and min per month date across all years
cat "$input" \
| awk '{
key = sprintf("%s", $1);
if (!(key in max) || $3 > max[key]) max[key] = $3;
if (!(key in min) || $3 < min[key]) min[key] = $3;
}
END {
for (key in max) {
printf "%s %s %s\n", key, max[key], min[key];
}
}' \
| sort -n > max_min.txt

for year in $(seq 1995 2013); do
join -1 1 -2 1 -o "0 1.2 1.3 2.2" -e "NA" max_min.txt <(grep "$year" "$input" | cut -d' ' -f 1,3) \
| grep -v "NA" \
| ./scripts/plot.py "$year" > "$year.png"
done
46 changes: 46 additions & 0 deletions tuft-weather/scripts/plot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env python3

import datetime
import io
import matplotlib.pyplot as plt
import numpy as np
import sys

# Read data from stdin
data = sys.stdin
year = sys.argv[1]

to_dt = lambda x: datetime.datetime.strptime(f"{year}-{x}", "%Y-%m-%d")

data = [ line.strip().replace("\r", "") for line in data ]
data = [ (to_dt(date), float(_min), float(_max), float(temp)) for date, _min, _max, temp in [ line.split() for line in data if line ] ]
data = { key: [ x for x in values ] for key, values in zip(["date", "min", "max", "temp"], zip(*data)) }

dates = data["date"]
historic_max = data["max"]
historic_min = data["min"]
temps = data["temp"]

# Plotting
plt.figure(figsize=(10, 5))

# Historic ranges (shaded areas)
plt.fill_between(dates, historic_min, historic_max, color="tan", alpha=0.3, label='Normal range')

plt.plot(dates, temps, color="black", label=f"{year} temperature")

# Labels and titles
plt.xlabel(f"Days in {year}")
plt.ylabel("Temperature (°F)")
plt.title(f"Temperature Records for {year}")

# Legend
plt.legend(loc="upper right")

# Show the plot
plt.grid(True)

buf = io.BytesIO()
plt.savefig(buf, format='png')
plt.close()
sys.stdout.buffer.write(buf.getvalue())
Empty file added tuft-weather/verify.sh
Empty file.

0 comments on commit 1f94d72

Please sign in to comment.