Skip to content

Instantly share code, notes, and snippets.

View walkerjeffd's full-sized avatar

Jeff Walker walkerjeffd

View GitHub Profile
@walkerjeffd
walkerjeffd / ggplot2.calendar
Last active December 20, 2015 02:29
Calendar Plot using ggplot2
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,
@walkerjeffd
walkerjeffd / events.R
Last active March 9, 2018 21:43
R functions for assigning and summarizing storm events based on interevent period and minimum event total precipitation
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])) {
@walkerjeffd
walkerjeffd / zoo_regular.R
Created August 7, 2013 23:02
R function for creating a regular and continuous zoo object from two vectors of dates/datetimes and values with optional fill values
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)
@walkerjeffd
walkerjeffd / is_regular.R
Created August 7, 2013 23:04
R function to test is vector of datetimes is regular and continuous
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)
}
}
@walkerjeffd
walkerjeffd / ghcnd-inventory-convert.py
Created February 10, 2014 14:48
Tools for processing GHCND text files
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)
@walkerjeffd
walkerjeffd / sketch.ino
Created May 25, 2014 17:35
Arduino Temperature and Humidity Logger using Adafruit SD Shield and DHT22
// 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)
@walkerjeffd
walkerjeffd / setup.sh
Last active August 29, 2015 14:02
Raspberry Pi Set Up
# 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
@walkerjeffd
walkerjeffd / r-for-engineers.md
Last active August 29, 2015 14:02
R Programming for Environmental Engineers

R Programming for Environmental Engineers

Jeff Walker, PhD

This document provides some suggestions and resources for environmental engineers using R. This information is based on my own personal experience of learning and using R.

Software

@walkerjeffd
walkerjeffd / LOGGER00.csv
Last active August 29, 2015 14:04
Riffle-ito Script for DHT22
DATETIME RTC_TEMP_C TEMP_C HUMIDITY_PCT BATTERY_LEVEL
2014-07-15 21:05:29 25.50 25.70 70.40 5.15
2014-07-15 21:05:35 25.50 25.70 70.30 5.14
2014-07-15 21:05:40 25.50 25.70 70.30 5.14
2014-07-15 21:05:45 25.50 25.70 70.30 5.14
2014-07-15 21:05:51 25.50 25.70 70.30 5.14
2014-07-15 21:05:56 25.50 25.60 70.19 5.14
2014-07-15 21:06:02 25.50 25.60 70.30 5.14
2014-07-15 21:06:07 25.50 25.70 70.30 5.14
2014-07-15 21:06:12 25.50 25.60 70.30 5.14
@walkerjeffd
walkerjeffd / Synology-Diskstation-Git.md
Last active April 27, 2024 15:39
Instructions for setting up git server on Synology Diskstation

Configure Synology NAS as Git Server

Instructions for setting up a git server on a Synology NAS with Diskstation. Specifically, I am using a DS414 with DSM 5.0.

Set Up User and Folder

  • Create user gituser via Diskstation interface (with File Station and WebDAV privilages)
  • Add new shared folder called git (located at /volume1/git) with read/write access for gituser and admin. This folder will hold all the repos.
  • Install Git Server package via Diskstation