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

3
4
5
6
7

rm(list = ls())
data(L0123001); BasinObs_L0123001 <- BasinObs
data(L0123002); BasinObs_L0123002 <- BasinObs

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

24

25
test_that("PE_Oudin works", {
26
  skip_on_cran()
27

28
29
30
31
32
33
34
  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,
35
                        Lat = 0.9, LatUnit = "rad",
36
37
38
39
                        TimeStepIn = "daily", TimeStepOut = "daily"))
  expect_true(comp_evap(BasinObs = BasinObs_L0123002,
                        Lat = 0.9, LatUnit = "rad",
                        TimeStepIn = "daily", TimeStepOut = "hourly"))
40

41
  ## check with several catchments using different values for Lat
42

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

53
54
55
56
57
58
59
  ## 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",
60
                         RunFortran = TRUE)
61

62
  expect_equal(PotEvapFor, c(PotEvapFor1, PotEvapFor2))
63
})
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88

test_that("Inconsitent time series", {
  skip_on_cran()

  warnDaily <- "each day should have only one identical value of julian days. The time series is not sorted, or contains duplicate or missing dates"

  # duplicated dates
  DatesFor1Dupl <- BasinObs_L0123001$DatesR
  DatesFor1Dupl[5L] <- DatesFor1Dupl[4L]
  expect_warning(object = PE_Oudin(JD = as.POSIXlt(DatesFor1Dupl)$yday + 1,
                                   Temp = BasinObs_L0123001$T,
                                   Lat = 0.8, LatUnit = "rad"),
                 regexp = warnDaily)

  # not ordered dates
  DatesFor1Messy <- sample(BasinObs_L0123001$DatesR)
  expect_warning(object = PE_Oudin(JD = as.POSIXlt(DatesFor1Messy)$yday + 1,
                                   Temp = BasinObs_L0123001$T,
                                   Lat = 0.8, LatUnit = "rad"),
                 regexp = warnDaily)


})