Skip to content

Instantly share code, notes, and snippets.

@troyhill
troyhill / script_flowVsStage_20200803.R
Created August 3, 2020 13:38
Flow through S333 by headwater stage category, WY2006-2019
### calculate total flow through S333 below and above 9.2' from WY 2006-2019.
if(!"devtools" %in% installed.packages()) install.packages("devtools", repos='http://cran.us.r-project.org')
if(!"SFNRC" %in% installed.packages()) devtools::install_github("troyhill/SFNRC")
library(SFNRC)
theme_set(theme_bw())
@troyhill
troyhill / shrimp_mortality.R
Last active May 31, 2019 13:47
recreates pink shrimp survival rate calculations from Browder et al. 2002
### function to calculate equations 4, 3, and 5 from Browder et al. 2002
sv.rate <- function(salinity, temperature, daily = FALSE) {
LP <- -4.6019 + (0.7039 * temperature) + (0.2186 * salinity) +
(-0.0250 * temperature^2) + (-0.0077 * salinity^2) +
(0.0115 * temperature * salinity) # equation 4, using survival rate coefficients from Table 1
ifelse(daily == TRUE,
M1 <- -log(exp(LP)) * (exp(LP) + 1)^-1 / 28, # daily survival # equation 3
M1 <- -log(exp(LP)) * (exp(LP) + 1)^-1 # 28-day survival
@troyhill
troyhill / rainfall_formula.R
Created February 22, 2019 20:15
rainfall formula exploration
# script to explore the SFWMD's rainfall formula
a <- list.files("C:/RDATA/rainfall_formula/", pattern = "\\.txt$", full.names = TRUE)
rain <- read.delim(a[4], skip = 1)
head(rain)
pet <- read.delim(a[3], skip = 1)
head(pet)
@troyhill
troyhill / crontab_fireHydro_20190221.R
Last active June 4, 2019 14:12
fireHydro crontab 20190221
### may be necessary: install dev version of curl for google drive
# install.packages("https://github.com/jeroenooms/curl/archive/master.tar.gz", repos = NULL)
pkgs.used <- c("devtools", "sf", "ggplot2", "gmailr", "googledrive")
pkgs.to.install <- pkgs.used[!pkgs.used %in% installed.packages()]
if (length(pkgs.to.install) > 0) {
install.packages(pkgs.to.install)
}
if (!"fireHydro" %in% installed.packages()) {
@troyhill
troyhill / tests.sh
Created December 20, 2018 14:22
tests for Jed
###
discharge_section_join.sh L67_L30 > /home/thill/RDATA/dataForEver/data_L67_L30_flow.csv
###
#!/bin/bash
# Script pulls coordinates for all stations in DataForEver database
# Usage: ./bash/dataForEver_getCoords.sh
@troyhill
troyhill / addtoPath.sh
Created December 19, 2018 22:02
add files to PATH
export PATH=$PATH:/opt/physical/appaserver/src_waterquality:/opt/physical/appaserver/src_appaserver:/opt/physical/appaserver/utility:/opt/physical/appaserver/src_hydrology:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:.:/home/thill/bash:.:/opt/physical/appaserver/utility:/opt/physical/appaserver/src_appaserver:/opt/physical/appaserver/src_waterquality:/opt/physical/appaserver/src_hydrology:/opt/physical/sql:/opt/physical/util/
source ~/.profile
@troyhill
troyhill / example.R
Created December 19, 2018 19:03
Example download script for Jed
### script to download and summarize DataForEver hydro data for a set of stations
### install.packages("devtools") # install devtools package, if it's not installed already
devtools::install_github("troyhill/SFNRC")
library(SFNRC)
library(plyr)
library(ggplot2)
### stations can be defined manually
@troyhill
troyhill / gfh.R
Created December 18, 2018 22:16
getFireHydro test
getFireHydro(EDEN_date = "20181018", dataToPlot = "WF_Use", output_shapefile = NULL,
imageExport = "output_WFuse_20181018.png")
# beepr::beep(2)
getFireHydro(EDEN_date = "20170630", dataToPlot = "WL_des", output_shapefile = NULL,
imageExport = "output_WLdes_20170630.png")
# beepr::beep(2)
@troyhill
troyhill / WRTDS.R
Last active December 17, 2018 20:14
WRTDS implementation using DataForEver data
### Weighted regression using time, discharge, and season
### Application of EGRET tools to DataForEver data
library(plyr)
library(SFNRC)
# Meta-analysis -----------------------------------------------------------
targStns <- c("S333", "S12A", "S12B", "S12C", "S12D") #, "S151", "S343", "S332")
@troyhill
troyhill / assignTides.R
Created November 13, 2018 22:20
identifies higher and lower high/low tides
assignTide <- function(data, timeCol = "time", levelCol = "level", tideCol = "tide") {
### this works well with output from HL()
### arguments:
### data = the data frame
### timeCol = name of column with time stamp data, in format "YYYY-MM-DD ..."
### levelCol = name of column with water level data (numeric)
### tideCol = name of column with tide indicator (H/L) - this is tailored to HL() output
data[, "day"] <- substr(data[, timeCol], 1, 10) # weak point - assumes YYYY-MM-DD format