inst/tests/test_partGL.R

#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#+++ Unit tests for fConvertTimeToPosix functions +++
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# Author: TW
#require(testthat)
context("partGL")

	if( !exists(".partGLRHLightResponseCost") ) .partGLRHLightResponseCost <- REddyProc:::.partGLRHLightResponseCost
	if( !exists(".partGPAssociateSpecialRows") ) .partGPAssociateSpecialRows <- REddyProc:::.partGPAssociateSpecialRows
	if( !exists(".binUstar") ) .binUstar <- REddyProc:::.binUstar

#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

# 8 first days of June from IT-MBo.2005.txt
# 10 days from June from Example_DETha98.txt shipped with REddyProc
.tmp.f <- function(){
	#save(dsNEE, file="tmp/dsNEE_Tharandt.RData")
	load("tmp/dsNEE_Tharandt.RData") # dsNEE
	dsNEE$Temp <- dsNEE$Tair_f
	dsNEE$Rg_f <- dsNEE$Rg
	dsNEE$isNight <- (dsNEE$Rg_f <= 4 & dsNEE$PotRad_NEW == 0)
	dsNEE$isDay=(dsNEE$Rg_f > 4 & dsNEE$PotRad_NEW != 0)
}

.tmp.f2 <- function(){
	# else stop in partitionNEEGL, and grap ds:
	attr(ds$sDateTime, "tzone") <- "UTC"
	dsJune <- ds
	dsNEE <- dsJune[ dsJune$sDateTime >= as.POSIXct("1998-06-01", tz="UTC") & dsJune$sDateTime < as.POSIXct("1998-06-10", tz="UTC")
		, c("sDateTime","NEE_f","NEE_fqc","NEE_fsd","Tair_f","Tair_fqc","VPD_f","VPD_fqc","Rg_f","PotRad_NEW")]
	save(dsNEE, file="tmp/dsNEE_Tharandt.RData")
	dput(dsNEE)
}

dsNEE <- structure(list(sDateTime = structure(c(896660100, 896661900, 
								896663700, 896665500, 896667300, 896669100, 896670900, 896672700, 
								896674500, 896676300, 896678100, 896679900, 896681700, 896683500, 
								896685300, 896687100, 896688900, 896690700, 896692500, 896694300, 
								896696100, 896697900, 896699700, 896701500, 896703300, 896705100, 
								896706900, 896708700, 896710500, 896712300, 896714100, 896715900, 
								896717700, 896719500, 896721300, 896723100, 896724900, 896726700, 
								896728500, 896730300, 896732100, 896733900, 896735700, 896737500, 
								896739300, 896741100, 896742900, 896744700, 896746500, 896748300, 
								896750100, 896751900, 896753700, 896755500, 896757300, 896759100, 
								896760900, 896762700, 896764500, 896766300, 896768100, 896769900, 
								896771700, 896773500, 896775300, 896777100, 896778900, 896780700, 
								896782500, 896784300, 896786100, 896787900, 896789700, 896791500, 
								896793300, 896795100, 896796900, 896798700, 896800500, 896802300, 
								896804100, 896805900, 896807700, 896809500, 896811300, 896813100, 
								896814900, 896816700, 896818500, 896820300, 896822100, 896823900, 
								896825700, 896827500, 896829300, 896831100, 896832900, 896834700, 
								896836500, 896838300, 896840100, 896841900, 896843700, 896845500, 
								896847300, 896849100, 896850900, 896852700, 896854500, 896856300, 
								896858100, 896859900, 896861700, 896863500, 896865300, 896867100, 
								896868900, 896870700, 896872500, 896874300, 896876100, 896877900, 
								896879700, 896881500, 896883300, 896885100, 896886900, 896888700, 
								896890500, 896892300, 896894100, 896895900, 896897700, 896899500, 
								896901300, 896903100, 896904900, 896906700, 896908500, 896910300, 
								896912100, 896913900, 896915700, 896917500, 896919300, 896921100, 
								896922900, 896924700, 896926500, 896928300, 896930100, 896931900, 
								896933700, 896935500, 896937300, 896939100, 896940900, 896942700, 
								896944500, 896946300, 896948100, 896949900, 896951700, 896953500, 
								896955300, 896957100, 896958900, 896960700, 896962500, 896964300, 
								896966100, 896967900, 896969700, 896971500, 896973300, 896975100, 
								896976900, 896978700, 896980500, 896982300, 896984100, 896985900, 
								896987700, 896989500, 896991300, 896993100, 896994900, 896996700, 
								896998500, 897000300, 897002100, 897003900, 897005700, 897007500, 
								897009300, 897011100, 897012900, 897014700, 897016500, 897018300, 
								897020100, 897021900, 897023700, 897025500, 897027300, 897029100, 
								897030900, 897032700, 897034500, 897036300, 897038100, 897039900, 
								897041700, 897043500, 897045300, 897047100, 897048900, 897050700, 
								897052500, 897054300, 897056100, 897057900, 897059700, 897061500, 
								897063300, 897065100, 897066900, 897068700, 897070500, 897072300, 
								897074100, 897075900, 897077700, 897079500, 897081300, 897083100, 
								897084900, 897086700, 897088500, 897090300, 897092100, 897093900, 
								897095700, 897097500, 897099300, 897101100, 897102900, 897104700, 
								897106500, 897108300, 897110100, 897111900, 897113700, 897115500, 
								897117300, 897119100, 897120900, 897122700, 897124500, 897126300, 
								897128100, 897129900, 897131700, 897133500, 897135300, 897137100, 
								897138900, 897140700, 897142500, 897144300, 897146100, 897147900, 
								897149700, 897151500, 897153300, 897155100, 897156900, 897158700, 
								897160500, 897162300, 897164100, 897165900, 897167700, 897169500, 
								897171300, 897173100, 897174900, 897176700, 897178500, 897180300, 
								897182100, 897183900, 897185700, 897187500, 897189300, 897191100, 
								897192900, 897194700, 897196500, 897198300, 897200100, 897201900, 
								897203700, 897205500, 897207300, 897209100, 897210900, 897212700, 
								897214500, 897216300, 897218100, 897219900, 897221700, 897223500, 
								897225300, 897227100, 897228900, 897230700, 897232500, 897234300, 
								897236100, 897237900, 897239700, 897241500, 897243300, 897245100, 
								897246900, 897248700, 897250500, 897252300, 897254100, 897255900, 
								897257700, 897259500, 897261300, 897263100, 897264900, 897266700, 
								897268500, 897270300, 897272100, 897273900, 897275700, 897277500, 
								897279300, 897281100, 897282900, 897284700, 897286500, 897288300, 
								897290100, 897291900, 897293700, 897295500, 897297300, 897299100, 
								897300900, 897302700, 897304500, 897306300, 897308100, 897309900, 
								897311700, 897313500, 897315300, 897317100, 897318900, 897320700, 
								897322500, 897324300, 897326100, 897327900, 897329700, 897331500, 
								897333300, 897335100, 897336900, 897338700, 897340500, 897342300, 
								897344100, 897345900, 897347700, 897349500, 897351300, 897353100, 
								897354900, 897356700, 897358500, 897360300, 897362100, 897363900, 
								897365700, 897367500, 897369300, 897371100, 897372900, 897374700, 
								897376500, 897378300, 897380100, 897381900, 897383700, 897385500, 
								897387300, 897389100, 897390900, 897392700, 897394500, 897396300, 
								897398100, 897399900, 897401700, 897403500, 897405300, 897407100, 
								897408900, 897410700, 897412500, 897414300, 897416100, 897417900, 
								897419700, 897421500, 897423300, 897425100, 897426900, 897428700
						), class = c("POSIXct", "POSIXt"), tzone = "UTC"), NEE_f = c(4.1960303030303, 
						4.10934375, 4.43365789473684, 4.14159459459459, 4.738, 4.59211904761905, 
						4.76740909090909, 14.68, 0.41, -3.51, -4.66, -1.31, -2.65, -4.37, 
						-7.36, -4.9, -15.41, -17.37, -23.71, -24.74, -18.22, -31.37, 
						-19.82, -18.58, -17.39, -17.43, -16.2, -28.04, -10.63, -12.34, 
						-8.65, -12.73, 0.87, -8.58, -8.29, -3.08, -3.24, -0.68, 3.49, 
						2.7, 3.04, 4.59, 3.886625, 2.933, 3.98753333333333, 3.98753333333333, 
						3.61592857142857, 3.61592857142857, 3.61592857142857, 3.61592857142857, 
						3.61592857142857, 3.61592857142857, 3.61592857142857, 3.61592857142857, 
						3.61592857142857, 3.61592857142857, 3.1120625, 1.93, -1.79, -4.55428571428571, 
						-13.8055555555556, -17.5555555555556, -18.0776923076923, -18.1815384615385, 
						-24.2675, -21.928, -17.89, -12.07, -12.9583333333333, -17.75, 
						-13.575, -13.25, -15.65, -10.02, -13.8971428571429, -14.95, -10.015, 
						-7.71, -10.76, -11.59, -4.57, -6.8, -0.46, -3.11, -0.44, -2.7, 
						5.61, 2.78, 3.509, 4.61, 3.64, 5.31, 1.39, 4.86878947368421, 
						4.84617948717949, 4.730775, 4.62386363636364, 9.16, 4.67611904761905, 
						4.730775, 5.07, 9.44, 3.68, 4.89, 11.06, 4.49726315789474, 4.36317647058824, 
						0.6, 0.526923076923077, -0.35, 1.66, -4.7, -6.78, -21.3314285714286, 
						-9.21647058823529, -11.38, -8.93, -14.24, -13.39, -19.02, -11.78, 
						-17.81, -23.5, -15.1927272727273, -13.899, -22.15, -15.83, -11.59, 
						-9.94, -6.92, -2.74, -4.12, -2.65, -1.58, 3.663, 3.646, 3.616, 
						4.66109523809524, 4.55721276595745, 4.37677777777778, 4.57465384615385, 
						4.60647169811321, 4.39544230769231, 3.349, 5.82, 4.40038775510204, 
						4.38164, 4.27934615384615, 4.31362962962963, 4.27934615384615, 
						4.31362962962963, 4.32357692307692, 4.18546428571429, 0.52, -3.33, 
						-0.98, -2.05, -21.11, -7.6, -6.77, -10.44, -19.08, -18.66, -11.43, 
						-16.83, -12.04, -14.82, -15.5, -16.96, -13.57, -19.4, -20.82, 
						-14.31, -16.85, -12.54, -10.68, -8.36, -5.24, -3.4, -5.57, -1.53, 
						-1.03, 3.783, 3.765, 3.734, 4.86866666666667, 4.85652631578947, 
						4.74207692307692, 4.4281875, 4.72565909090909, 4.75571428571429, 
						4.85897619047619, 4.797425, 4.65044736842105, 4.40288888888889, 
						4.43685714285714, 4.461, 4.46514285714286, 4.57367741935484, 
						4.57367741935484, 2.25, -0.272093023255814, 9.94, -0.43, -10.9475, 
						4.34, -8.45, -19.061, -16.065, -17.33125, -20.55, -7.83, -3.9, 
						-10.85, -10.73, -7.1, -9.25, -9.6, -5.9, -3.77, -1.46, 1.18, 
						-1.94, 1.18, -2.73, -1.38, -0.78, -1.09, -0.33, 2.16, 5.02, 6.32, 
						9.7, 6.68, 5.56, 4.92, 2.82, 6.52, 5.5, 2.56, 7.86, 4.82, 4.363, 
						5.56, 6.81, 4.36, 4.06, 4.25, 3.58, 1.06, -1.78, -6.89, -5.09, 
						-10.46, -13.23, -8.185, -3.31333333333333, -14.0544444444444, 
						-10.9146153846154, -11.9492857142857, -11.4726315789474, -0.8475, 
						-4.85, 0.37, -1.04, 3.96, -1.32, -1.18, -1.52, -1.19, -2.05, 
						0.31, -0.01, -1.03, -0.51, 3.26, 2.75, 5.42, 9.87, 3.42, 5.702, 
						16.81, 2.97, 5.7997619047619, 5.69886363636364, 5.87725, 5.73119047619048, 
						5.66713636363636, 5.3855625, 4.85285714285714, 4.94438461538462, 
						4.90064285714286, 5.3855625, 5.3855625, 4.94438461538462, 4.90064285714286, 
						4.94438461538462, 2.32, -2.02, -2.945, -7.55, -9.6425, -12.895, 
						-10.25, -13.4526666666667, -7.905, -9.165, -6.32, 0.17, -14.3533333333333, 
						-9.02666666666667, -9.425, -12.8025, -9.035, -8.57478260869565, 
						-10.991, -12.9656097560976, 2.32, 1.97023255813954, 5.94, -1.27, 
						-7.04333333333333, -16.135, -10.3363829787234, -0.114848484848485, 
						2.8140625, 6.35733333333333, 4.924, 4.30169230769231, 4.772, 
						4.57369230769231, 4.881625, 4.236625, 4.72334615384615, 4.35, 
						11.94, 7.76, 3.44, 4.1, 4.98, 6.23, 3.74, 7.03, 3.85, 3.72, 2.5275, 
						0.95, -1.41133333333333, 0.14, -1.08, -1.99, -3.05, -3.51, -6.54, 
						-6.61, -11.96, 3.63, -14.7, -10.26, -11.12, -16.49, -11.48, -19.2, 
						-24.25, -13.08, -18.81, -20.05, -18.78, -15.83, -11.4, -9.51333333333333, 
						-7.12, -3, 0.22, 4.006, 4.006, 3.987, 3.954, 4.96, 3.875, 4.68322916666667, 
						4.86950980392157, 4.81164150943396, 5.22405357142857, 5.35267857142857, 
						5.2169649122807, 5.19295081967213, 5.17129032258064, 5.20190476190476, 
						5.19875, 5.19230769230769, 5.16388059701493, 4.78684931506849, 
						1.38, -1.75, -5.73, -8.91, -10.17, -12.44, -12.57, -12.67, -13.96, 
						-15.57, -11.84, -8.88, -14.33, -13.98, -14.51, -8.34, -10.54, 
						-12.17, -12.98, -11.8, -12.45, -8.35, -6.82, -5.88, -2.43, -3.14, 
						-3.41, -1.43, 0.34, 4.332, 4.322, 4.302, 4.18992, 4.81429166666667, 
						4.53585714285714), NEE_fqc = c(1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 
						0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
						0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 
						1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1, 0, 0, 
						0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 
						1, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 
						0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
						0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 
						0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
						0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
						1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
						0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
						0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 1, 1, 1, 1, 1, 
						0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
						1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 
						1, 2, 1, 1, 2, 2, 1, 1, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 
						1, 1, 2, 2, 2, 2, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 
						0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
						0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 
						1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
						0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1), NEE_fsd = c(4.16363460125922, 
						4.16366125027679, 4.12220247661117, 3.94271517033813, 4.00575817859314, 
						4.002254883964, 3.92991287741872, 4.18288071775, 4.0549961194074, 
						4.34479453867882, 4.57699387529336, 4.41395424347512, 4.27220954357771, 
						4.65706293941524, 5.81847623237104, 6.71601304534889, 8.55494162750395, 
						7.86318469383823, 8.01804188778568, 5.82650797975041, 6.0054554410923, 
						6.05339098557515, 5.74739212599941, 6.54369745355303, 6.05749944971796, 
						8.0832915878828, 7.67271038062693, 7.76157238466233, 6.7987212817701, 
						5.58789539987999, 5.80256510720576, 4.96952916865398, 5.52680865962573, 
						6.07015880534257, 6.04032509660923, 4.43893221741099, 3.70478100199287, 
						2.13824694551401, 1.74315873299624, 1.75991590708193, 1.77391661013304, 
						1.78377793367523, 1.78377793367523, 1.79849456358314, 1.79849456358314, 
						1.79849456358314, 1.11924551952064, 1.11924551952064, 1.11924551952064, 
						1.11924551952064, 1.11924551952064, 1.11924551952064, 1.11924551952064, 
						1.11924551952064, 1.11924551952064, 1.11924551952064, 1.72936136454087, 
						1.88485947436281, 3.54208036799468, 4.25451468890345, 3.64393026521883, 
						6.51596522226583, 5.39678322992218, 6.20970053780621, 5.04828931421328, 
						6.81764035425748, 3.36243215544939, 2.98267776782318, 3.70473435844821, 
						3.10416195269696, 3.14969839825974, 2.91701004781396, 3.14736715366987, 
						3.14094652214027, 4.12950648498387, 3.78150029015528, 3.58001629419011, 
						3.72552792679552, 2.9519180205419, 3.04495103174325, 5.09231272496975, 
						2.86888421980858, 3.23822470536315, 3.29718061379719, 2.87662666197422, 
						1.57762455686524, 1.6698462509746, 2.16415463213581, 2.36168732084128, 
						2.40557102748058, 2.47383969164624, 2.43741633874957, 2.47237506599767, 
						2.47290192981461, 2.44422865748982, 2.52067363287307, 2.41685461158313, 
						2.38646156757794, 2.47163180226542, 2.52067363287307, 2.52067363287307, 
						2.44455269989155, 2.50326483767918, 2.43230985464137, 2.35090377141409, 
						3.7602974988992, 4.24122387618414, 4.11676174592692, 3.9502961589721, 
						3.70722959423446, 7.40196573431856, 6.84207667209402, 6.5944930233714, 
						5.03330384728039, 8.605555575598, 6.80319959738833, 9.60502776327759, 
						7.18519917152635, 7.22989142380437, 3.56979457859039, 5.03360264180195, 
						3.13168218906921, 4.49621136810389, 3.13491655681325, 4.5351379986354, 
						4.5760297780294, 5.06870294294403, 6.11324287604692, 4.87971913367249, 
						4.84723069953819, 4.03745942040642, 3.41323242038329, 4.22108291228459, 
						2.63472508053497, 2.11425548217391, 2.23444389081926, 2.43899145350213, 
						2.50056800190914, 2.38777318433588, 2.52603402669885, 3.64643070114053, 
						3.63964132110555, 3.61072086884112, 3.45780190782027, 3.45663486709972, 
						3.49231281302429, 3.45903449876891, 3.44234425301413, 3.42469026995775, 
						3.44234425301413, 3.42469026995775, 3.40385510593534, 3.43882268946952, 
						3.94616822730113, 3.39167269004007, 4.22483529689827, 6.03234435046385, 
						7.20854206370543, 6.86468202764406, 8.20188903908873, 5.6166003952569, 
						3.19714959855737, 2.54630102087104, 3.01151480630121, 4.18509358716544, 
						3.55672960098817, 2.86594204573711, 2.82444730241202, 4.10689953730595, 
						3.76090119223808, 4.10828757339531, 5.41467714378508, 4.84345729530349, 
						4.20860937331357, 5.29002023649854, 4.89150546501644, 4.821268159589, 
						2.80832269578059, 4.84501197373557, 4.72444776314298, 4.18855614912574, 
						1.75609597599991, 2.19674726240497, 2.20396999838353, 2.35730731851035, 
						2.38682908273203, 2.4176478823585, 2.57836003962347, 2.3332387284836, 
						2.67292616366915, 2.93326792939967, 3.06431519814226, 3.12888917691411, 
						2.89884091186291, 2.43121164122839, 2.45802293990704, 2.49077197477068, 
						2.46217091133793, 2.5778643148557, 2.5778643148557, 2.56683257596125, 
						3.35663561588197, 5.63827102837332, 4.90313868863609, 6.4335542276412, 
						7.29954911760044, 5.58169535866327, 4.59440589799765, 4.99656181789038, 
						4.47602322699195, 2.66699402752559, 4.50849885269608, 3.82397569965019, 
						3.42545748395145, 2.85519458375627, 1.90264289870695, 2.80025643666988, 
						2.80025643666988, 2.84931395251559, 1.91139347074327, 1.63341666454092, 
						2.20617315730203, 2.20617315730203, 2.82842712474619, 1.40714249456123, 
						0.0707106781186548, 0.0424264068711929, 0.55075705472861, 1.01707095786544, 
						0.643467170879758, 3.65570980405018, 3.3479788217933, 3.04069064366571, 
						2.89786863925236, 1.67699820166256, 3.03889587875346, 3.31266845076683, 
						3.09079375386766, 3.21917033977244, 3.09079375386766, 2.94982814599581, 
						1.67699820166256, 1.67699820166256, 1.65921006003861, 1.61974482352417, 
						1.60501953108263, 1.56824446648686, 1.58190228311781, 1.22326755267798, 
						1.7819090885901, 1.55468324748162, 3.87755492833077, 2.77991846403211, 
						3.52586159682992, 6.04086362479185, 7.13470742217226, 1.3494196283341, 
						7.79967663147361, 7.61071132832385, 8.17655604037046, 6.73882766107088, 
						3.6270224243402, 3.18222092256336, 3.18222092256336, 3.18222092256336, 
						3.18222092256336, 3.18222092256336, 6.7009130743065, 7.62127961150007, 
						0.608111831820431, 0.608111831820431, 7.61611406536263, 7.06477388173181, 
						5.53408230569201, 5.17188558303145, 4.24898502312118, 1.88797510576808, 
						4.48252382391134, 5.38784435558415, 4.82046427323383, 4.82046427323383, 
						3.65570980405018, 3.3479788217933, 3.04069064366571, 3.0049115714024, 
						3.09833692019648, 3.07519562985914, 3.01608478937678, 1.64706296049463, 
						1.03178007921656, 1.01302957660521, 0.98695238815432, 1.64706296049463, 
						1.64706296049463, 1.01302957660521, 0.98695238815432, 1.01302957660521, 
						1.7819090885901, 0.597327380922723, 2.63221706298448, 1.76783766223033, 
						3.06317237516925, 1.74655374953077, 4.21435641587182, 6.58997124063383, 
						1.53442171517481, 4.64569155239562, 3.68243126208759, 7.43876333808248, 
						2.97005611619264, 1.8252762348021, 0.247487373415291, 3.93715104273805, 
						4.60326514552442, 6.16977520554489, 7.01041248129486, 6.85125282294431, 
						1.7819090885901, 4.0230014194404, 4.96773590280321, 4.30774883204673, 
						0.857807282163851, 5.47451367703105, 5.10480695267233, 3.46515900064729, 
						4.18391378694792, 4.07262879886362, 3.18156020426038, 2.37310718906021, 
						2.88529489227438, 2.90210734882474, 2.89235894210936, 0.802841727419368, 
						3.07934791723583, 3.22706658714067, 3.72210297717934, 3.807294815112, 
						3.72719248907547, 3.72719248907547, 3.72719248907547, 3.72719248907547, 
						4.0624133433895, 4.12392287664901, 4.11012932550768, 4.11036396082158, 
						4.73110410502999, 3.35570046030969, 4.32390207976572, 4.32600086312311, 
						2.54726039863645, 3.01835864152835, 2.47954178655339, 4.67279318652358, 
						6.07491061662639, 5.61328557976521, 5.0274856493105, 6.25376260076017, 
						5.25621884132848, 5.95941667101936, 5.65430990199832, 6.92195566118699, 
						6.65924333082449, 4.61124330687124, 6.31325730330847, 5.83373979536283, 
						6.14265795756411, 5.90027753584524, 6.41018163326349, 5.69066887300801, 
						4.27102509441736, 4.33806984729384, 3.87781872903287, 2.48733550452847, 
						4.53969242049803, 2.70489704055441, 2.70489704055441, 2.90406102475204, 
						3.10237005870664, 3.09932635889867, 3.04302739708817, 3.49735520278544, 
						3.54167186155098, 3.62365070959756, 3.99663493645088, 4.07130920246521, 
						3.96115150540179, 3.95636005871655, 3.92750186061709, 3.8624987679893, 
						3.83180451087002, 3.8021054608067, 3.75941689757459, 3.85027416293392, 
						3.64193141676837, 5.44886930652376, 5.18292931169238, 4.92241433817458, 
						5.53613265392953, 5.59836493987307, 5.44778334126214, 6.34172908423072, 
						3.92941085187807, 4.4883766553176, 4.91881664049974, 3.2988026447317, 
						3.39577662529338, 3.11364256137406, 2.76580006508063, 2.94348247674572, 
						2.98912696284383, 4.00252420354956, 2.32103425222464, 3.49989999857139, 
						5.06243024643303, 2.70114790413261, 3.52139177030901, 3.81943713130613, 
						4.35367316182554, 5.94429979055565, 4.59833574966712, 1.10699292379551, 
						1.53744376590929, 1.6930251160211, 1.31667420218904, 0.960701018849802, 
						0.954500825911988, 2.18561372296536, 2.48553083436344), Tair_f = c(14.9, 
						14.8, 15.2, 14.9, 15.5, 15.3, 15.5, 14.1, 13.9, 13.9, 14, 14.1, 
						13.6, 13.7, 14, 14.1, 14.5, 14.6, 14.8, 15.4, 15, 15.2, 15.4, 
						15.5, 14.9, 15.1, 14.6, 14.3, 13.9, 13.7, 12.9, 12.9, 12.4, 12, 
						12, 11.4, 11.3, 11, 11, 11.1, 11.2, 11.1, 10.6, 10.5, 10.2, 10.2, 
						10, 10, 10.2, 10, 10.1, 10.3, 10.3, 10.4, 10.4, 10.1, 10, 9.6, 
						9.7, 10, 11.3, 12.4, 13.6, 14.6, 15.1, 15.7, 16.4, 17.1, 18.4, 
						18.5, 19, 19.7, 20.1, 20.6, 21.3, 21.2, 21.6, 21.4, 21.4, 22.1, 
						22.6, 22.4, 22.3, 22, 22, 21.4, 20.7, 19.7, 19, 18.7, 18.4, 18.4, 
						18.1, 18.1, 18.1, 17.9, 17.6, 17.6, 17.9, 18.1, 18.1, 17.7, 18.1, 
						17.9, 17.6, 14.7, 13.8, 14, 14.5, 14.8, 15.2, 15.9, 15.9, 16.1, 
						15.9, 15.3, 15.9, 16.8, 17.6, 18.5, 18.4, 19.1, 19.3, 19.5, 19.9, 
						20, 20.4, 20.2, 20.8, 21.3, 21.5, 21.4, 21.2, 20.6, 20, 19.4, 
						18.8, 18, 17.6, 17, 16, 15.4, 15.2, 15.1, 15.1, 14.5, 14.6, 14.8, 
						14.9, 14.8, 15.1, 14.7, 14.8, 15.3, 15.9, 16.1, 16.2, 17, 17.1, 
						16.9, 17.8, 18.5, 19, 19, 19.6, 19.7, 20.2, 20.7, 20.5, 21.1, 
						20.6, 21.1, 21.1, 21.3, 21.5, 21.4, 21.4, 20.8, 20.3, 20.2, 20.1, 
						19.9, 19.5, 19.6, 19.2, 19, 19, 18.3, 17.2, 16.6, 16.5, 16.2, 
						16.1, 16.3, 16.4, 16.4, 16.3, 16.7, 16.9, 16.9, 16.8, 14.1, 13.9, 
						14.4, 15.4, 16.5, 17, 17.9, 18.6, 19.5, 20.3, 20.7, 21.8, 22.5, 
						23.8, 24.4, 25.2, 25.8, 26.2, 26.7, 27.1, 27.2, 27.8, 27.6, 27.5, 
						27.5, 27.3, 27.1, 26.7, 26.1, 25.5, 24.7, 24, 23.2, 23, 23.5, 
						23.8, 23.5, 23.9, 23.7, 23.4, 23, 22.5, 22, 21.9, 21.7, 21.7, 
						21.6, 21.5, 21.7, 22, 22.5, 23.3, 24.3, 25.4, 26.1, 27.3, 27.5, 
						28.4, 28.4, 29.6, 29.9, 30.3, 30.6, 30.3, 30.4, 30.8, 30.9, 31.5, 
						31.7, 31.8, 31.5, 30.4, 29.9, 29.4, 28.9, 28.5, 27.9, 27.5, 26.9, 
						26.6, 25.5, 24.8, 24, 23.9, 24.1, 23.9, 23.4, 23, 22.4, 22.6, 
						23, 23.1, 23.1, 22.8, 22.8, 22.5, 22.5, 22.6, 22.5, 21.4, 22.5, 
						23.4, 24.8, 25.3, 25.8, 25.5, 25, 24.8, 25, 25.8, 26.9, 25.7, 
						23.2, 23, 24.3, 24.2, 23, 20.5, 18.5, 18.8, 19, 20.4, 21.7, 21.1, 
						20.6, 19.9, 19.4, 18.8, 18.3, 18.3, 18.3, 17.3, 16, 15, 14.6, 
						14.4, 14.2, 14.1, 14.1, 14, 13.9, 13.8, 13.8, 13.8, 13.6, 14, 
						14.2, 14.5, 14.6, 14.1, 14.1, 14.2, 14.6, 14.4, 13.4, 14, 14.2, 
						14.1, 14.2, 14.5, 14.9, 15.7, 16.1, 16.3, 16.6, 17.1, 18.1, 18.6, 
						18.7, 18.9, 18.6, 18.3, 18, 18, 18, 16.4, 15.5, 15.3, 15.2, 14.7, 
						14.4, 14, 13.9, 13.8, 13.9, 13.6, 13.5, 13.4, 13.4, 13.4, 13.1, 
						13.1, 13.3, 13.9, 14.9, 15.9, 16.8, 17.6, 18, 18.3, 18.9, 19.5, 
						19.9, 20.8, 21.1, 21.7, 22.2, 22, 22.5, 22.5, 23, 23.2, 23.1, 
						23.8, 23.6, 23.8, 23.8, 23.8, 23.7, 23.5, 22.9, 22.1, 21.3, 20.9, 
						20.2, 19.5, 18.9), Tair_fqc = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
						0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
						0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
						0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
						0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
						0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
						0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
						0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
						0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
						0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
						0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
						0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
						0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
						0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
						0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
						0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
						0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
						0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
						0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
						0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
						0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), VPD_f = c(3.8, 
						4, 4.8, 4.6, 5.5, 5.3, 5.2, 3.2, 3, 3.2, 3.4, 3.4, 2.7, 2.9, 
						3.3, 3.3, 4, 4.2, 4.4, 5.1, 4.8, 5, 5.2, 5.3, 4.4, 4.4, 3.7, 
						3.6, 3.5, 3.1, 2.2, 2.3, 2.1, 1.9, 2.2, 1.7, 1.8, 1.6, 1.6, 1.6, 
						1.7, 1.7, 1.3, 1.2, 1.2, 1.4, 1.4, 1.4, 1.4, 1.3, 1.5, 1.8, 2, 
						2, 2, 2, 1.9, 1.7, 1.8, 1.9, 2.6, 3.4, 4.6, 5.9, 7.2, 7.8, 8.8, 
						10.3, 11.9, 12, 13.2, 14.4, 15.4, 15.6, 17, 16.4, 16.8, 16, 15.8, 
						16.7, 16.9, 16.5, 16.3, 15.6, 15.5, 14.4, 13.5, 12.3, 11.4, 11.3, 
						11.1, 11, 10.5, 10.2, 10, 9.7, 9.1, 9, 9.3, 9.7, 9.6, 9.1, 9.6, 
						9.1, 8.3, 2.2, 1.2, 1.4, 1.5, 1.7, 1.8, 2.1, 2, 2.3, 2.4, 2.7, 
						2.8, 4, 5.4, 7.4, 8, 9.2, 10.1, 11.1, 11.1, 11.3, 11.9, 11.5, 
						12.8, 15, 15.5, 15.1, 14.6, 13.1, 12.1, 11.2, 10.2, 9, 8.7, 7.9, 
						6.6, 5.6, 5.5, 5.6, 5.5, 4.9, 4.8, 4.7, 4.9, 4.8, 5, 4.6, 4.4, 
						4.7, 4.9, 5, 5, 6, 7.1, 7.3, 9.4, 10.5, 10.7, 10.9, 11.6, 12.2, 
						12.6, 13.5, 13.8, 15, 14.3, 15, 15, 15.2, 15.3, 14.7, 14.5, 13.2, 
						12.5, 12, 12, 11.5, 10.9, 11.5, 11.2, 11, 10.8, 9.8, 7.9, 7.4, 
						7.5, 7.3, 7.4, 8.1, 8.5, 8.5, 8.4, 9, 9.4, 9.4, 9.2, 5.9, 5.4, 
						5.6, 6.4, 8, 8.3, 8.9, 9.6, 10.9, 11.5, 11.8, 13.4, 13.9, 15.6, 
						16.4, 17.7, 20, 21.4, 22.8, 23.8, 24.2, 25.7, 25.1, 24.5, 24.4, 
						23.7, 22.6, 21.4, 20, 18.3, 16.6, 15, 13.7, 13.8, 15.7, 16.6, 
						16, 16.4, 16, 15.1, 14.3, 13.1, 12.1, 11.5, 11.1, 10.9, 10.7, 
						10.4, 10.5, 10.8, 11.4, 12.5, 14, 15.9, 16.7, 19.5, 18.7, 20.7, 
						19.4, 25.1, 27.1, 29.9, 31.6, 30.3, 30.2, 31.1, 31.5, 33.4, 34.2, 
						33.8, 32.2, 28.7, 27, 25.8, 24.6, 23.2, 21.2, 19.3, 17.5, 16.7, 
						15.3, 15.6, 13.9, 13.7, 14.1, 13.2, 11.8, 10.4, 9.4, 9.4, 10, 
						10.2, 10.2, 9.8, 10, 9.5, 9.6, 9.7, 9.3, 7.1, 8.3, 9.5, 11.7, 
						13.8, 15.5, 14.6, 13.6, 12.8, 12.6, 14, 16.2, 12.9, 8.2, 7.1, 
						8.5, 8.2, 5.9, 3.2, 3.4, 3.6, 2.9, 4.4, 4.9, 3.2, 4.4, 3.6, 2.4, 
						2.3, 2, 1.6, 2.2, 2.4, 1.9, 1.8, 1.7, 1.6, 1.5, 1.5, 1.6, 1.6, 
						1.6, 1.6, 1.7, 1.7, 1.5, 1.9, 2, 2, 1.9, 1.2, 1.1, 1, 1.2, 1.4, 
						1.2, 1.4, 2, 2.1, 2.2, 2.9, 4, 5.6, 6.1, 6.3, 6.6, 7.3, 8.4, 
						9.1, 9.5, 9.6, 9.4, 8.9, 8.4, 8.1, 8.5, 5.1, 4.3, 4.1, 4, 3.6, 
						3.2, 2.8, 2.9, 3, 3.3, 3.5, 3.6, 3.6, 3.9, 4, 3.7, 4, 4.3, 4.9, 
						5.8, 6.7, 7.5, 8.3, 8.7, 10.4, 11.9, 13.1, 13.6, 14.6, 15, 16.3, 
						17.4, 16.7, 17.4, 17.1, 17.4, 17.9, 17.9, 19.4, 19.5, 19.4, 19.2, 
						19.3, 18.4, 18, 16.6, 14.9, 13.8, 13, 11.4, 10.1, 9.5), VPD_fqc = c(0, 
						0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
						0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
						0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
						0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
						0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
						0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
						0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
						0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
						0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
						0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
						0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
						0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
						0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
						0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
						0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
						0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
						0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
						0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
						0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
						0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
						0, 0, 0, 0, 0, 0, 0), Rg_f = c(0, 0, 0, 0, 0, 0, 0, 0, 7.6, 28.21, 
						72.65, 58.6, 64.96, 88.09, 129.71, 181.79, 249.7, 275.14, 334.38, 
						436.75, 446.38, 485.57, 436.23, 465.6, 397.78, 373.51, 264.65, 
						335.03, 279.05, 186.92, 157.86, 195.08, 109.75, 157.09, 148.44, 
						68.99, 62.2, 23.19, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
						0, 0, 0, 0.65, 18.18, 63.46, 102.18, 144.81, 259.45, 341.64, 
						445.58, 477.72, 516.94, 518.02, 649.17, 788.36, 807.12, 820.66, 
						861.57, 883.71, 934.16, 866.49, 734.32, 488.3, 461.36, 387.41, 
						304.3, 548.53, 497.1, 282.8, 217.01, 219.53, 177.14, 104.46, 
						0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.25, 1.81, 
						1.75, 11.23, 20.21, 22.18, 44.11, 179.91, 344.17, 326.2, 439.67, 
						247.61, 165.58, 587.41, 338.38, 702.08, 877.56, 516.66, 544.75, 
						626.47, 552.62, 525.21, 468.4, 509.77, 397.1, 472.03, 500.15, 
						405.04, 307.41, 217.25, 136.11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
						0, 0, 0, 0, 0, 0, 0, 0.92, 10.4, 30.54, 54.78, 70.5, 150.72, 
						336.81, 252.93, 378.43, 598.36, 664.71, 711.15, 796.05, 853.26, 
						864.03, 925.24, 891.71, 743.14, 732.38, 628.13, 630.96, 579.5, 
						589.56, 510.88, 477.17, 442.26, 285.11, 232.36, 226.17, 181.08, 
						113.69, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.46, 
						16.67, 52.51, 116.79, 175.91, 237.03, 340.2, 429, 504.94, 579.23, 
						644.62, 707.77, 761.29, 808.66, 841.88, 866.18, 887.1, 890.79, 
						897.56, 892.63, 843.73, 802.51, 711.15, 684.7, 607.13, 502.21, 
						420.85, 344.01, 268.47, 201.75, 109.72, 0, 0, 0, 0, 0, 0, 0, 
						0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11.63, 44.51, 100.55, 169.79, 
						247.24, 324.14, 418.02, 393.32, 574.58, 627.06, 690.55, 741.3, 
						792.67, 840.65, 875.1, 891.71, 897.86, 886.79, 867.41, 813.58, 
						756.37, 675.23, 698.54, 463.33, 348.72, 271.36, 159.39, 104.06, 
						47.86, 22.05, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
						0, 0, 13.72, 39.16, 96.58, 149.74, 260.72, 316.05, 404.52, 441.36, 
						563.94, 670.77, 577.23, 277.63, 222.33, 801.43, 900.32, 878.79, 
						785.28, 341.46, 863.41, 817.58, 362.5, 25.35, 27.65, 34.36, 64.53, 
						159.09, 318.33, 273.7, 60.1, 20.36, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
						0, 0, 0, 0, 0, 0, 0, 0, 0.46, 8.7, 21.81, 63.67, 71.58, 78.25, 
						45.52, 66.16, 57.06, 98.03, 152.54, 136.17, 112.92, 245.27, 116.82, 
						215.28, 241.09, 292.34, 286.89, 438.17, 497.75, 330.11, 382.09, 
						515.13, 632.53, 516.57, 448.41, 281.14, 221.16, 97.54, 48.45, 
						0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.28, 16.7, 
						61.49, 125.96, 202.52, 284.03, 365.73, 447.76, 534.32, 614.45, 
						683.78, 748.68, 805.59, 862.18, 825.27, 897.2475, 996.6, 904.94, 
						941.23, 801.59, 943.39, 688.45, 582.24, 780.67, 640.44, 556.04, 
						465.7, 384.61, 301.13, 205.9, 140.66, 0, 0, 0, 0, 0, 0), PotRad_NEW = c(0, 
						0, 0, 0, 0, 0, 0, 0, 31.0113596762252, 124.182306379573, 221.793025863617, 
						322.173371655182, 423.605808207084, 524.354798407536, 622.69649910131, 
						716.948256524067, 805.497396974778, 886.828820109871, 959.550922730176, 
						1022.41940949748, 1074.35858317276, 1114.47975009418, 1142.09642597201, 
						1156.7360818252, 1158.14822908322, 1146.30870551496, 1121.42008865122, 
						1083.90822962696, 1034.41496675034, 973.787143471304, 903.06211865536, 
						823.450017085794, 736.313023893104, 643.142077189756, 545.531357705712, 
						445.151011914147, 343.718575362245, 242.969585161793, 144.627884468018, 
						50.3761270452619, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
						0, 33.3160607059766, 126.340357520714, 223.806357769276, 324.046391164729, 
						425.345322943889, 525.969900298644, 624.198408812053, 718.350131469362, 
						806.814106192115, 888.076689845959, 960.747457094333, 1023.58299096147, 
						1075.50815804161, 1115.63450432963, 1143.27545691542, 1157.95807143671, 
						1159.43112428826, 1147.66941112736, 1122.87417812717, 1085.46967859886, 
						1036.09591389984, 975.597682833102, 905.010126905481, 825.541018769464, 
						738.550096898259, 645.525800083521, 548.059799834959, 447.819766439507, 
						346.520834660347, 245.896257305591, 147.667748792183, 53.5160261348739, 
						0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 35.4800203141296, 
						128.361131872284, 225.68639289217, 325.790541174076, 426.960766986786, 
						527.466019716958, 625.58662662506, 719.643716922721, 808.027947717396, 
						889.227040315451, 961.85165572989, 1024.65916665563, 1076.57491916719, 
						1116.71062034534, 1144.37953721519, 1159.10824693785, 1160.64473720637, 
						1148.96271824627, 1124.26207264082, 1086.96543528465, 1037.7109619835, 
						977.341410431478, 906.889720393235, 827.561339818226, 740.713599292071, 
						647.832487733916, 550.507226714031, 450.403078432125, 349.232852619415, 
						248.727599889242, 150.606992981141, 56.54990268348, 0, 0, 0, 
						0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 37.50330822859, 130.244848608224, 
						227.433490397721, 327.406308990282, 428.452741742085, 528.843856173385, 
						626.861932482585, 720.829854208291, 809.139804156946, 890.280774600784, 
						962.864421038985, 1025.648817157, 1077.55970453013, 1117.70887348301, 
						1145.40936060339, 1160.18720287662, 1161.78954732421, 1150.18897738841, 
						1125.58398203712, 1088.39555956257, 1039.2600141839, 979.018068705475, 
						908.700479516654, 829.510400064178, 742.802794563117, 650.061254183484, 
						552.872612393986, 452.899793801425, 351.853361049622, 251.462246618322, 
						153.444170309122, 59.4762485834158, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
						0, 0, 0, 0, 0, 0, 0, 39.3860430813494, 131.991771951647, 229.048050264278, 
						328.894218188229, 429.821880107735, 530.104135744918, 628.025127902332, 
						721.909401255335, 810.15056985722, 891.238802848134, 963.786658079697, 
						1026.55282163483, 1078.46334705304, 1118.63003085211, 1146.36560993591, 
						1161.19552085658, 1162.86601972663, 1151.34852384725, 1126.84010076618, 
						1089.76009639736, 1040.74295989607, 980.627388057947, 910.441974984339, 
						831.387612552004, 744.81694282017, 652.211213949873, 555.154935637242, 
						455.30876771329, 354.381105793784, 254.098850156601, 156.177857999188, 
						62.2935846461844, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
						0, 41.1283916918298, 133.602210320652, 230.530512301075, 330.254827512609, 
						431.068845273181, 531.247609787983, 629.077034621365, 722.883231190987, 
						811.061149465552, 892.102040815844, 964.61927312208, 1027.37205643393, 
						1079.28667323055, 1119.47485002513, 1147.24895597042, 1162.13376841328, 
						1163.87460408594, 1152.44167680741, 1128.03060713322, 1091.05907523354, 
						1042.15967426959, 982.169086549364, 912.113767661276, 833.192383534508, 
						746.75530093261, 654.281482303787, 557.353180323365, 457.628865111831, 
						356.814847351258, 256.636082836456, 158.806658003074, 65.0004614334521, 
						0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 42.7305683761548, 
						135.076515506527, 231.88135520456, 331.488729823647, 432.194329567674, 
						532.275053704155, 630.018493295495, 723.752230990684, 811.872456549858, 
						892.871408482155, 965.363172262862, 1028.10739371518, 1080.03050181407, 
						1120.24407778415, 1148.06005619128, 1163.00249793286, 1164.81573368785, 
						1153.46873848977, 1129.15566257245, 1092.29250940568, 1043.51001776054, 
						983.642869594147, 913.715408409934, 834.924112456318, 748.61712265214, 
						656.271175521768, 559.466335823736, 459.858961204648, 359.153361460621, 
						259.07263732414, 161.329197732801, 67.5954600376106, 0, 0, 0, 
						0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 44.1928342826379, 136.415081884726, 
						233.101095653588, 332.59655108721, 433.199053357771, 533.18726575914, 
						630.85036225516, 724.517300187456, 812.585412278626, 893.547828713698, 
						966.019260100444, 1028.75970015496, 1080.69564255298, 1120.9384489207, 
						1148.79955368377, 1163.80224561512, 1165.68982449629, 1154.42999332927, 
						1130.21541094715, 1093.46039556805, 1044.7938356955, 985.048429661859, 
						915.246437928906, 836.582191927964, 750.401658717958, 658.17941111587, 
						561.493397347008, 461.997941913386, 361.395439642824, 261.407227241455, 
						163.744130745436, 70.0771928131399, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
						0, 0, 0, 0, 0, 0, 0, 45.5154967535342, 137.618345658769, 234.190287443711, 
						333.578949409619, 434.083763994513, 533.985065955646, 631.573516318591, 
						725.179349641006, 813.200944162306, 894.132225996035, 966.588438471626, 
						1029.32983570497, 1081.28289499419, 1121.55868509075, 1149.46807605954, 
						1164.53353048313, 1166.4972742594, 1155.32570718789, 1131.20997787854, 
						1094.56271314598, 1046.01095785031, 986.385445985734, 916.706386591575, 
						838.16600769275, 752.108156947724, 660.005308042489, 563.433366257547, 
						464.044704291639, 363.539889706746, 263.638587745612, 166.050137382668, 
						72.4443040602518, 0, 0, 0, 0)), .Names = c("sDateTime", "NEE_f", 
				"NEE_fqc", "NEE_fsd", "Tair_f", "Tair_fqc", "VPD_f", "VPD_fqc", 
				"Rg_f", "PotRad_NEW"), row.names = 7249:7676, class = "data.frame")
dsNEE$Temp <- dsNEE$Tair_f
dsNEE$isNight <- (dsNEE$Rg_f <= 4 & dsNEE$PotRad_NEW == 0)
dsNEE$isDay=(dsNEE$Rg_f > 4 & dsNEE$PotRad_NEW != 0)
		
# regression result from dput in 
resLRCEx1 <- structure(list(resOptList = list(structure(list(opt.parms.V = structure(c(0.057727631357497, 
														26.7860437982592, 0.127675386739064, 3.70812572474264, 101.076168553152
												), .Names = c("k", "beta0", "alfa", "Rb", "E0")), iOpt = 1:5, 
										initialGuess.parms.V.n = structure(c(0, 25.775475, 0.1, 4.63708724196195, 
														101.076168553152), .Names = c("k", "beta0", "alfa", "Rb", 
														"E0")), covParms = structure(c(0.00017151098929435, 0.00452409498388695, 
														-8.15012868562107e-05, -0.00500338006345583, 0, 0.00452409498388695, 
														2.38611495679995, 0.00405805924870779, 0.789790315415903, 
														0, -8.15012868562106e-05, 0.0040580592487078, 0.000416060186647488, 
														0.0162555529616199, 0, -0.00500338006345583, 0.789790315415903, 
														0.0162555529616199, 0.953236941957707, 0, 0, 0, 0, 0, 1040.06004200981
												), .Dim = c(5L, 5L), .Dimnames = list(c("k", "beta0", "alfa", 
																"Rb", "E0"), c("k", "beta0", "alfa", "Rb", "E0")))), .Names = c("opt.parms.V", 
										"iOpt", "initialGuess.parms.V.n", "covParms")), structure(list(
										opt.parms.V = structure(c(0.0726557184779755, 27.1288440292203, 
														0.107092931031202, 4.02327029285789, 89.8099951584634), .Names = c("k", 
														"beta0", "alfa", "Rb", "E0")), iOpt = 1:5, initialGuess.parms.V.n = structure(c(0, 
														25.2232867857143, 0.1, 4.68854660255697, 89.8099951584634
												), .Names = c("k", "beta0", "alfa", "Rb", "E0")), covParms = structure(c(9.12009073811097e-05, 
														0.00186451724028767, -0.00010623823740155, -0.0058357197818203, 
														0, 0.00186451724028767, 2.19791022928612, -0.00594176354964599, 
														0.302455556995159, 0, -0.00010623823740155, -0.00594176354964599, 
														0.000262232141105773, 0.00922073809739433, 0, -0.0058357197818203, 
														0.302455556995159, 0.00922073809739433, 0.579815674883389, 
														0, 0, 0, 0, 0, 891.943053894839), .Dim = c(5L, 5L), .Dimnames = list(
														c("k", "beta0", "alfa", "Rb", "E0"), c("k", "beta0", 
																"alfa", "Rb", "E0")))), .Names = c("opt.parms.V", "iOpt", 
										"initialGuess.parms.V.n", "covParms")), structure(list(opt.parms.V = structure(c(0.0640638097556254, 
														24.5802057457923, 0.127671882231455, 4.56949452128719, 89.8100930253668
												), .Names = c("k", "beta0", "alfa", "Rb", "E0")), iOpt = 1:5, 
										initialGuess.parms.V.n = structure(c(0, 23.7206553846154, 
														0.1, 4.68854628884207, 89.8100930253668), .Names = c("k", 
														"beta0", "alfa", "Rb", "E0")), covParms = structure(c(8.0936637484978e-05, 
														0.0029705471801011, -0.000147993741733685, -0.00533348107477245, 
														0, 0.0029705471801011, 1.80517447877443, -0.00492982775968234, 
														0.206157196700883, 0, -0.000147993741733685, -0.00492982775968231, 
														0.000447552692195042, 0.0132474819067256, 0, -0.00533348107477244, 
														0.206157196700884, 0.0132474819067256, 0.550740061994027, 
														0, 0, 0, 0, 0, 891.943075507185), .Dim = c(5L, 5L), .Dimnames = list(
														c("k", "beta0", "alfa", "Rb", "E0"), c("k", "beta0", 
																"alfa", "Rb", "E0")))), .Names = c("opt.parms.V", "iOpt", 
										"initialGuess.parms.V.n", "covParms")), structure(list(opt.parms.V = structure(c(0.0360593307622046, 
														23.7973845946638, 0.14959156663802, 5.27914716093707, 74.9586032440677
												), .Names = c("k", "beta0", "alfa", "Rb", "E0")), iOpt = 1:5, 
										initialGuess.parms.V.n = structure(c(0, 23.0107602739726, 
														0.1, 4.8107407352963, 74.9586032440677), .Names = c("k", 
														"beta0", "alfa", "Rb", "E0")), covParms = structure(c(0.000106151639145986, 
														0.00710954577372435, -0.000151141366391096, -0.00426117697426513, 
														0, 0.00710954577372435, 2.77127578994385, 0.00680783581834069, 
														0.876006150268337, 0, -0.000151141366391096, 0.00680783581834066, 
														0.000994863723911163, 0.0296336838567208, 0, -0.00426117697426513, 
														0.876006150268336, 0.0296336838567208, 1.18206737153361, 
														0, 0, 0, 0, 0, 1314.28885858365), .Dim = c(5L, 5L), .Dimnames = list(
														c("k", "beta0", "alfa", "Rb", "E0"), c("k", "beta0", 
																"alfa", "Rb", "E0")))), .Names = c("opt.parms.V", "iOpt", 
										"initialGuess.parms.V.n", "covParms"))), summary = structure(list(
								Start = c(1, 3, 5, 7), End = c(4, 6, 8, 10), Num = c(118L, 
										118L, 120L, 90L), iMeanRec = c(95L, 193L, 288L, 360L), iCentralRec = c(97, 
										193, 289, 385), iFirstRec = c(1L, 97L, 193L, 289L), E_0 = c(101.076168553152, 
										89.8099951584634, 89.8100930253668, 74.9586032440677), E_0_SD = c(32.2499618916024, 
										29.8654156826058, 29.8654160444348, 36.2531220529163), R_ref12 = c(4.63708724196195, 
										4.68854660255697, 4.68854628884207, 4.8107407352963), R_ref = c(3.70812572474264, 
										4.02327029285789, 4.56949452128719, 5.27914716093707), R_ref_SD = c(0.976338538601087, 
										0.761456285602391, 0.742118630674387, 1.08722921756804), 
								a = c(0.127675386739064, 0.107092931031202, 0.127671882231455, 
										0.14959156663802), a_SD = c(0.0203975534475948, 0.0161935833312387, 
										0.0211554411959439, 0.0315414603959798), b = c(26.7860437982592, 
										27.1288440292203, 24.5802057457923, 23.7973845946638), b_SD = c(1.54470545956178, 
										1.48253506848443, 1.3435678169614, 1.66471492753079), k = c(0.057727631357497, 
										0.0726557184779755, 0.0640638097556254, 0.0360593307622046
								), k_SD = c(0.0130962204201956, 0.009549916616448, 0.00899647917159696, 
										0.0103029917570571), parms_out_range = c(0L, 0L, 0L, 0L)), .Names = c("Start", 
								"End", "Num", "iMeanRec", "iCentralRec", "iFirstRec", "E_0", 
								"E_0_SD", "R_ref12", "R_ref", "R_ref_SD", "a", "a_SD", "b", "b_SD", 
								"k", "k_SD", "parms_out_range"), row.names = c(NA, 4L), class = "data.frame")), .Names = c("resOptList", 
				"summary"))



test_that("partGL_RHLightResponseGrad matches numerical estimates",{
			#str(ds)
			ds <- dsNEE
			theta0 <- structure(c(0, 27.3333395589509, 0.162207578338878, 2.59392002410639, 185
					), .Names = c("k", "beta0", "alfa", "Rb","E0"))
			res <- partGL_RHLightResponseGrad(theta0, Rg=ds$Rg_f, VPD=ds$VPD_f, Temp=ds$Temp)
			.numDerivLRC <- function(theta, eps=0.0001, ...){
				ans <- matrix( NA, nrow=length(list(...)[[1]]), ncol=length(theta), dimnames=list(NULL,names(theta)))
				i <- 1L
				for( i in seq_along(theta)){
							thetaMinus <- theta; thetaMinus[i] <- theta[i]-eps
							thetaPlus <- theta; thetaPlus[i] <- theta[i]+eps
							fMinus <- partGL_RHLightResponse(thetaMinus, ...)$NEP
							fPlus <- partGL_RHLightResponse(thetaPlus, ...)$NEP
							ans[,i] <- derivI <- (fPlus - fMinus)/(2*eps)
						}
				ans
			}
			res2 <- .numDerivLRC(theta=theta0, Rg=ds$Rg_f, VPD=ds$VPD_f, Temp=ds$Temp)
			expect_true( all(na.omit(abs(res$NEP - res2) < 1e-2)))
			#plot( res$NEP[,4L] ~ res2[,4L])
		})

test_that("estimating temperature sensitivity oneWindow are in accepted range",{
			dss <- dsNEE[ dsNEE$Rg_f <= 0 & dsNEE$PotRad_NEW <= 0 & as.POSIXlt(dsNEE$sDateTime)$mday %in% 1:8, ]
			dss <- dss[ order(dss$Temp), ]
			dss$NEE <- dss$NEE_f
			resE0 <- partGLEstimateTempSensInBoundsE0Only(dss$NEE_f, dss$Temp+273.15)
			expect_true( resE0$E0 >= 50 && resE0$E0 < 400 )
			medianResp <- median(dss$NEE_f,na.rm=TRUE)
			expect_true( abs(resE0$RRefFit - medianResp)/medianResp < 0.2 )
			E0Win <- as.data.frame(resE0)
			res <- partGLFitNightRespRefOneWindow( dss, data.frame(iWindow=1L), E0Win=E0Win)
			RRef <- res[[2]]$RRef[1]
			expect_true( RRef >= 0)
			.tmp.plot <- function(){
				plot( NEE_f ~ Temp, dss)		# FP_VARnight negative?
				lines( fLloydTaylor(RRef, resE0$E0, dss$Temp+273.15, T_ref.n=273.15+15) ~ dss$Temp)#
			}
		})

test_that("estimating temperature sensitivity on record with some freezing temperatures",{
			dss <- dsNEE[ dsNEE$Rg_f <= 0 & dsNEE$PotRad_NEW <= 0 & as.POSIXlt(dsNEE$sDateTime)$mday %in% 1:8, ]
			dss$NEE <- dss$NEE_f
			dss <- dss[ order(dss$Temp), ]
			dss$Temp <- dss$Temp - dss$Temp[ nrow(dss)-14L ] -1	# only the last 13 records will have temperature above -1degC
			isValid <- isValidNightRecord(dss)
			expect_true(sum(isValid) >= 13 && sum(isValidNightRecord(dss)) < nrow(dss) )
			#
			resE0 <- partGLEstimateTempSensInBoundsE0Only(dss$NEE_f[isValid], dss$Temp[isValid]+273.15)
			expect_true( is.na(resE0$E0) )
			.tmp.f <- function(){
				expect_true( resE0$E0 >= 50 && resE0$E0 <= 400 )
				medianResp <- median(dss$NEE_f[isValid],na.rm=TRUE)
				expect_true( abs(resE0$RRefFit - medianResp)/medianResp < 0.2 )
				E0Win <- as.data.frame(resE0)
				res <- partGLFitNightRespRefOneWindow( dss, data.frame(iWindow=1L), E0Win=E0Win)
				RRef <- res[[2]]$RRef[1]
				expect_true( RRef >= 0 )
			}
			.tmp.plot <- function(){
				plot( NEE_f ~ Temp, dss)		# FP_VARnight negative?
				points( NEE_f ~ Temp, dss[isValid,], col="red")
				lines( fLloydTaylor(RRef, resE0$E0, dss$Temp+273.15, T_ref.n=273.15+15) ~ dss$Temp)#
			}
		})

test_that("applyWindows",{
			nRec <- nrow(dsNEE)
			nRecInDay <- 10L
			ds <- within(dsNEE, {
						iRec <-1:nRec
						iDayOfRec <- ((c(1:nRec)-1L) %/% nRecInDay)+1L 			# specifying the day for each record assuming equidistand records
					})
			fReportTime <- function(dss,winInfo, prevRes){
				nRecS <- nrow(dss)
				list( res1=dss$iRec[1], res2=data.frame(
								startRec=dss$iRec[1]	
								,endRec=dss$iRec[nRecS]
								,startDay=dss$iDayOfRec[1]
								,endDay=dss$iDayOfRec[nRecS]
						)
						,prevRes=within(prevRes, sum <- sum +1L)
				)
			}
			prevRes <- list(sum=0)
			fReportTime(ds,0,prevRes)
			resApply <- applyWindows( ds, fReportTime, prevRes, winSizeInDays=6L, nRecInDay=nRecInDay )	# larger than reference window of 4 days
			#resApply <- applyWindows( ds[1:41,], fReportTime, prevRes, winSizeInDays=6L, nRecInDay=nRecInDay )	# larger than reference window of 4 days
			res <- resApply[[2L]]
			nRecRes <- nrow(res)
			expect_equal( res$dayStart, res$startDay )	
			expect_equal( res$dayEnd, res$endDay )	
			expect_equal( res$iRecStart, res$startRec )	
			expect_equal( res$iRecEnd, res$endRec )	
			#
			expect_true( all(diff(res$startDay[-1])==2L))	# shifted starting day
			# day boundary before startRec
			expect_true( all((ds$iDayOfRec[res$startRec[-1]] - ds$iDayOfRec[res$startRec[-1]-1])==1L))   
			# day boundary after endRec
			expect_true( all((ds$iDayOfRec[res$startRec[-nRecRes]]+1 - ds$iDayOfRec[res$startRec[-nRecRes]])==1L))
			# prevRes accumulated
			expect_equal( resApply[[3]]$sum, nrow(res) )
		})



test_that("estimating temperature sensitivity windows outputs are in accepted range",{
			dss <- dsNEE[ dsNEE$Rg_f <= 0 & dsNEE$PotRad_NEW <= 0 & as.POSIXlt(dsNEE$sDateTime)$mday %in% 1:12, ]
			dss$NEE <- dss$NEE_f
			dss <- dss[ order(dss$Temp), ]
			res <- applyWindows(dss, partGLFitNightTempSensOneWindow, prevRes=list(prevE0=NA)
					, winSizeInDays=12L
			#,controlGLPart=controlGLPart	
			)
			#res <- partGLEstimateTempSensInBounds(dss$NEE_f, dss$Temp+273.15)
			expect_true( res$summary$E0 >= 50 && res$summary$E0 <= 400 )
			expect_true( res$summary$RRefFit > 0 )
		})


test_that("RHLightResponseCostC",{
			.tmp.reloadDll <- function(){
				library.dynam.unload("REddyProc", file.path(.libPaths()[1],"REddyProc") )
				installPkg()
				library.dynam("REddyProc","REddyProc", .libPaths()[1] )
			}
			#
			dss <- subset(dsNEE, as.POSIXlt(dsNEE$sDateTime)$mday %in% 1:8 )
			dssDay <- subset(dss, isDay==TRUE)
			theta <- c(k=0, beta0=28.6, alfa=0.18,  Rb=2.87, E0=185)
			flux <- dssDay$NEE_f
			sdFlux <- dssDay$NEE_fsd
			betaPrior <- 26
			sdBetaPrior <- 0.3*betaPrior / sqrt(length(flux))
			parameterPrior <- c(0,betaPrior,8,15, 185)
			sdParameterPrior <- c(NA,sdBetaPrior,NA,NA, NA)
			predR <- partGL_RHLightResponse(theta
				,dssDay$Rg_f, dssDay$VPD_f, dssDay$Temp, 10.0, FALSE)
			RSSR <- .partGLRHLightResponseCost( theta, theta, seq_along(theta), flux, sdFlux, parameterPrior, sdParameterPrior
					,dssDay$Rg_f, dssDay$VPD_f, dssDay$Temp, useCVersion=FALSE)
			tmp <- RHLightResponseCostC( theta, flux, sdFlux, parameterPrior, sdParameterPrior
					,dssDay$Rg_f, dssDay$VPD_f, dssDay$Temp, 10.0, FALSE)
			#(predR$NEP - tmp)					
			expect_true(tmp - RSSR < 1e-8)	
		})

.benchmark_RHLightResponseCostC <- function(){
	#require(rbenchmark)
	tmp <- benchmark( 
	 .partGLRHLightResponseCost( theta[1:4], theta, 1:4, flux, sdFlux, parameterPrior, sdParameterPrior
			 ,dssDay$Rg_f, dssDay$VPD_f, dssDay$Temp, useCVersion=FALSE)
		,
		RHLightResponseCostC( theta, flux, sdFlux, parameterPrior, sdParameterPrior
				,dssDay$Rg_f, dssDay$VPD_f, dssDay$Temp, 10.0, FALSE)
		,replications = 10000
					)
	tmp			#speedup of only 2 :(

	tmp <- benchmark( 
			.partGLRHLightResponseCost( theta[1:4], theta, 1:4, flux, sdFlux, parameterPrior, sdParameterPrior
					,dssDay$Rg_f, dssDay$VPD_f, dssDay$Temp, useCVersion=FALSE)
			,
			.partGLRHLightResponseCost( theta[1:4], theta, 1:4, flux, sdFlux, parameterPrior, sdParameterPrior
					,dssDay$Rg_f, dssDay$VPD_f, dssDay$Temp)
			,replications = 10000
	)
	tmp			#speedup of only about 1.8 :(
}



test_that("partGLFitLRC",{
			dss <- subset(dsNEE, as.POSIXlt(dsNEE$sDateTime)$mday %in% 1:8 )
			dssDay <- subset(dss, isDay==TRUE)
			dssNight <- subset(dss, isNight==TRUE)
			dsDay <- data.frame( NEE=dssDay$NEE_f, sdNEE=dssDay$NEE_fsd, Rg=dssDay$Rg_f, Temp=dssDay$Temp, VPD=dssDay$VPD_f)
			res <- resNewPrior <- partGLFitLRC(dsDay, E0=185, sdE0=.05*185,RRefNight=mean(dssNight$NEE_f, na.rm=TRUE), lastGoodParameters=NA_real_
					,controlGLPart=partGLControl(nBootUncertainty=10L)
			)
			#testing Lasslop compliency: different priors, covariance from fit
			res <- resNewPrior <- partGLFitLRC(dsDay, E0=185, sdE0=.05*185,RRefNight=mean(dssNight$NEE_f, na.rm=TRUE), lastGoodParameters=NA_real_
				,controlGLPart=partGLControl(nBootUncertainty=0L, isLasslopPriorsApplied=TRUE)
			)
			#dput(res$opt.parms.V)
			.tmp.plot <- function(){
				dsDay <- dsDay[ order(dsDay$Rg_f), ]
				plot( -NEE ~ Rg, dsDay)		# NEE negative?
				p <- c(res$opt.parms.V, E0=185)
				pred <- partGL_RHLightResponse(p, Rg=dsDay$Rg_f, VPD=dsDay$VPD, Temp=dsDay$Temp)
				lines(pred$NEP  ~ dsDay$Rg_f)
			}
			# testing increasing number of bootstrap samples
			.tmp.f <- function(){
				(res60 <- partGLFitLRC(dsDay, dssNight$NEE, E0=185, sdE0=.05*185, RRefNight=mean(dssNight$NEE, na.rm=TRUE)
						,controlGLPart=partGLControl(nBootUncertainty=100L)
				))
			}		
		})


test_that("partGLFitLRCWindows outputs are in accepted range",{
			ds <- with(dsNEE, data.frame(NEE=NEE_f, Temp=Temp, VPD=VPD_f, Rg=ifelse( Rg_f >= 0, Rg_f, 0 )
			, sdNEE=NEE_fsd, isDay=isDay, isNight=isNight))
			#yday <- as.POSIXlt(dsNEE$sDateTime)$yday	
			resFits <- partGLFitLRCWindows(ds, nRecInDay=48L, controlGLPart=partGLControl(nBootUncertainty=10L))
			expect_equal( nrow(resFits$summary), length(resFits$resOptList) )
			.tmp.f <- function(){
				# in order to replicate, use nBoot=0L 
				resParms0 <- partGLFitLRCWindows(ds, nRecInDay=48L, controlGLPart=partGLControl(nBootUncertainty=0L))
				iTooMany <- which(resParms0$summary$iFirstRec >= nrow(ds)-2*48)
				if( length(iTooMany)){
					resParms0$summary <- resParms0$summary[-iTooMany,]
					resParms0$resOptList <- resParms0$resOptList[-iTooMany]
				}
				# regression result for resLRCEx1
				dput(resParms0)
			}
			# check the conditions of Lasslop10 Table A1
			resSummary <- resFits$summary
			expect_true( all(resSummary$E_0 >= 50 & resSummary$E_0 <= 400) )
			expect_true( all(resSummary$R_ref > 0) )
			expect_true( all(resSummary$a >= 0 ) )
			expect_true( all(resSummary$a[-1] < 0.22) )	# first value may be greater, due to previous estimate
			expect_true( all(resSummary$b >= 0 & resSummary$b < 250) )
			expect_true( all(ifelse(resSummary$b > 100, resSummary$b_SD < resSummary$b, TRUE) ))
			expect_true( all(resSummary$k >= 0) )
			expect_true( !all(is.na(resSummary$R_ref_SD)))
			expect_true( all(resSummary$iMeanRec < nrow(ds)) )
			expect_true( all(resSummary$iCentralRec < nrow(ds)) )
			.tmp.inspectYear <- function(){
				# dsYear generated from inside sPartitionGL
				dsYear <- local({ load("tmp/dsTestPartitioningLasslop10.RData"); get(ls()[1]) })
				dsYear2 <- with(dsYear, data.frame(NEE=NEE_f, sdNEE=NEE_fsd, Temp=Tair_f, VPD=VPD_f, Rg=ifelse( Rg >= 0, Rg, 0 )
								,isDay=!is.na(FP_VARday), isNight=!is.na(FP_VARnight) 				
						))
				resY <- resY1 <- partGLFitLRCWindows(dsYear2, nRecInDay=48L, controlGLPart=partGLControl(nBootUncertainty=30L)	)
				#resY <- resYL <- partGLFitLRCWindows(dsYear2, nRecInDay=48L, controlGLPart=partGLControl(isLasslopPriorsApplied=TRUE, nBootUncertainty=0L)	)
				resSummary <- resY$summary
				#resParms <- resY
				head(resSummary)				
				plot( R_ref ~ dayStart, resSummary)
				#points( R_ref ~ Start, resSummary, col="red")
				#points( R_ref ~ Start, resSummary, col="blue")
				with(resSummary, segments(dayStart,R_ref-R_ref_SD,dayStart, R_ref+R_ref_SD))
				points( R_ref_night ~ dayStart, resSummary, pch="+", col="blue")
				plot( b ~ dayStart, resSummary)
				plot( E_0 ~ dayStart, resSummary )
				#
				iStarts <- intersect(resYL$summary$Start, resY1$summary$Start)
				sumL <- subset(resYL$summary, dayStart %in% iStarts)
				sum1 <- subset(resY1$summary, dayStart %in% iStarts)
				plot(sumL$R_ref ~ sum1$R_ref); abline(0,1)			
				summary(lm( sumL$R_ref  ~ sum1$R_ref-1 ))
				plot(sumL$R_ref_SD ~ sum1$R_ref_SD); abline(0,1)			
				summary(lm( sumL$R_ref_SD  ~ sum1$R_ref_SD-1 ))	# Lasslop sd is smaller
				#
				plot( R_ref ~ R_ref12, resSummary)
			}
})

test_that(".partGPAssociateSpecialRows correct next lines",{
			expect_error(
					res <- .partGPAssociateSpecialRows(integer(0),9)
			)
			res <- .partGPAssociateSpecialRows(c(3,6,7,9),12)
			expect_true( all(res$wBefore+res$wAfter == 1)) 
			# special rows
			expect_equal( c(iRec=3,iSpecialBefore=1L,iSpecialAfter=1L,iBefore=3, iAfter=3, wBefore=0.5, wAfter=0.5), unlist(res[3,])) 
			expect_equal( c(iRec=6,iSpecialBefore=2L,iSpecialAfter=2L,iBefore=6, iAfter=6, wBefore=0.5, wAfter=0.5), unlist(res[6,]))
			# first rows and last rows
			expect_equal( c(iRec=1,iSpecialBefore=1L,iSpecialAfter=1L,iBefore=3, iAfter=3, wBefore=0.5, wAfter=0.5), unlist(res[1,])) 
			expect_equal( c(iRec=12,iSpecialBefore=4L,iSpecialAfter=4L,iBefore=9, iAfter=9, wBefore=0.5, wAfter=0.5), unlist(res[12,])) 
			# weights after and before special row 6
			expect_equal( rep(3,2), unlist(res[4:5,"iBefore"])) 
			expect_equal( rep(6,2), unlist(res[4:5,"iAfter"])) 
			expect_equal( rep(1,2), unlist(res[4:5,"iSpecialBefore"])) 
			expect_equal( rep(2,2), unlist(res[4:5,"iSpecialAfter"])) 
			expect_equal( (2:1)/3, unlist(res[4:5,"wBefore"])) 
			expect_equal( (1:2)/3, unlist(res[4:5,"wAfter"])) 
			# test last row is special
			res <- .partGPAssociateSpecialRows(c(3,6,7,9),9)
		})
			
			
test_that("partGLInterpolateFluxes runs",{
			tmp <- partGLInterpolateFluxes( dsNEE$Rg_f, dsNEE$VPD_f, dsNEE$Temp, resLRCEx1)
			expect_equal( nrow(dsNEE), nrow(tmp) )
			.tmp.plot <- function(){
				tmp$time <- dsNEE$sDateTime
				plot( Reco_DT ~ time, tmp)
				plot( GPP_DT ~ time, tmp)
			}
			expect_true( all(c("GPP","Reco") %in% names(tmp) ))
			tmp <- partGLInterpolateFluxes( dsNEE$Rg_f, dsNEE$VPD_f, dsNEE$Temp, resLRCEx1
							,controlGLPart=partGLControl(isSdPredComputed=TRUE))
			expect_equal( nrow(dsNEE), nrow(tmp) )
			expect_true( all(c("GPP","Reco") %in% names(tmp) ))
			expect_true( all(c("sdGPP","sdReco") %in% names(tmp) ))
		})

#resLRCEx1
test_that("partitionNEEGL",{
			dsNEE1 <- dsNEE
			#DoY.V.n <- as.POSIXlt(dsNEE1$sDateTime)$yday + 1L
			#Hour.V.n <- as.POSIXlt(dsNEE1$sDateTime)$hour + as.POSIXlt(dsNEE1$sDateTime)$min/60
			#dsNEE1$PotRad_NEW <- fCalcPotRadiation(DoY.V.n, Hour.V.n, Lat_deg.n=45.0, Long_deg.n=1, TimeZone_h.n=0 )
			tmp <- partitionNEEGL( dsNEE1,RadVar.s='Rg_f'  )
			expect_equal( nrow(dsNEE1), nrow(tmp) )
			#tmp[ is.finite(tmp$FP_beta), ]	# note FP_dRecPar is not zero, because iCentralRec != iMeanRec
			#
			dsNEE2 <- dsNEE1
			names(dsNEE2)[ match(c("NEE_f", "NEE_fqc", "NEE_fsd"),names(dsNEE2))] <- c("NEE_u50_f", "NEE_u50_fqc", "NEE_u50_fsd")
			tmp <- partitionNEEGL( dsNEE2, RadVar.s='Rg_f', Suffix.s="u50", controlGLPart=partGLControl(nBootUncertainty=0L, isAssociateParmsToMeanOfValids=FALSE) )
			expect_equal( nrow(dsNEE1), nrow(tmp) )
			expect_true( all(is.finite(tmp$GPP_DT_u50)))
			expect_true( all(tmp$GPP_DT_u50 >= 0))
			expect_true( all(tmp$GPP_DT_u50 < 250))
			expect_true( all(tmp$Reco_DT_u50 < 6))
			expect_true( all(tmp$Reco_DT_u50 > 0))
			expect_true( all(tmp$Reco_DT_u50_SD > 0))
			expect_true( all(tmp$GPP_DT_u50_SD >= 0))
			expect_true( all(abs(diff(tmp$Reco_DT_u50)) < 0.6))	#smooth
			# reporting good values at central records
			expect_true( sum( is.finite(tmp$FP_alpha) ) == nrow(resLRCEx1$summary) ) 
			expect_true( all((tmp$FP_alpha[resLRCEx1$iCentralRec] - resLRCEx1$a)[resLRCEx1$parms_out_range==0L] < 1e-2) )
			#expect_true( all((is.na(tmp$FP_alpha[resLRCEx1$iFirstRec] - resLRCEx1$a)[resLRCEx1$parms_out_range!=0L])) )
			expect_true( length(is.finite(tmp$FP_R_refNight)) > 0 )
			.tmp.plot <- function(){
				tmp$time <- dsNEE1$sDateTime
				plot( Reco_DT_u50 ~ time, tmp)
				#plot( diff(Reco_DT_u50) ~ time[-1], tmp)
				plot( GPP_DT_u50 ~ time, tmp)
				plot( FP_R_refNight ~ time, tmp)
				plot( FP_R_ref ~ FP_R_refNight, tmp)
			}
		})


test_that("partGLPartitionFluxes sparse data",{
			dsNEE1 <- dsNEE
			#set all data except one day to NA to associate the same data with several windows
			dsNEE1$NEE_f[ (dsNEE$sDateTime >= "1998-06-03 00:00:00 GMT") & (dsNEE$sDateTime < "1998-06-05 00:00:00 GMT" | dsNEE$sDateTime >= "1998-06-06 00:00:00 GMT") ] <- NA
			#plot( NEE_f ~ sDateTime, dsNEE1 )
			#
			ds <- dsNEE1
			ds$NEE <- ds$NEE_f
			ds$sdNEE <- ds$NEE_fsd
			ds$Temp <- ds$Tair_f
			ds$VPD <- ds$VPD_f
			ds$Rg <- ds$Rg_f
			#
			resLRC <- partGLFitLRCWindows(ds )
			expect_true( resLRC$summary$iMeanRec[2] == resLRC$summary$iMeanRec[3])
			#
			tmp <- partitionNEEGL( dsNEE1, RadVar.s="Rg_f" )
			expect_equal( nrow(dsNEE1), nrow(tmp) )
			#
			expect_true( all(is.finite(tmp$GPP_DT)))
			expect_true( all(tmp$GPP_DT >= 0))
			expect_true( all(tmp$GPP_DT < 250))
			expect_true( all(tmp$Reco_DT < 6))
			expect_true( all(tmp$Reco_DT > 0))
			expect_true( all(tmp$Reco_DT_SD > 0))
			expect_true( all(tmp$GPP_DT_SD >= 0))
			#TODO expect_true( all(abs(diff(tmp$Reco_DT)) < 0.6))	#smooth
			# reporting good values at first row
			expect_true( sum( is.finite(tmp$FP_alpha) ) == nrow(resLRC$summary) ) 
			expect_true( all((is.na(tmp$FP_alpha[resLRC$iCentralRec] - resLRC$a)[resLRC$parms_out_range!=0L])) )
			.tmp.plot <- function(){
				tmp$time <- dsNEE1$sDateTime
				plot( Reco_DT ~ time, tmp)
				#plot( diff(Reco_DT_u50) ~ time[-1], tmp)
				plot( GPP_DT ~ time, tmp)
			}
})


test_that("partGLPartitionFluxes missing night time data",{
			dsNEE1 <- dsNEE
			#set all data except one day to NA to associate the same data with several windows
			dsNEE1$hourOfDay <- as.POSIXlt(dsNEE1$sDateTime)$hour
			dsNEE1$NEE_f[ (dsNEE1$sDateTime >= "1998-06-01 00:00:00 GMT") & (dsNEE1$sDateTime < "1998-06-05 00:00:00 GMT") & 
							((dsNEE1$hourOfDay >= 18) | (dsNEE1$hourOfDay <= 6))] <- NA
			ds <- dsNEE1
			ds$NEE <- ds$NEE_f
			ds$sdNEE <- ds$NEE_fsd
			ds$Temp <- ds$Tair_f
			ds$VPD <- ds$VPD_f
			ds$Rg <- ds$Rg_f
			#
			resLRC <- partGLFitLRCWindows(ds, WinSizeNight.i=4L, winExtendSizes=c() )
			expect_true( all( is.finite(resLRC$summary$R_ref_night)) )
		})

	
test_that("partGLPartitionFluxes filter Meteo flag",{
		dsNEE1 <- dsNEE
		# test setting VPD_fqc to other than zero, for omitting those rows
		dsNEE1$VPD_fqc[ (dsNEE1$sDateTime > "1998-06-03 00:00:00 GMT") & (dsNEE1$sDateTime < "1998-06-05 00:00:00 GMT" | dsNEE1$sDateTime >= "1998-06-06 00:00:00 GMT") ] <- 1L
		#plot( VPD_fqc ~ sDateTime, dsNEE1 )
		ds <- dsNEE1
		ds$NEE <- ds$NEE_f
		ds$sdNEE <- ds$NEE_fsd
		ds$Temp <- ds$Tair_f
		ds$VPD <- ds$VPD_f
		ds$Rg <- ds$Rg_f
		#
		.tmp.f <- function(){
			tmp0 <- partitionNEEGL( dsNEE1, controlGLPart=partGLControl(isFilterMeteoQualityFlag=TRUE) )
			tmpPar0 <- tmp0[is.finite(tmp0$FP_beta),]
		}
		tmp <- partitionNEEGL( ds, controlGLPart=partGLControl(isFilterMeteoQualityFlag=TRUE) )
		expect_equal( nrow(ds), nrow(tmp) )
		tmpPar <- tmp[is.finite(tmp$FP_beta),]
		expect_true( nrow(tmpPar) == 3L )	# only three estimates instead of four
})
		

.profilePartGL <- function(){
	require(profr)
	p1 <- profr({
				for( i in 1:1 ){
					tmp <- partitionNEEGL( dsNEE1 )
				}
			}, 0.01 )
	plot(p1)
	
	
	
}

Try the REddyProc package in your browser

Any scripts or data that you put into this service are public.

REddyProc documentation built on May 2, 2019, 5:19 p.m.