Skip to content

Commit

Permalink
added some diagnostics (vpd,z0,...)
Browse files Browse the repository at this point in the history
  • Loading branch information
noctiluc3nt committed Oct 10, 2024
1 parent 57599d7 commit 203b8ce
Show file tree
Hide file tree
Showing 16 changed files with 175 additions and 6 deletions.
4 changes: 4 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export(calc_cov)
export(calc_csi)
export(calc_dshear)
export(calc_ef)
export(calc_evapotranspiration)
export(calc_flux_footprint)
export(calc_gustfactor)
export(calc_iw)
Expand All @@ -27,10 +28,12 @@ export(calc_quadrant_analysis)
export(calc_ri)
export(calc_satvaporpressure)
export(calc_spectrum)
export(calc_spectrum1D)
export(calc_ti)
export(calc_tke)
export(calc_ustar)
export(calc_var)
export(calc_vpd)
export(calc_vtke)
export(calc_windDirection)
export(calc_windSpeed2D)
Expand Down Expand Up @@ -65,6 +68,7 @@ export(scale_phiu)
export(scale_phiw)
export(shift2maxccf)
export(sos2Ts)
export(ustar2z0)
importFrom(MASS,kde2d)
importFrom(RcppRoll,roll_mean)
importFrom(RcppRoll,roll_sd)
Expand Down
4 changes: 2 additions & 2 deletions R/auxilliary.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ binning=function(var1,var2,bins) {

#' Shifting two timeseries to match maximum cross-correlation
#'
#'@description Shifts two timeseries to match their maximum cross-correlation
#'@description Shifts two timeseries to match their maximum cross-correlation (can be used e.g. for lag-time correction)
#'@param var1 vector, first timeseries
#'@param var2 vector, second timeseries
#'@param plot logical, should the cross-correlation be plotted? default \code{plot = TRUE}
Expand All @@ -61,7 +61,7 @@ shift2maxccf=function(var1,var2,plot=TRUE) {
n=max(n1,n2)
#calc cross-correlation
notna=(!is.na(var1) & !is.na(var2))
cc=ccf(var1[notna],var2[notna])
cc=ccf(var1[notna],var2[notna])
maxcc=max(cc$acf) #max positive cross-correlation
lag=cc$lag[which(cc$acf==max(cc$acf))] #respective time lag
if (plot == TRUE) {
Expand Down
8 changes: 8 additions & 0 deletions R/constants.R
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,12 @@ M_CO2 = function() {
#' @keywords internal
M_CH4 = function() {
return(0.01604)
}

#' Charnock constant (alpha)
#'
#' Charnock constant (alpha) used to convert friction velocity to surface roughness length
#' @keywords internal
alpha = function() {
return(0.016)
}
21 changes: 21 additions & 0 deletions R/diagnostics-meteorology.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,27 @@ calc_satvaporpressure = function(temp) {
return(a*exp(b*temp/(temp+c))*1000)
}

#' Vapor pressure deficit (VPD)
#'
#'@description Calculates vapor pressure deficit (VPD) from temperature and relative humidity using Arrhenius formula
#'@param temp temperature [K]
#'@param rh relative humidity [%]
#'@return VPD, vapor pressure deficit [Pa]
#'@export
#'
calc_vpd = function(temp,rh) {
#calculate saturation pressure here using Arrhenius formula
a=-1.0440397*10^4
b=-11.29465
c=-2.7022355*10^-2
d=1.289036*10^-5
e=-2.4780681*10^-9
f=6.5459673
temp=temp*5/9 #K to deg R (Rankine scale)
es=exp(a/temp+b+c*temp+d*temp^2+e*temp^3+f*log(temp))
return(es*(1-rh/100))
}

#' Potential temperature
#'
#'@description Calculates potential temperature for given temperature and pressure
Expand Down
29 changes: 29 additions & 0 deletions R/diagnostics-turbulence.R
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,32 @@ calc_br = function(sh,lh) {
calc_ef = function(sh,lh) {
return(lh/(sh+lh))
}

#' Evapotranspiration
#'
#'@description Calculates evapotranspiration from latent heat flux
#'@param lh latent heat flux [W/m^2]
#'@param temp temperature [K] (optional), if provided, the latent heat of vaporization is calculated temperature-dependent
#'
#'@return evapotranspiration [kg/(s*m^2)]
#'@export
#'
calc_evapotranspiration = function(lh,temp=NULL) {
lv=Lv(temp)
return(lh/lv)
}


### surface roughness and related concepts ###

#' Calculates surface roughness length z0 from friction velocity using the simple estimate from Charnock, 1955
#'
#'@description Calculates surface roughness z0 from friction velocity using the simple estimate from Charnock, 1955: z0 = alpha*ustar^2/g with alpha=0.016 and g=9.81 m/s^2
#'@param ustar friction velocity [m/s]
#'
#'@return surface roughness length [m]
#'@export
#'
ustar2z0 = function(ustar) {
return(alpha()*ustar^2/g())
}
1 change: 1 addition & 0 deletions R/ec-processing.R
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ cov2cf = function(cov_co2w,rho=NULL) {
#'set.seed(5)
#'x=rnorm(100)
#'y=rnorm(100)
#'y[1:10]=NA
#'cov_xy=calc_cov(x,y)
#'
calc_cov = function(x,y) {
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Reddy: An open-source package for analyzing eddy-covariance measurements
# Reddy: A toolbox for analyzing eddy-covariance measurements
<!-- badges: start -->
[![CRAN status](https://www.r-pkg.org/badges/version/Reddy)](https://cran.r-project.org/package=Reddy)
[![Last Commit](https://img.shields.io/github/last-commit/noctiluc3nt/Reddy)](https://github.com/noctiluc3nt/Reddy)
Expand Down Expand Up @@ -31,7 +31,7 @@ The Reddy package provides functions for the post-processing, analysis and evalu
- `spectrum.R`: wrapper for the rbase spectrum function to derive averaged FFT spectra and compare them with theoretical slopes
- `surface-energy-balance.R`: visualization of surface energy balance, residual flux and closure ratio

<image src="./inst/figures/schema.png">
<image src="./inst/figures/schema2.png">


### Usage
Expand Down
17 changes: 17 additions & 0 deletions man/Reddy-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions man/alpha.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/calc_cov.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions man/calc_evapotranspiration.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions man/calc_spectrum1D.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions man/calc_vpd.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/deaccumulate1h.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/shift2maxccf.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions man/ustar2z0.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 comment on commit 203b8ce

@noctiluc3nt
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#6

Please sign in to comment.