-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMetDataGapFilling.R
63 lines (59 loc) · 3.79 KB
/
MetDataGapFilling.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
63
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
# Script to fill the gaps in meteorological data
# Written by `Pushpendra Raghav`
# University of Alabama ([email protected])
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
if(!require(REddyProc)){
install.packages("REddyProc")
library(REddyProc)
}
data <- readRDS('~/Downloads/sample_data.rds') # change here as required
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
#****Gap Filling****
# (See paper by Markus Reichstein: "On the separation of net ecosystem exchange into assimilation and ecosystem respiration: review and improved algorithm
#https://onlinelibrary.wiley.com/doi/full/10.1111/j.1365-2486.2005.001002.x); https://rdrr.io/rforge/REddyProc/man/sMDSGapFill.html
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
data$DateTime <- as.POSIXct(data$DateTime, tz="Etc/GMT-6") # time stamp in POSIX time format
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
#--------------Case 1 (when you have ustar data)--------------------------------
#+++ Processing with ustar filtering before
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
vars <- c('ET','GPP','RH','Rg', 'Tair', 'VPD', 'u', 'Ustar', 'NEE') # Variables for which you want to perform gap-filling
temp <- sEddyProc$new('Any name', data, vars) # To preserve original data
temp$sSetLocationInfo(LatDeg=35.559815, LongDeg=-98.063128, TimeZoneHour=-6) #Location of Site
# estimating the thresholds based on the ustar data
(uStarTh <- temp$sEstUstarThreshold()$uStarTh)
temp$sMDSGapFillAfterUstar('ET')
temp$sMDSGapFillAfterUstar('GPP')
temp$sMDSGapFillAfterUstar('RH')
temp$sMDSGapFillAfterUstar('Rg')
temp$sMDSGapFillAfterUstar('Tair')
temp$sMDSGapFillAfterUstar('VPD')
temp$sMDSGapFillAfterUstar('u')
temp$sMDSGapFillAfterUstar('NEE')
temp <- temp$sExportResults() # <-------- DataFrame contains the gap-filled values and associated quality flags (Enjoy :)
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
#---Case 2 (when you do not ustar data and/or do not want ustar filtering for gap-filling)---
#+++ Processing without ustar filtering before
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
vars <- c('ET','GPP','RH','Rg', 'Tair', 'VPD', 'u', 'NEE') # Variables for which you want to perform gap-filling
temp <- sEddyProc$new('Any name', data, vars) # To preserve original data
temp$sMDSGapFill('ET', FillAll=TRUE)
temp$sMDSGapFill('GPP', FillAll=TRUE)
temp$sMDSGapFill('RH', FillAll=TRUE)
temp$sMDSGapFill('Rg', FillAll=TRUE)
temp$sMDSGapFill('Tair', FillAll=TRUE)
temp$sMDSGapFill('VPD', FillAll=TRUE)
temp$sMDSGapFill('u', FillAll=TRUE)
temp$sMDSGapFill('NEE', FillAll=TRUE)
temp <- temp$sExportResults() # <-------- DataFrame contains the gap-filled values and associated quality flags (Enjoy :)
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------