Skip to content

Instantly share code, notes, and snippets.

@troyhill
troyhill / noaa_function.R
Last active December 15, 2015 02:29
Function scrapes NOAA tide data from CO-OPS website, formats data and makes it an R object. Major update in October 2013 to accommodate changes to the CO-OPS website
### Important note: I'm no longer maintaining this gist, since this code is incorporated into the
### VulnToolkit package.
### Because it's not being maintained, the code below might not work. The latest, updated version
### of the NOAA scraper is available at https://github.com/troyhill/VulnToolkit/blob/master/R/noaa.r
### Function downloads and compiles tide data from NOAA CO-OPS website
### Requires RCurl and XML packages - install.packages("RCurl"); install.packages("XML")
###
### This version does not include a monthly time interval option
@troyhill
troyhill / HL_function.R
Last active December 16, 2015 19:59
R function to pick out high and low tides from a dataset of tidal water levels
### Important note: I'm no longer maintaining this gist, since this code is incorporated into the
### VulnToolkit package.
### Because it's not being maintained, the code below might not work. The latest, updated version
### is available at https://github.com/troyhill/VulnToolkit/blob/master/R/HL.r
### Function to pick out high and low tides from a dataset of tidal water levels
###
### Arguments:
@troyhill
troyhill / HL.plot.R
Last active December 17, 2015 03:08
A function to allow visual examination of the high and low tides found by function HL()
### Important note: I'm no longer maintaining this gist, since this code is incorporated into the
### VulnToolkit package.
### Because it's not being maintained, the code below might not work. The latest, updated version
### is available at https://github.com/troyhill/VulnToolkit/blob/master/R/HL_plot.R
### Function to visually examine high and low tides found by function HL()
### Arguments are the same as for HL()
###
@troyhill
troyhill / number.tides.R
Last active December 19, 2015 18:18
An R function to create columns with sequential tide numbers (for whole tidal cycles, flood, and ebb tides)
### Important note: I'm no longer maintaining this gist, since this code is incorporated into the
### VulnToolkit package.
### Because it's not being maintained, the code below might not work. The latest, updated version
### is available at:
### https://github.com/troyhill/VulnToolkit/blob/master/R/number_tides.R
### function to number tides and insert tide numbers (for whole tidal cycles, flood, and ebb tides)
### in high-frequency dataset.
@troyhill
troyhill / harcon.R
Last active August 29, 2015 13:57
R function to scrape data on harmonic constituent data for a NOAA CO-OPS tide station.
### Important note: I'm no longer maintaining this gist, since this code is incorporated into the
### VulnToolkit package.
### Because it's not being maintained, the code below might not work. The latest, updated version
### is available at https://github.com/troyhill/VulnToolkit/blob/master/R/harcon.R
### Input argument is a single NOAA station number. See http://co-ops.nos.noaa.gov/stations.html?type=Water+Levels
### Output is a dataframe with a row for each harmonic constituent, and columns for
### each station's amplitude, phase, and speed.
### Important note: I'm no longer maintaining this gist, since this code is incorporated into the
### VulnToolkit package.
### Because it's not being maintained, the code below might not work. The latest, updated version
### is available at https://github.com/troyhill/VulnToolkit/blob/master/R/vuln_kit.R
### Code to transform tidal data to a set of resources to evaluate vulnerability to sea level rise
###
### Required arguments:
@troyhill
troyhill / noaa_datums.R
Last active August 29, 2015 13:58
Brings vertical datums associated with NOAA CO-OPS stations into R.
### Important note: I'm no longer maintaining this gist, since this code is incorporated into the
### VulnToolkit package.
### Because it's not being maintained, the code below might not work. The latest, updated version
###is available at https://github.com/troyhill/VulnToolkit/blob/master/R/noaa_datums.R
### Input argument is a single NOAA station number. See http://co-ops.nos.noaa.gov/stations.html?type=Water+Levels
### Output is a dataframe with a row for each elevation datum listed for the station.
### Results are in meters and calculated over the 1983-2001 epoch.
@troyhill
troyhill / profilePlot.R
Created May 21, 2015 22:05
code for panel graphics
### code to make decent-looking, simple panel graphics
profilePlot <- function(xdata = dated$OM.pct, ydata = dated$midpoint, siteList = dated$site,
xlabel = "Organic matter content (decimal fraction)",
ylabel = "depth (cm)",
rowNos = 4, colNos = 4,
xTiers = 1,
filename = "OM_profiles.png",
figylims = c(80, 0),
figxlims = c(0, 0.8)
@troyhill
troyhill / TopCon_conversion.R
Last active October 21, 2020 15:46
convert Topcon total station data to known coordinates (e.g., lat/long; northing/easting)
# install.packages("plyr")
library(plyr)
#####
# User inputs
#
# data should be the raw TopConLink output of the points tab from the "measurement" file
tsData <- read.delim("C:/RDATA/surveying/data_150526SWD.txt", header=TRUE, sep = "\t", na.strings=".")
# the TSObs dataset is needed to convert between total station orientations
@troyhill
troyhill / NCDC_pdfToR.R
Created September 16, 2015 13:57
Import annual NCDC local climatological data report pdfs to R
NCDC_combine <- function(pdfFiles, pdfToText = "C:\\Program Files\\xpdfbin-win-3.04\\bin64\\pdftotext.exe") {
# get pdftotxt from ftp://ftp.foolabs.com/pub/xpdf/xpdfbin-win-3.04.zip
# get NCDC Local Climatological Data annual summary pdfs from https://www.ncdc.noaa.gov/IPS/lcd/lcd.html
combineWords <- function(input, terms = 9, n = 3, spacer = "_", spacerIn = " ") {
# function takes a vector of words with spaces (input), and returns some number of terms (terms),
# on the basis of combining sequences of n words
splitTerms <- strsplit(input, spacerIn)[[1]] # individual words
starts <- seq(from = 1, to = length(splitTerms), by = n) # start of new terms
for (i in 1:(length(starts))) {
tmpName <- paste(splitTerms[starts[i]:(starts[i] + n - 1)], collapse = spacer)