R/get.onset.R

#' Title
#'Generate onset temperature for a given ascii data export
#' @param filename
#'
#' @return
#' @export
#'
#' @examples
get.onset <- function(filename){
  spc <- readin(filename)

  x <- spc$V1
  y <- spc$V2 - min(spc$V2)
  plot(x, y)
  spl <- smooth.spline(y ~ x, all.knots = F, spar = 0.8)
  lines(spl, col=2)
  newx <- seq(min(x), max(x), (max(x) - min(x))/10000)
  # newx <- spc$V1[which.middle(spc$V2)]
  pred0 <- predict(spl, x=newx, deriv=0)
  pred1 <- predict(spl, x=newx, deriv=1)
  maxx <- pred1$x[which.max(pred1$y)]
  maxy1 <- pred1$y[which.max(pred1$y)]
  maxy0 <- pred0$y[which.max(pred1$y)]
  yint <- maxy0 - (maxy1*maxx)
  xint <- -yint/maxy1
  return(xint)
}
yanxianUCSB/jascor documentation built on May 21, 2019, 3:04 a.m.