@@ -138,6 +138,40 @@ test_that("sMDSGapFill runs of equal values",{
138138})
139139
140140
141+ sMDSGapFill_user = function (
142+ var_tofill
143+ , QFVar = ' none'
144+ , QFValue = NA_real_
145+ , FillAll = TRUE
146+ , isVerbose = TRUE
147+ , suffix = ' '
148+ , minNWarnRunLength = NA_integer_
149+ ) {
150+ # initialized one output column
151+ var_f = paste0(var_tofill ," _uStar_f" )
152+ .self $ sTEMP [[var_f ]] <- .self $ sDATA [[var_tofill ]]
153+ # set bad quality (not apssing uStarTrheshold) to NA
154+ .self $ sTEMP [[var_f ]][.self $ sTEMP [[QFVar ]] != QFValue ] <- NA
155+ # simulate gapfilling by setting all gaps to zero
156+ .self $ sTEMP [[var_f ]][is.na(.self $ sTEMP [[var_f ]])] <- 0.0
157+ }
158+ # create a derived class and override sMDSGapFill
159+ sEddyProcGapfill <- setRefClass(" sEddyProcGapfill" , contains = " sEddyProc" , inheritPackage = TRUE )
160+ sEddyProcGapfill $ methods(sMDSGapFill = sMDSGapFill_user )
161+
162+ test_that(" sEddyProc_sMDSGapFillAfterUstar with user gafilling function" ,{
163+ uStarTh <- 0.15
164+ data <- EddyDataWithPosix [1 : (48 * 3 * 30 ),]
165+ # note, using the derived class
166+ EP <- sEddyProcGapfill $ new(' DE-Tha' , data , c(' NEE' ,' Rg' , ' Tair' , ' VPD' , ' Ustar' ))
167+ EP $ sMDSGapFillAfterUstar(" NEE" , uStarTh = uStarTh , isFilterDayTime = TRUE )
168+ ans <- EP $ sExportResults()
169+ expect_true(all(ans $ NEE_uStar_f [is.na(data $ NEE )] == 0.0 ))
170+ expect_true(all(ans $ NEE_uStar_f [data $ Ustar < uStarTh ] == 0.0 ))
171+ expect_true(all(ans $ NEE_uStar_f [! is.na(data $ NEE ) & data $ NEE != 0.0 & data $ Ustar > uStarTh ] != 0.0 ))
172+ })
173+
174+
141175
142176
143177
0 commit comments