tests_private/ctd_beaufort_sea.R

library(oce)
require(testthat)
options(width=100)                     # makes summaries easier to read
#options(warn=2)                        # die on warning, to catch unrecognized SBE names
Sys.setenv(TZ="America/Halifax")       # without a TZ, problems on macos high-sierra beta

count <- 0L
years <- 2003:2012
for (year in years) {
    cat("year=", year, "\n", sep="")
    path <- paste("~/data/arctic/beaufort/", year, sep="")
    files <- sort(list.files(path=path, pattern=".cnv$|.ctd$", full.names=TRUE))
    nfiles <- length(files)
    for (i in seq_along(files)) {
        if (!interactive())
            png(sprintf("ctd_beaufort_sea_%d_%03d.png", year, i))
        cat("\n##\n# file[", i, "]= '",  files[i], "'\n", sep="")
        d <- read.oce(files[i])
        testthat::expect_false(is.na(d[['latitude']][1]))
        testthat::expect_false(is.na(d[['longitude']][1]))
        testthat::expect_true("temperature" %in% names(d[['data']]))
        summary(d)                     # for inspection
        #cat("time[1]: ", d[["time"]][1], "\n", sep="") # not sure why
        if (files[i] == "~/data/arctic/beaufort/2007/d200720_049.cnv" && "gsw" == options()$oceEOS)
            expect_error(plot(d), "need at least two non-NA values to interpolate") # weird file, with just 1 level
        else
            plot(d)
        if (!interactive())
            dev.off()
        count <- count + 1L
    }
    cat("Successfully checked ", nfiles, " CTD files (.cnv or .ctd) in ", path[1], "\n", sep="")
}
cat("Processed ", count, " files\n", sep="")
dankelley/oce documentation built on May 8, 2024, 10:46 p.m.