-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
6,829 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
*.png | ||
*.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
rm *.txt | ||
rm *.png |
Large diffs are not rendered by default.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.