R version 3.5.2 (2018-12-20) -- "Eggshell Igloo" Copyright (C) 2018 The R Foundation for Statistical Computing Platform: x86_64-redhat-linux-gnu (64-bit) R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. Natural language support but running in an English locale R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. [Previously saved workspace restored] > #!/usr/bin/env Rscript > library(REddyProc) > library(dplyr) Attaching package: ‘dplyr’ The following objects are masked from ‘package:stats’: filter, lag The following objects are masked from ‘package:base’: intersect, setdiff, setequal, union > library(lubridate) Attaching package: ‘lubridate’ The following objects are masked from ‘package:base’: date, intersect, setdiff, union > library(tidyr) > fileName <- 'input.txt' > metaName <- 'metadata.txt' > > #Read in MetaData file which has 5 lines > # First line: latitude, longitude, timezone offset from UTC > # Second line: Name of ustar variable > # Third line: Ameriflux variable names to gap fill with u* screening > # Fourth line: REddyProc names that match those > # Fifth line: Ameriflux variable names to gap fill without u* screen > #Sixth line: REddyProc names that match those > > #Note: Tair, Rg, and Ustar are required > > metaData <- readLines(metaName) > metaLoc <- unlist(strsplit(metaData[1],",")) > latitude <- as.double(metaLoc[1]) > longitude <- as.double(metaLoc[2]) > timezone <- as.integer(metaLoc[3]) > ustarname <- unlist(metaData[2]) > metaCol_ustar_AM <- unlist(strsplit(metaData[3],",")) > metaCol_ustar <- unlist(strsplit(metaData[4],",")) > ustarloop <- seq(length(metaCol_ustar)) > metaCol_AM <- unlist(strsplit(metaData[5],",")) > metaCol <- unlist(strsplit(metaData[6],",")) > noustarloop <- seq(length(metaCol)) > > #Read Ameriflux file and rename columns > AM_site <- read.csv(fileName, na.strings = c("-9999", -9999)) > names(AM_site)[names(AM_site) == ustarname] <- 'Ustar' > for (uloc in ustarloop) { names(AM_site)[names(AM_site) == metaCol_ustar_AM[uloc]] <- metaCol_ustar[uloc] } > for (nuloc in noustarloop) { names(AM_site)[names(AM_site) == metaCol_AM[nuloc]] <- metaCol[nuloc] } > AM_site <- AM_site[, c("TIMESTAMP_START","TIMESTAMP_END","Ustar",metaCol_ustar,metaCol)] > > #Parse DatTime stamp TIMESTAMP_END to REddyproc standard > AM_site$DateTime <- parse_date_time(AM_site$TIMESTAMP_END, "%Y%m%d%H%M", tz="UTC") > AM_site <- separate(AM_site, DateTime, into = c("Date","Time"), sep = " ", extra = "merge", remove = F) > AM_site <- separate(AM_site, Date, into = c("Year","Month","Day"), sep = "-", extra = "merge", remove = F) > AM_site$DoY <- as.integer(strftime(AM_site$Date, format = "%j")) > AM_site$Year<-sapply(AM_site$Year,as.integer) > AM_site <- AM_site %>% + mutate(Hour = + strsplit(Time, ":") %>% + sapply(function(x){ + x <- as.numeric(x) + x[1] + x[2]/60 + x[3]/(60*60) + }) + ) > AM_site$Rg <- ifelse(AM_site$Rg<0, 0, AM_site$Rg) > > EddyData <- AM_site[, c("Year","DoY","Hour","Ustar",metaCol_ustar,metaCol)] > > #Filter runs > i<-1 > for (i in ustarloop) { EddyData <- filterLongRuns(EddyData, metaCol_ustar[i]) } > > #Convert time > EddyDataWithPosix <- fConvertTimeToPosix(EddyData, 'YDH',Year = 'Year',Day = 'DoY', Hour = 'Hour') Converted time format 'YDH' to POSIX with column name 'DateTime'. > > #Set up Reddyproc > EProc <- sEddyProc$new('site', EddyDataWithPosix, c('Ustar',metaCol_ustar, metaCol)) New sEddyProc class for site 'site' > EProc$sSetLocationInfo(LatDeg = latitude, LongDeg = longitude,TimeZoneHour = timezone) > > #Estimate ustar cutoff > uStarTh <- EProc$sEstUstarThold() Estimated UStar threshold of: 0.058 by using controls: taClasses UstarClasses 7 20 swThr minRecordsWithinTemp 10 100 minRecordsWithinSeason minRecordsWithinYear 160 3000 isUsingOneBigSeasonOnFewRecords 1 Warning messages: 1: In .estimateUStarSeason(...) : sEstUstarThreshold: too few finite records within season (n = 0). Need at least n = 160. Returning NA for this Season. 2: In .estimateUStarSeason(...) : sEstUstarThreshold: too few finite records within season (n = 0). Need at least n = 160. Returning NA for this Season. 3: In .estimateUStarSeason(...) : sEstUstarThreshold: too few finite records within season (n = 0). Need at least n = 160. Returning NA for this Season. 4: In .estimateUStarSeason(...) : sEstUstarThreshold: too few finite records within season (n = 8). Need at least n = 160. Returning NA for this Season. > EProc$sGetUstarScenarios() season uStar 1 2018001 0.05810525 2 2018003 0.05810525 3 2018006 0.05810525 4 2018009 0.05810525 5 2018012 0.05810525 Warning message: In EProc$sGetUstarScenarios() : uStar scenarios not set yet. Setting to annual mapping. > > #Gap fill met variables > i<-1 > for (i in noustarloop) { EProc$sMDSGapFill(metaCol[i],FillAll = FALSE, minNWarnRunLength = NA) } Initialized variable 'Tair' with 14495 real gaps for gap filling. Limited MDS algorithm for gap filling of 'Tair' with LUT(Rg only) and MDC. Look up table with window size of 7 days with Rg ......................746 Mean diurnal course with window size of 0 days: . ...............14 Mean diurnal course with window size of 1 days: . ...............94 Mean diurnal course with window size of 2 days: . ..............52 Look up table with window size of 14 days with Rg .............575 Look up table with window size of 21 days with Rg ........131 Look up table with window size of 28 days with Rg ......0 Look up table with window size of 35 days with Rg ......0 Look up table with window size of 42 days with Rg ......0 Look up table with window size of 49 days with Rg ......0 Look up table with window size of 56 days with Rg ......0 Look up table with window size of 63 days with Rg ......0 Look up table with window size of 70 days with Rg ......0 Mean diurnal course with window size of 7 days: . ......260 Mean diurnal course with window size of 14 days: . ....354 Mean diurnal course with window size of 21 days: . 72 Finished gap filling of 'Tair' in 4 seconds. Artificial gaps filled: 5323, real gaps filled: 14495, unfilled (long) gaps: 12197. Initialized variable 'Rg' with 8898 real gaps for gap filling. Restriced MDS algorithm for gap filling of 'Rg' with no meteo conditions and hence only MDC. Mean diurnal course with window size of 0 days: . ............................................................ .............................729 Mean diurnal course with window size of 1 days: . ............................................................ ......................765 Mean diurnal course with window size of 2 days: . ............................................................ ...............54 Mean diurnal course with window size of 7 days: . ............................................................ ..............270 Mean diurnal course with window size of 14 days: . ............................................................ ...........354 Mean diurnal course with window size of 21 days: . ............................................................ ........287 Mean diurnal course with window size of 28 days: . ............................................................ .....287 Mean diurnal course with window size of 35 days: . ............................................................ ..287 Mean diurnal course with window size of 42 days: . ..........................................................266 Mean diurnal course with window size of 49 days: . .......................................................259 Mean diurnal course with window size of 56 days: . .....................................................259 Mean diurnal course with window size of 63 days: . ..................................................244 Mean diurnal course with window size of 70 days: . ................................................231 Mean diurnal course with window size of 77 days: . ..............................................231 Mean diurnal course with window size of 84 days: . ...........................................210 Mean diurnal course with window size of 91 days: . .........................................203 Mean diurnal course with window size of 98 days: . .......................................201 Mean diurnal course with window size of 105 days: . .....................................178 Mean diurnal course with window size of 112 days: . ...................................175 Mean diurnal course with window size of 119 days: . ..................................167 Mean diurnal course with window size of 126 days: . ................................147 Mean diurnal course with window size of 133 days: . ..............................147 Mean diurnal course with window size of 140 days: . .............................130 Mean diurnal course with window size of 147 days: . ............................119 Mean diurnal course with window size of 154 days: . ..........................119 Mean diurnal course with window size of 161 days: . .........................109 Mean diurnal course with window size of 168 days: . ........................91 Mean diurnal course with window size of 175 days: . .......................91 Mean diurnal course with window size of 182 days: . ......................91 Mean diurnal course with window size of 189 days: . .....................91 Mean diurnal course with window size of 196 days: . .....................91 Mean diurnal course with window size of 203 days: . ....................91 Mean diurnal course with window size of 210 days: . ...................91 Finished gap filling of 'Rg' in 73 seconds. Artificial gaps filled: 15687, real gaps filled: 8898, unfilled (long) gaps: 1833. Initialized variable 'VPD' with 16089 real gaps for gap filling. Limited MDS algorithm for gap filling of 'VPD' with LUT(Rg only) and MDC. Look up table with window size of 7 days with Rg ......................................1676 Mean diurnal course with window size of 0 days: . ......................100 Mean diurnal course with window size of 1 days: . .....................330 Mean diurnal course with window size of 2 days: . .................140 Look up table with window size of 14 days with Rg ................608 Look up table with window size of 21 days with Rg ..........151 Look up table with window size of 28 days with Rg ........0 Look up table with window size of 35 days with Rg ........0 Look up table with window size of 42 days with Rg ........0 Look up table with window size of 49 days with Rg ........0 Look up table with window size of 56 days with Rg ........0 Look up table with window size of 63 days with Rg ........0 Look up table with window size of 70 days with Rg ........0 Mean diurnal course with window size of 7 days: . ........382 Mean diurnal course with window size of 14 days: . .....305 Mean diurnal course with window size of 21 days: . ..87 Mean diurnal course with window size of 28 days: . .32 Mean diurnal course with window size of 35 days: . 25 Mean diurnal course with window size of 42 days: . 28 Mean diurnal course with window size of 49 days: . 16 Mean diurnal course with window size of 56 days: . 2 Mean diurnal course with window size of 63 days: . 2 Mean diurnal course with window size of 70 days: . 8 Finished gap filling of 'VPD' in 5 seconds. Artificial gaps filled: 5323, real gaps filled: 16089, unfilled (long) gaps: 12197. Warning messages: 1: In sFillInit(Var, QFVar, QFValue, FillAll) : sMDSGapFill::: The long gap between position 1 and 12197 will not be filled! 2: In sFillInit(Var, QFVar, QFValue, FillAll) : sMDSGapFill::: The long gap between position 1 and 12197 will not be filled! > > #Gap fill flux variables with u* cutoff > i<-1 > for (i in ustarloop) { EProc$sMDSGapFillUStarScens(metaCol_ustar[i] ,FillAll = FALSE, minNWarnRunLength = NA) } Ustar filtering (u * Th_1 = 0.0581052528571429), marked 85% of the data as gap Initialized variable 'NEE' with 15653 real gaps for gap filling. Full MDS algorithm for gap filling of 'NEE.Ustar_uStar_fqc_0' with LUT(Rg, VPD, Tair) and MDC. Look up table with window size of 7 days with Rg VPD Tair ..................................87 Look up table with window size of 14 days with Rg VPD Tair .................................5 Look up table with window size of 7 days with Rg .................................1284 Mean diurnal course with window size of 0 days: . ....................179 Mean diurnal course with window size of 1 days: . ...................374 Mean diurnal course with window size of 2 days: . ...............81 Look up table with window size of 21 days with Rg VPD Tair ..............0 Look up table with window size of 28 days with Rg VPD Tair ..............0 Look up table with window size of 35 days with Rg VPD Tair ..............0 Look up table with window size of 42 days with Rg VPD Tair ..............0 Look up table with window size of 49 days with Rg VPD Tair ..............0 Look up table with window size of 56 days with Rg VPD Tair ..............0 Look up table with window size of 63 days with Rg VPD Tair ..............0 Look up table with window size of 70 days with Rg VPD Tair ..............0 Look up table with window size of 14 days with Rg ..............606 Look up table with window size of 21 days with Rg ........132 Look up table with window size of 28 days with Rg .......0 Look up table with window size of 35 days with Rg .......0 Look up table with window size of 42 days with Rg .......0 Look up table with window size of 49 days with Rg .......0 Look up table with window size of 56 days with Rg .......0 Look up table with window size of 63 days with Rg .......0 Look up table with window size of 70 days with Rg .......0 Mean diurnal course with window size of 7 days: . .......240 Mean diurnal course with window size of 14 days: . ....330 Mean diurnal course with window size of 21 days: . .78 Mean diurnal course with window size of 28 days: . 14 Mean diurnal course with window size of 35 days: . 13 Mean diurnal course with window size of 42 days: . 14 Mean diurnal course with window size of 49 days: . 19 Finished gap filling of 'NEE' in 13 seconds. Artificial gaps filled: 5323, real gaps filled: 15653, unfilled (long) gaps: 12197. Ustar filtering (u * Th_1 = 0.0581052528571429), marked 85% of the data as gap Initialized variable 'LE' with 15777 real gaps for gap filling. Full MDS algorithm for gap filling of 'LE.Ustar_uStar_fqc_0' with LUT(Rg, VPD, Tair) and MDC. Look up table with window size of 7 days with Rg VPD Tair ...................................127 Look up table with window size of 14 days with Rg VPD Tair ..................................11 Look up table with window size of 7 days with Rg ..................................1346 Mean diurnal course with window size of 0 days: . ....................153 Mean diurnal course with window size of 1 days: . ...................366 Mean diurnal course with window size of 2 days: . ...............104 Look up table with window size of 21 days with Rg VPD Tair ..............0 Look up table with window size of 28 days with Rg VPD Tair ..............0 Look up table with window size of 35 days with Rg VPD Tair ..............0 Look up table with window size of 42 days with Rg VPD Tair ..............0 Look up table with window size of 49 days with Rg VPD Tair ..............0 Look up table with window size of 56 days with Rg VPD Tair ..............0 Look up table with window size of 63 days with Rg VPD Tair ..............0 Look up table with window size of 70 days with Rg VPD Tair ..............0 Look up table with window size of 14 days with Rg ..............606 Look up table with window size of 21 days with Rg ........137 Look up table with window size of 28 days with Rg .......0 Look up table with window size of 35 days with Rg .......0 Look up table with window size of 42 days with Rg .......0 Look up table with window size of 49 days with Rg .......0 Look up table with window size of 56 days with Rg .......0 Look up table with window size of 63 days with Rg .......0 Look up table with window size of 70 days with Rg .......0 Mean diurnal course with window size of 7 days: . .......241 Mean diurnal course with window size of 14 days: . ....317 Mean diurnal course with window size of 21 days: . .81 Mean diurnal course with window size of 28 days: . 21 Mean diurnal course with window size of 35 days: . 19 Mean diurnal course with window size of 42 days: . 21 Mean diurnal course with window size of 49 days: . 23 Finished gap filling of 'LE' in 13 seconds. Artificial gaps filled: 5316, real gaps filled: 15777, unfilled (long) gaps: 12204. Ustar filtering (u * Th_1 = 0.0581052528571429), marked 85% of the data as gap Initialized variable 'H' with 15251 real gaps for gap filling. Full MDS algorithm for gap filling of 'H.Ustar_uStar_fqc_0' with LUT(Rg, VPD, Tair) and MDC. Look up table with window size of 7 days with Rg VPD Tair ..............................182 Look up table with window size of 14 days with Rg VPD Tair ............................1 Look up table with window size of 7 days with Rg ............................1015 Mean diurnal course with window size of 0 days: . ..................168 Mean diurnal course with window size of 1 days: . ................185 Mean diurnal course with window size of 2 days: . ..............44 Look up table with window size of 21 days with Rg VPD Tair ..............0 Look up table with window size of 28 days with Rg VPD Tair ..............0 Look up table with window size of 35 days with Rg VPD Tair ..............0 Look up table with window size of 42 days with Rg VPD Tair ..............0 Look up table with window size of 49 days with Rg VPD Tair ..............0 Look up table with window size of 56 days with Rg VPD Tair ..............0 Look up table with window size of 63 days with Rg VPD Tair ..............0 Look up table with window size of 70 days with Rg VPD Tair ..............0 Look up table with window size of 14 days with Rg ..............606 Look up table with window size of 21 days with Rg ........131 Look up table with window size of 28 days with Rg .......0 Look up table with window size of 35 days with Rg .......0 Look up table with window size of 42 days with Rg .......0 Look up table with window size of 49 days with Rg .......0 Look up table with window size of 56 days with Rg .......0 Look up table with window size of 63 days with Rg .......0 Look up table with window size of 70 days with Rg .......0 Mean diurnal course with window size of 7 days: . .......220 Mean diurnal course with window size of 14 days: . ....304 Mean diurnal course with window size of 21 days: . .84 Mean diurnal course with window size of 28 days: . .28 Mean diurnal course with window size of 35 days: . 26 Mean diurnal course with window size of 42 days: . 28 Mean diurnal course with window size of 49 days: . 27 Finished gap filling of 'H' in 13 seconds. Artificial gaps filled: 5318, real gaps filled: 15251, unfilled (long) gaps: 12202. Warning messages: 1: In sFillInit(Var, QFVar, QFValue, FillAll) : sMDSGapFill::: The long gap between position 1 and 12197 will not be filled! 2: In .self$sMDSGapFillAfterUstar(..., uStarTh = uStarTh[, c(1L, 1L + : sMDSGapFillAfterUstar::: Duplicated columns found! Please specify different suffix when processing different" , " setups on the same dataset! 3: In sFillInit(Var, QFVar, QFValue, FillAll) : sMDSGapFill::: The long gap between position 1 and 12204 will not be filled! 4: In .self$sMDSGapFillAfterUstar(..., uStarTh = uStarTh[, c(1L, 1L + : sMDSGapFillAfterUstar::: Duplicated columns found! Please specify different suffix when processing different" , " setups on the same dataset! 5: In sFillInit(Var, QFVar, QFValue, FillAll) : sMDSGapFill::: The long gap between position 1 and 12202 will not be filled! > > #Partition with nighttime > EProc$sMRFluxPartitionUStarScens('NEE_f') Start flux partitioning for variable NEE_uStar_f with temperature Tair_f. Estimate of the temperature sensitivity E_0 from short term data: 166.4. Regression of reference temperature R_ref for 3 periods. > > #EddyProc.C$sMRFluxPartition('NEE_f', parsE0Regression = list(TempRange = 3)) # night time partitioning of NEE without ustar filter -> Reco, GPP > #EddyProc.C$sMRFluxPartitionUStarScens('NEE_uStar_f') # night time partitioning of NEE with ustar filter -> Reco, GPP > #EddyProc.C$sGLFluxPartition('NEE_uStar_f') # day time partitioning after Lasslop et al. (2010) -> Reco_DT, GPP_DT > #EddyProc.C$sTKFluxPartition('NEE_uStar_f') # day time partitioning after Lasslop 2015 -> Reco_DT, GPP_DT > #EddyProc.C$sTKFluxPartitionUStarScens('NEE_uStar_f') # day time partitioning after Lasslop 2015 and ustar filter -> Reco_DT, GPP_DT > #Output data > > FilledEddyData <- EProc$sExportResults() > CombinedData <- cbind(EddyData, FilledEddyData) > fWriteDataframeToFile(CombinedData, 'output.txt') Number of NA convertered to '-9999': 851359 Wrote tab separated textfile: output.txt > > proc.time() user system elapsed 131.663 0.383 132.028