tests/testthat/test-readfile.R

 context("Basic read - no tests")


# ftest1 <- system.file("extdata", "ocfiles", "S2008001.L3b_DAY_CHL.main", package = "croc")
# ftest2 <- system.file("extdata", "ocfiles", "S2010006.L3b_DAY_RRS.main", package = "croc")
# ss <- c(2L, 17L, 22L, 28L, 35L, 37L, 57L, 60L, 65L, 84L, 90L, 94L, 
#         97L, 123L, 124L, 127L, 144L, 186L, 199L, 209L)
# srj.vals <- c(2.77291652661871, 0.936526525863455, 4.05376445711522, 0.293754891732076, 
#               0.270393980401165, 0.505745622833565, 0.264196309786807, 0.342589976356427, 
#               0.328800995758015, 0.50318465129568, 0.279153425121026, 0.443662079457447, 
#               0.313772940144764, 0.483958409687222, 0.421589703471587, 0.34881600770005, 
#               0.594098383577779, 1.25794532157248, 1.15165476575385, 1.02698164706242
# )
# 
# soc.vals <- c(1.07632764104741, 0.39672062474529, 1.71999711131399, 0.17805968497236, 
#               0.168216571907782, 0.256407563570206, 0.165537732325897, 0.197567519765016, 
#               0.192185794678422, 0.255531580697685, 0.171952612346636, 0.23483326682149, 
#               0.186212666896167, 0.248919971658723, 0.226961738284949, 0.19996892887274, 
#               0.286083664050031, 0.501174994930848, 0.466264317169169, 0.425822794993995
# )
# test_that("file read is successful", {
#   expect_that(file.exists(ftest1), is_true()) 
#   expect_that(readL3(ftest1),is_a("list"))
#   expect_that(names(readL3(ftest2))[21L], equals("Rrs_670_ssq"))
#  })
# 
# test_that("SeaWiFS chla is correctly calculated", {
#   d <- readL3(ftest2)
#   srj  <- chla(d, sensor = "SeaWiFS", algo = "johnson")
#   expect_that(max(abs(srj[ss] - srj.vals)) < sqrt(.Machine$double.eps), is_true())
#   soc <- chla(d, sensor = "SeaWiFS", algo = "oceancolor")
#   expect_that(max(abs(soc[ss] - soc.vals)) < sqrt(.Machine$double.eps), is_true())
# })
#  
# load(system.file(package = "croc", "extdata", "A2002218.L3b_DAY_RRS.sub100.Rdata"))
# arj.vals <- c(0.222394638156379, 0.220222571893624, 0.208328815546689, 0.216354240496008, 
#               0.239055795393761, 0.205286077599231, 0.200468991373106, 0.195268554818653, 
#               0.211016521802958, 0.242049472103708, 0.232730862337822, 0.23411359079671, 
#               0.230345795394606, 0.227259063202271, 0.181179603723816, 0.169899553808312, 
#               0.188490229866462, 0.175124150964606, 0.181300886038744, 0.216038114280159, 
#               0.237018176484669, 0.233093056970501, 0.257437385713684, 0.265783453461839, 
#               0.256964688757362, 0.29855366703788, 0.179458553450707, 0.204987943641012, 
#               0.231015531542178, 0.232651297590472, 0.249564411460352, 0.216291498925906, 
#               0.178092398563937, 0.231730209544595, 0.222243517738029, 0.233140342471676, 
#               0.251550759466132, 0.239999824123444, 0.260501838068977, 0.22743037148309, 
#               0.227609316525771, 0.235273417120848, 0.24055321930818, 0.203585704099243, 
#               0.195890838033963, 0.211162286663492, 0.185380912223883, 0.240204155046625, 
#               0.209536438800657, 0.208883520946077, 0.246688835282204, 0.250199808345254, 
#               0.21944137238304, 0.179769438201606, 0.246585231406896, 0.23770104754484, 
#               0.212455866179739, 0.0995888059065303, 0.302990002891622, 0.256697985790512, 
#               0.26301531547978, 0.25479720303301, 0.243434630606967, 0.275306027519055, 
#               0.257393044398158, 0.233131815771459, 0.194804749960411, 0.252815547426267, 
#               0.113954406167314, 0.128294376597649, 0.173241473084798, 0.187212911182819, 
#               0.204818563533344, 0.227000132550886, 0.210262235957201, 0.217982591133404, 
#               0.214806278306759, 0.230031389834826, 0.243843932044655, 0.276310563200038, 
#               0.290744834587231, 0.275430260623232, 0.255990748509259, 0.277844219649337, 
#               0.224210428372348, 0.25277151341061, 0.23836948526974, 0.215126589599087, 
#               0.200796317567209, 0.21386416979011, 0.222306928964617, 0.217960540139329, 
#               0.220177513576891, 0.210330900852139, 0.226560911716695, 0.233273073107556, 
#               0.260622364910561, 0.256048394576021, 0.256116192144628, 0.238458683495343
# )
# 
# aoc.vals <- c(0.138394311629176, 0.135340748956471, 0.137894427199096, 0.138796446173381, 
#               0.139882286492014, 0.135391306077894, 0.13548446178279, 0.135502943381212, 
#               0.132344697287959, 0.135266368491084, 0.132540252053366, 0.135461025259244, 
#               0.137663362705752, 0.128738368770628, 0.118569280102985, 0.122542047813624, 
#               0.129444078108442, 0.119251512100118, 0.0943242766437246, 0.138326248790117, 
#               0.152152526835181, 0.152992076530809, 0.148744081521215, 0.155970943682632, 
#               0.150860883405231, 0.158122334021456, 0.14289131864821, 0.137988613425732, 
#               0.139255566629781, 0.139948843275473, 0.143323052376783, 0.152847252140876, 
#               0.109449488409675, 0.127928331184783, 0.140937048917924, 0.142722364826237, 
#               0.136625615358254, 0.138635516387481, 0.147914002083951, 0.135431636618317, 
#               0.144023085901366, 0.160236165661393, 0.152375940162637, 0.1040301405821, 
#               0.127467285469452, 0.131840160900825, 0.128272849933814, 0.146202619503305, 
#               0.141423940406029, 0.143235161422582, 0.14748939361934, 0.137795939995328, 
#               0.146805662779195, 0.1381098269918, 0.1444132994203, 0.132580001236244, 
#               0.126227900373675, 0.0784567869232435, 0.147348426365509, 0.148941995099094, 
#               0.150079103893699, 0.147715362928392, 0.148839378419979, 0.150381928258278, 
#               0.149368516654955, 0.14624797087065, 0.140034165545356, 0.155796559639267, 
#               0.119145921253205, 0.111486476607397, 0.132623045084053, 0.140729529443217, 
#               0.121097740550019, 0.0905430786715072, 0.115667502745567, 0.141112268768464, 
#               0.143589199964926, 0.148544362394055, 0.147565804486716, 0.147741939566057, 
#               0.149573195595645, 0.148052531552187, 0.149278289571592, 0.152865711313434, 
#               0.148939505150577, 0.133157244193345, 0.129474132778173, 0.126726197931534, 
#               0.116704321014998, 0.124437401299254, 0.133875513569587, 0.1403280710286, 
#               0.137132602324058, 0.138509782467766, 0.142118568125704, 0.141984701978918, 
#               0.148892080344977, 0.147645417774956, 0.144417146988498, 0.149650561774244
# )
# test_that("MODIS chla is correctly calculated", {
#   arj  <- chla(A2002218.L3b_DAY_RRS.sub100, sensor = "MODISA", algo = "johnson")
#   expect_that(max(abs(arj - arj.vals)) < sqrt(.Machine$double.eps), is_true())
#   aoc <- chla(A2002218.L3b_DAY_RRS.sub100, sensor = "MODISA", algo = "oceancolor")
#   expect_that(max(abs(aoc - aoc.vals)) < sqrt(.Machine$double.eps), is_true())
# })
# 
# 
mdsumner/roc documentation built on May 22, 2019, 5:05 p.m.