DOI-USGS / DOI-USGS/streamMetabolizer

filter DO better for nighttime regression

Open
#109 1 comment 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Stan
Stars
47
Forks
25
PR merge metrics
No merged PRs in 30d

Description

rather than using filter(), use a sevitsky golay filter (more appropriate to curved time series; then could use the derivatives directly from the polynomial filter). their paper has been cited lots: Smoothing and Differentiation of Data by Simplified Least Squares Procedures. sgolay()

Code from Bob, 9/3/15:

``` r
library(signal)

nightregsg<-function(o2file, bp, ts){

temp<-o2file$temp
oxy<-o2file$oxy

##filter oxy data. No derivative!
oxyf<-sgolayfilt(x=oxy, p=3, n=5, m=0)

##calculate delO/delt, SG filter with m=1 so we took derivative
deltaO2<-1440*(sgolayfilt(x=oxy, p=3, n=5, m=1))/ts

#calc the dodef
satdef<-osat(temp,bp)-oxyf

#calculate regression and plot
nreg<-lm(deltaO2~satdef)
plot(satdef,deltaO2)
abline(nreg)

coeff<-coef(nreg)

out<-list(coeff, K600fromO2(mean(temp), coeff[2]))
out
}

nightregsg(french[french$dtime>=as.numeric(chron(dates="09/15/12", times="19:40:00")) & french$dtime<=as.numeric(chron(dates="09/15/12", times="23:00:00")), ], bp=523, ts=5)

nightregsg(french[french$dtime>=as.numeric(chron(dates="08/24/12", times="19:40:00")) & french$dtime<=as.numeric(chron(dates="08/24/12", times="23:00:00")), ], bp=523, ts=5)

nightregsg(french[french$dtime>=as.numeric(chron(dates="08/25/12", times="19:40:00")) & french$dtime<=as.numeric(chron(dates="08/25/12", times="23:00:00")), ], bp=523, ts=5)

##ignore the below

o2file<-french[french$dtime>=as.numeric(chron(dates="09/15/12", times="19:40:00")) & french$dtime<=as.numeric(chron(dates="09/15/12", times="23:00:00")), ]
plot(french15$oxy)
length(french15$oxy)

plot(sgolayfilt(x=french15$oxy, p=3, n=7, m=0))
plot(sgolayfilt(x=french15$oxy, p=3, n=7, m=1))
length(sgolayfilt(x=french15$oxy, p=3, n=7, m=1))
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.