Skip to content

Instantly share code, notes, and snippets.

@timmc
Last active April 11, 2022 12:47
Show Gist options
  • Save timmc/7081c40c3a504b9c0138988b8ce62a4b to your computer and use it in GitHub Desktop.
Save timmc/7081c40c3a504b9c0138988b8ce62a4b to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -eu -o pipefail
data_path="/home/timmc/warehouse/biobot-data.csv"
png_path_prefix="/home/timmc/warehouse/biobot-data.Suffolk"
case "$1" in
fetch)
curl -sS https://raw.githubusercontent.com/biobotanalytics/covid19-wastewater-data/master/wastewater_by_county.csv > "$data_path"
;;
plot)
Rscript - <<EOF
d = read.csv("$data_path", header=T, sep=',')
d.Suffolk=subset(d, d\$name=='Suffolk County, MA')
d.Suffolk\$timestamp=as.Date(d.Suffolk\$sampling_week)
xwindow = as.Date(c('2020-01-01', '2022-03-01'))
# Log y axis
png("${png_path_prefix}.log.png", height=800, width=1200, units='px')
plot(
d.Suffolk\$timestamp, d.Suffolk\$effective_concentration_rolling_average,
type='l',
log='y',
xlim=xwindow,
)
dev.off()
# Linear y axis
png("${png_path_prefix}.lin.png", height=800, width=1200, units='px')
plot(
d.Suffolk\$timestamp, d.Suffolk\$effective_concentration_rolling_average,
type='l',
xlim=xwindow,
ylim=c(0, max(d.Suffolk\$effective_concentration_rolling_average) * 1.1),
)
abline(h=0) # draw y=0 line since origin does not start at 0
dev.off()
EOF
;;
*)
>&2 echo "Usage: $0 <fetch|plot>"
exit 1
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment