EarthyScience / REddyProc

Processing data from micrometeorological Eddy-Covariance systems
58 stars 33 forks source link

Missing VPD_f does not produce informative error in sGLFluxPartition #34

Closed lsigut closed 5 years ago

lsigut commented 5 years ago

The method will inform user about missing Tair_f or Rg_f but not about missing VPD_f.

bgctw commented 5 years ago

Is it possible to create a pull request on a version that includes a failing test case in order to see what exactly to fix?

lsigut commented 5 years ago

Example here:

library(REddyProc)
DETha98 <- fConvertTimeToPosix(Example_DETha98, 'YDH', Year = 'Year',
                               Day = 'DoY', Hour = 'Hour')[-(2:4)]
EProc <- sEddyProc$new('DE-Tha', DETha98,
                       c('NEE', 'Rg', 'Tair', 'VPD', 'Ustar'))
EProc$sMDSGapFillAfterUstar('NEE', uStarTh = 0.3, FillAll = TRUE)
# missing 'VPD'...
for (i in c('Tair', 'Rg')) EProc$sMDSGapFill(i, FillAll = TRUE)
EProc$sSetLocationInfo(LatDeg = 51.0, LongDeg = 13.6, TimeZoneHour = 1)
# ...produces Error here
EProc$sGLFluxPartition(suffix = "uStar")

Error in data.frame(sDateTime = ds[[1]], NEE = NEEFiltered, sdNEE = ds[[NEESdVar]], : arguments imply differing number of rows: 17520, 0

This behaviour differs compared to what happens when Tair_f or Rg_f is missing (error will inform that these are needed).

bgctw commented 5 years ago

The corresponding test case in test_partGL.R would be:

test_that("report missing VPD_f column in error",{
  skip("only interactively test issue #34")
  DETha98 <- fConvertTimeToPosix(Example_DETha98, 'YDH', Year = 'Year',
                                 Day = 'DoY', Hour = 'Hour')[-(2:4)]
  EProc <- sEddyProc$new('DE-Tha', DETha98,
                         c('NEE', 'Rg', 'Tair', 'VPD', 'Ustar'))
  EProc$sMDSGapFillAfterUstar('NEE', uStarTh = 0.3, FillAll = TRUE)
  # missing 'VPD'...
  for (i in c('Tair', 'Rg')) EProc$sMDSGapFill(i, FillAll = TRUE)
  EProc$sSetLocationInfo(LatDeg = 51.0, LongDeg = 13.6, TimeZoneHour = 1)
  # ...produces Error here
  # Error should report missing column VPD_f
  expect_error(
    EProc$sGLFluxPartition(suffix = "uStar")
    ,"VPD_f"
  )
})

I will add a fix after pull request #35 has been merged, because it contains some common commits.