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.
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, |
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
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
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
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
// 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
# 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
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 |
Instructions for setting up a git server on a Synology NAS with Diskstation. Specifically, I am using a DS414 with DSM 5.0.
- 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 forgituser
andadmin
. This folder will hold all the repos. - Install Git Server package via Diskstation
OlderNewer