R/compare.ACs.blank.R

Defines functions compare.ACs.blank

Documented in compare.ACs.blank

#' Compare blank file generated by \code{\link{analyse.ACs.blank}}
#'
#' Allows the user to compare the evolution of the blank values of
#' the ACs over time.
#'
#' @param NF is the number of file to compare. The default is 2.
#' @param output.path is the path where the PNG plots will be save.
#' @param SAVE is a logical paramter indicating whether or not the plot
#' will save. If TRUE, two PNG file will be saved in output.path. Default is TRUE.
#'
#' @details The user will prompt to select the files manually.
#'
#' @author Simon Belanger
#' @export
#'

compare.ACs.blank <-function(NF=2, output.path, SAVE=TRUE) {

  filen = rep("name", NF)

  for (i in 1:NF) {
    print(paste("Select file:", i))
    fn = file.choose()
    load(fn)
    filen[i] = unlist(str_split(fn, "/"))[length(unlist(str_split(fn, "/")))]
    if (i == 1) {
      a.offset = matrix(NA, ncol=length(ACS.blank$a.mean), nrow=NF)
      c.offset = matrix(NA, ncol=length(ACS.blank$c.mean), nrow=NF)
    }

    a.offset[i,] = ACS.blank$a.mean
    c.offset[i,] = ACS.blank$c.mean

  }

  if (SAVE) {
    png(file=paste(output.path, filen[1],"_a_comparison.png", sep=""),
        units="in", height = 5, width = 6, res=300)
    plot(ACS.blank$a.wl, a.offset[1,], ylim=c(min(a.offset),
                                              max(a.offset)),
         type="l", xlab="Wavelenght", ylab="a offset")
    for (i in 1:NF) lines(ACS.blank$a.wl, a.offset[i,], col=i)
    legend("bottomright", filen, col=seq(NF), lwd=rep(1,NF))
    dev.off()

    png(file=paste(output.path, filen[1],"_c_comparison.png", sep=""),
        units="in", height = 5, width = 6, res=300)
    plot(ACS.blank$c.wl, c.offset[1,], ylim=c(min(c.offset),
                                              max(c.offset)),
         type="l", xlab="Wavelenght", ylab="c offset")
    for (i in 1:NF) lines(ACS.blank$c.wl, c.offset[i,], col=i)
    legend("bottomright", filen, col=seq(NF), lwd=rep(1,NF))
    dev.off()

  } else {

    plot(ACS.blank$a.wl, a.offset[1,], ylim=c(min(a.offset),
                                              max(a.offset)),
         type="l", xlab="Wavelenght", ylab="a offset")
    for (i in 1:NF) lines(ACS.blank$a.wl, a.offset[i,], col=i)
    legend("bottomright", filen, col=seq(NF), lwd=rep(1,NF))


    plot(ACS.blank$c.wl, c.offset[1,], ylim=c(min(c.offset),
                                              max(c.offset)),
         type="l", xlab="Wavelenght", ylab="c offset")
    for (i in 1:NF) lines(ACS.blank$c.wl, c.offset[i,], col=i)
    legend("bottomright", filen, col=seq(NF), lwd=rep(1,NF))

  }

}
belasi01/Riops documentation built on Sept. 5, 2022, 6:38 p.m.