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
# Raspberry Pi Set Up Shell Script | |
# By Jeff Walker | |
# I created this to make it easier to re-install/re-configure my pi in case I need to start from scratch. | |
# Assumes Occidentalis v0.2 is being used. | |
# Run an update | |
# sudo apt-get update | |
# Adafruit WebIDE |
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
// log DHT sensor readings to SD card | |
#include "DHT.h" | |
#include <SD.h> | |
#include <Wire.h> | |
#include "RTClib.h" | |
RTC_DS1307 RTC; | |
// how many milliseconds between grabbing data and logging it. 1000 ms is once a second | |
#define LOG_INTERVAL 60000 // mills between entries (reduce to take more/faster data) |
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
import pandas as pd | |
import csv | |
colspecs = [(0,11), (12,20), (21,30), (31,35), (36,40), (41,45)] | |
df = pd.read_fwf('ghcnd-inventory.txt', colspecs=colspecs, header=None, index_col=None) | |
df.columns = ["ID", "LATITUDE", "LONGITUDE", "ELEMENT", "FIRSTYEAR", "LASTYEAR"] | |
df.set_index("ID", inplace=True) | |
df.to_csv('ghcnd-inventory.csv', quoting=csv.QUOTE_NONNUMERIC) |
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
is.regular <- function(x) { | |
# returns TRUE if vector x of POSIXct datetimes is continuous and regular | |
# by checking if there are more than one unique difftime between each row | |
x.difftime <- difftime(x[2:length(x)], x[1:(length(x)-1)], units='secs') | |
if (length(levels(factor(x.difftime))) > 1) { | |
return (FALSE) | |
} else { | |
return (TRUE) | |
} | |
} |
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
zoo.regular <- function(dates, values, by="hour", fill=NA) { | |
# convert time series to regular zoo object | |
require(zoo) | |
z <- zoo(values, dates) | |
z <- merge(z, zoo(, seq(floor_date(start(z), 'day'), | |
ceiling_date(end(z), 'day'), | |
by)), | |
fill=fill) | |
z <- z[1:(length(z)-1)] | |
return(z) |
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
assign.events <- function(df, datetime.name="DATETIME", value.name="VALUE", interevent=8, threshold=0.1) { | |
# assigns events to data frame such as storm events or discharge events | |
require(plyr) | |
if (!(datetime.name %in% names(df))) { | |
stop(paste0('Could not find datetime column called ', datetime.name)) | |
} | |
if (!(value.name %in% names(df))) { | |
stop(paste0('Could not find value column called ', value.name)) | |
} | |
if (!is.regular(df[, datetime.name])) { |
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
require(lubridate) | |
require(plyr) | |
require(ggplot2) | |
theme_set(theme_bw()) | |
# create random dataset | |
df <- data.frame(DATETIME = ymd("2000-01-01") + ddays(runif(100)*365*5)) | |
# compute day/month columns | |
df <- mutate(df, |
NewerOlder