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
library(zoo) | |
# Read data and set up ---------------------------------------------------- | |
dat=read.csv("ex_dat_S79_NA25.csv") | |
dat$Date=as.Date(dat$Date) | |
dat$S79.14d=with(dat,rollapply(S79,width=14,FUN=function(x)mean(x,na.rm=T),fill=NA,align="right")) | |
dat$CRE.low=with(dat,ifelse(S79.14d<750,1,0)) # RECOVER Low flow envelope | |
# Helper functions for 14-day periods | |
dat$period.14=c(0,rep(1:(nrow(dat)-1))%/%14)+1 |
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
## From https://tonyladson.wordpress.com/2020/10/05/errors-in-variables-regression/ | |
## Code adapted from https://gist.github.com/TonyLadson/286077221cc07022a77aa74d0a6c211c | |
# Libraries | |
library(deming) | |
# Functions --------------------------------------------------------------- | |
# given a point (x1, y1) and a line defined by a slope m and intercept c1 |
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
# date.fun from personal AnalystHelper package | |
date.fun=function (x, tz = "EST", form = "%F"){as.POSIXct(strptime(x, form), tz = tz)} | |
# Example dataset | |
example=c("19-AUG-53 12.00.00.000000000 AM", "26-AUG-53 12.00.00.000000000 AM", | |
"26-AUG-53 12.00.00.000000000 AM", "26-AUG-53 12.00.00.000000000 AM", | |
"26-AUG-53 12.00.00.000000000 AM", "26-AUG-53 12.00.00.000000000 AM", | |
"01-APR-02 05.45.00.000000000 PM", "01-APR-02 12.00.00.000000000 AM", | |
"01-APR-02 12.00.00.000000000 AM", "01-APR-02 12.00.00.000000000 AM", | |
"01-APR-02 12.00.00.000000000 AM", "01-APR-02 12.00.00.000000000 AM") |
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
## | |
## LOK MFL 18 month period exploration and learning | |
## | |
## Code was compiled by Paul Julian | |
## contact info: pjulian@sccf.org | |
# Libraries | |
import datetime as dt | |
# |
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
# Functions from a seperate python script | |
# Calendar to Julian Days | |
cal2jd=function(date){ | |
year=as.numeric(format(date,"%Y")) | |
month=as.numeric(format(date,"%m")) | |
day=as.numeric(format(date,"%d")) | |
a = (14 - month)/12 | |
y = year + 4800 - a | |
m = month + 12*a - 3 |
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
## Code was compiled by Paul Julian | |
## contact info: pauljulianphd@gmail.com | |
# GIS libraries | |
library(sp) | |
library(rgdal) | |
library(rgeos) | |
library(raster) | |
# projection |
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
## A series of functions to extract and display model summary tables | |
## Generalized Additive Models | |
## Code was compiled by Paul Julian | |
## contact info: pauljulianphd@gmail.com | |
## libraries | |
library(mgcv) | |
library(flextable) | |
library(magrittr) |
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
library(jpeg) | |
# Custom function similar to print.palette(...) | |
RenderPal <- function(x,name){ | |
if ((missing(x)) || (missing(name))){ | |
stop("Internal error, please troubleshoot") | |
} | |
n <- length(x) | |
old <- graphics::par(mar = c(0.5, 0.5, 0.5, 0.5)) |
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
## A working example with data of ggridges | |
# Libraries --------------------------------------------------------------- | |
if(!require(ggplot2)) { install.packages('ggplot2') } ; library(ggplot2) | |
if(!require(ggridges)) { install.packages('ggridges') } ; library(ggridges) | |
# Data -------------------------------------------------------------------- | |
dat=data.frame(FedWY=c(1979, 1979, 1979, 1979, 1979, 1979, 1979, 1979, 1979, | |
1979, 1979, 1979, 1979, 1979, 1979, 1979, 1979, 1979, 1979, 1979, | |
1979, 1979, 1979, 1979, 1979, 1979, 1980, 1980, 1980, 1980, 1980, | |
1980, 1980, 1980, 1980, 1980, 1980, 1980, 1980, 1980, 1980, 1980, |
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
# From | |
## Strobl, R.O., Robillard, P.D., 2008. Network design for water | |
## quality monitoring of surface freshwaters: A review. Journal | |
## of Environmental Management, Microbial and Nutrient Contaminants | |
## of Fresh and Coastal Waters 87, 639–648. | |
## https://doi.org/10.1016/j.jenvman.2007.03.001 | |
#devtools::install_github("SwampThingPaul/AnalystHelper") | |
library(AnalystHelper) |