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

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

test_that("PE_Oudin works", {
21
22
23
  skip_on_cran()
  rm(list = ls())
  
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
  data(L0123001); BasinObs_L0123001 <- BasinObs
  data(L0123002); BasinObs_L0123002 <- BasinObs

  expect_true(comp_evap(BasinObs_L0123001,
                        0.8, "rad",
                        "daily", "daily"))
  expect_true(comp_evap(BasinObs_L0123001,
                        0.8, "rad",
                        "daily", "hourly"))
  expect_true(comp_evap(BasinObs_L0123002,
                        0.9, "rad", 
                        "daily", "daily"))
  expect_true(comp_evap(BasinObs_L0123002,
                        0.9, "rad",
                        "daily", "hourly"))
  
  ## check with several catchments using different values for Lat
  
  ## one by one
  PotEvapFor1 <- PE_Oudin(JD = as.POSIXlt(BasinObs_L0123001$DatesR)$yday + 1,
                          Temp = BasinObs_L0123001$T,
                          Lat = 0.8, LatUnit = "rad",
                          RunFortran = T)
  PotEvapFor2 <- PE_Oudin(JD = as.POSIXlt(BasinObs_L0123002$DatesR)$yday + 1,
                          Temp = BasinObs_L0123002$T,
                          Lat = 0.9, LatUnit = "rad",
                          RunFortran = T)
  
  ## 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",
                         RunFortran = T)
  
  expect_equal(PotEvapFor, c(PotEvapFor1, PotEvapFor2))
  
63
})