test-evap.R 2.53 KB
Newer Older
1
2
context("Test evaporation")

3
4
5
6
comp_evap <- function(BasinObs,
                      Lat, LatUnit,
                      TimeStepIn = "daily",
                      TimeStepOut = "daily") {
7
8
  PotEvap <- PE_Oudin(JD = as.POSIXlt(BasinObs$DatesR)$yday + 1,
                      Temp = BasinObs$T,
9
                      Lat = Lat, LatUnit = LatUnit,
10
                      TimeStepIn = TimeStepIn, TimeStepOut = TimeStepOut)
11
12
  PotEvapFor <- PE_Oudin(JD = as.POSIXlt(BasinObs$DatesR)$yday + 1,
                         Temp = BasinObs$T,
13
14
15
                         Lat = Lat, LatUnit = LatUnit,
                         TimeStepIn = TimeStepIn, TimeStepOut = TimeStepOut,
                         RunFortran = TRUE)
16
17
18
19
  all(range(PotEvap - PotEvapFor) < 0.000001)
}

test_that("PE_Oudin works", {
20
21
  skip_on_cran()
  rm(list = ls())
22

23
24
25
  data(L0123001); BasinObs_L0123001 <- BasinObs
  data(L0123002); BasinObs_L0123002 <- BasinObs

26
27
28
29
30
31
32
  expect_true(comp_evap(BasinObs = BasinObs_L0123001,
                        Lat = 0.8, LatUnit = "rad",
                        TimeStepIn = "daily", TimeStepOut = "daily"))
  expect_true(comp_evap(BasinObs = BasinObs_L0123001,
                        Lat = 0.8, LatUnit = "rad",
                        TimeStepIn = "daily", TimeStepOut = "hourly"))
  expect_true(comp_evap(BasinObs = BasinObs_L0123002,
33
                        Lat = 0.9, LatUnit = "rad",
34
35
36
37
                        TimeStepIn = "daily", TimeStepOut = "daily"))
  expect_true(comp_evap(BasinObs = BasinObs_L0123002,
                        Lat = 0.9, LatUnit = "rad",
                        TimeStepIn = "daily", TimeStepOut = "hourly"))
38

39
  ## check with several catchments using different values for Lat
40

41
42
43
44
  ## one by one
  PotEvapFor1 <- PE_Oudin(JD = as.POSIXlt(BasinObs_L0123001$DatesR)$yday + 1,
                          Temp = BasinObs_L0123001$T,
                          Lat = 0.8, LatUnit = "rad",
45
                          RunFortran = TRUE)
46
47
48
  PotEvapFor2 <- PE_Oudin(JD = as.POSIXlt(BasinObs_L0123002$DatesR)$yday + 1,
                          Temp = BasinObs_L0123002$T,
                          Lat = 0.9, LatUnit = "rad",
49
                          RunFortran = TRUE)
50

51
52
53
54
55
56
57
  ## all in one
  BasinObs_L0123001$Lat <- 0.8
  BasinObs_L0123002$Lat <- 0.9
  BasinObs <- rbind(BasinObs_L0123001, BasinObs_L0123002)
  PotEvapFor <- PE_Oudin(JD = as.POSIXlt(BasinObs$DatesR)$yday + 1,
                         Temp = BasinObs$T,
                         Lat = BasinObs$Lat, LatUnit = "rad",
58
                         RunFortran = TRUE)
59

60
  expect_equal(PotEvapFor, c(PotEvapFor1, PotEvapFor2))
61
})