Skip to content

Commit b80045c

Browse files
committed
transform files from R origin
1 parent 5558ba4 commit b80045c

19 files changed

+5164
-105
lines changed

inst/fromR/WUE_metrics.jl

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
###############################
2+
### WUE metrics calculation ###
3+
###############################
4+
5+
#' Water-Use Efficiency Metrics
6+
#'
7+
#' Calculation of various water use efficiency (WUE) metrics.
8+
#'
9+
#' - data Data_frame or matrix containing all required variables
10+
#' - GPP Gross primary productivity (umol CO2 m-2 s-1)
11+
#' - NEE Net ecosystem exchange (umol CO2 m-2 s-1)
12+
#' - LE Latent heat flux (W m-2)
13+
#' - VPD Vapor pressure deficit (kPa)
14+
#' - Tair Air temperature (deg C)
15+
#' - constants Cmol - molar mass of carbon (kg mol-1) \cr
16+
#' umol2mol - conversion micromole (umol) to mole (mol) \cr
17+
#' kg2g - conversion kilogram (kg) to gram (g)
18+
#'
19+
#' # Details
20+
the following metrics are calculated:
21+
#'
22+
#' Water-use efficiency (WUE):
23+
#'
24+
#' \deqn{WUE = GPP / ET}
25+
#'
26+
#' Water-use efficiency based on NEE (WUE_NEE):
27+
#'
28+
#' \deqn{WUE_NEE = NEE / ET}
29+
#'
30+
#' Inherent water-use efficiency (IWUE; Beer et al. 2009):
31+
#'
32+
#' \deqn{IWUE = (GPP * VPD) / ET}
33+
#'
34+
#' Underlying water-use efficiency (uWUE; Zhou et al. 2014):
35+
#'
36+
#' \deqn{uWUE= (GPP * sqrt(VPD)) / ET}
37+
#'
38+
#' All metrics are calculated based on the median of all values. E_g.
39+
#' WUE = median(GPP/ET,na_rm=TRUE)
40+
#'
41+
#' # Value
42+
a named vector with the following elements:
43+
#' \item{WUE}{Water-use efficiency (gC (kg H20)-1)}
44+
#' \item{WUE_NEE}{Water-use efficiency based on NEE (gC (kg H20)-1)}
45+
#' \item{IWUE}{Inherent water-use efficiency (gC kPa (kg H20)-1)}
46+
#' \item{uWUE}{Underlying water-use efficiency (gC kPa^0.5 (kg H20)-1)}
47+
#'
48+
#' @note Units for VPD can also be hPa. Units change accordingly.
49+
#' WUE_NEE is calculated based on the absolute value of NEE (the sign convention does not matter here).
50+
#'
51+
#' @references Beer, C., et al., 2009: Temporal and among-site variability of inherent
52+
#' water use efficiency at the ecosystem level. Global Biogeochemical Cycles 23, GB2018.
53+
#'
54+
#' Zhou, S., et al., 2014: The effect of vapor pressure deficit on water
55+
#' use efficiency at the sub-daily time scale. Geophysical Research Letters 41.
56+
#'
57+
#' @seealso \code{\link{stomatal_slope}} for a measure of intrinsic WUE
58+
#'
59+
#' ```@example; output = false
60+
#' ```
61+
#' ## filter data for dry periods and daytime at DE-Tha in June 2014
62+
#' DE_Tha_Jun_2014_2 = filter_data(DE_Tha_Jun_2014,quality_control=FALSE,
63+
#' vars_qc=c("Tair","precip","VPD","H","LE"),
64+
#' filter_growseas=FALSE,filter_precip=TRUE,
65+
#' filter_vars=c("Tair","PPFD","ustar"),
66+
#' filter_vals_min=c(5,200,0.2),
67+
#' filter_vals_max=c(NA,NA,NA),NA_as_invalid=TRUE,
68+
#' quality_ext="_qc",good_quality=c(0,1),
69+
#' missing_qc_as_bad=TRUE,GPP="GPP",doy="doy",
70+
#' year="year",tGPP=0.5,ws=15,min_int=5,precip="precip",
71+
#' tprecip=0.1,precip_hours=24,records_per_hour=2)
72+
#'
73+
#' ## calculate WUE metrics in the filtered periods
74+
#' WUE_metrics(DE_Tha_Jun_2014_2)
75+
#'
76+
#' @importFrom stats median
77+
"""
78+
"""
79+
function WUE_metrics(data,GPP="GPP",NEE="NEE",LE="LE",VPD="VPD",Tair="Tair",
80+
constants=bigleaf_constants())
81+
82+
check_input(data,list(GPP,NEE,LE,VPD,Tair))
83+
84+
ET = LE_to_ET(LE,Tair) # kg H2O m-2 s-1
85+
GPP = (GPP * constants$umol2mol * constants$Cmol) * constants$kg2g # gC m-2 s-1
86+
NEE = (NEE * constants$umol2mol * constants$Cmol) * constants$kg2g # gC m-2 s-1
87+
88+
WUE = median(GPP/ET,na_rm=TRUE)
89+
WUE_NEE = median(abs(NEE)/ET,na_rm=TRUE)
90+
IWUE = median((GPP*VPD)/ET,na_rm=TRUE)
91+
uWUE = median((GPP*sqrt(VPD))/ET,na_rm=TRUE)
92+
93+
return(c(WUE=WUE,WUE_NEE=WUE_NEE,IWUE=IWUE,uWUE=uWUE))
94+
end

0 commit comments

Comments
 (0)