diff --git a/R/ingest.R b/R/ingest.R index 51f852b..8ad00ba 100644 --- a/R/ingest.R +++ b/R/ingest.R @@ -647,35 +647,11 @@ ingest <- function( } } else { - - # Calculate vapour pressure deficit from specific humidity - # this calculates this variable for cases where there is - # no bias correction - if ("vpd" %in% getvars){ - - if (source == "watch_wfdei" || source == "wfde5"){ - # use daily mean temperature - ddf <- ddf %>% - rowwise() %>% - dplyr::mutate( - vapr = calc_vp(qair = qair, patm = patm), - vpd = calc_vpd(eact = vapr, tc = temp) - ) %>% - ungroup() - - } else if (source == "cru"){ - # use daily minimum and maximum temperatures - ddf <- ddf %>% - rowwise() %>% - dplyr::mutate( - vpd = calc_vpd(eact = vapr, tmin = tmin, tmax = tmax) - ) %>% - ungroup() - } - + # For cases where there is no bias correction, + # (of sources cru, watch_wfdei, wfde5; but not ndep) + # vapour pressure deficit has already been computed within `ingest_globalfields()` } - } } else if (source == "gee"){ diff --git a/R/ingest_bysite.R b/R/ingest_bysite.R index 7641256..a03aa4d 100644 --- a/R/ingest_bysite.R +++ b/R/ingest_bysite.R @@ -448,46 +448,10 @@ ingest_bysite <- function( } } else { - - # Calculate vapour pressure deficit from specific humidity - # this calculates this variable for cases where there is - # no bias correction - if ("vpd" %in% getvars){ - - # xxxxxxx - if (!("vapr" %in% names(df_tmp))){ - # calculate vapour pressure from specific humidity - needed for bias correction with worldclim data - if (source == "watch_wfdei"){ - # specific humidity (qair, g g-1) is read, convert to vapour pressure (vapr, Pa) - df_tmp <- df_tmp %>% - rowwise() %>% - dplyr::mutate(vapr = calc_vp(qair = qair, patm = patm)) %>% - ungroup() - - } else if (source == "cru"){ - # vapour pressure is read from file, convert from hPa to Pa - df_tmp <- df_tmp %>% - dplyr::mutate(vapr = 1e2 * vap) %>% - dplyr::select(-vap) - - } - } - - if (source == "watch_wfdei"){ - # use daily mean temperature - df_tmp <- df_tmp %>% - rowwise() %>% - dplyr::mutate(vpd = calc_vpd(eact = vapr, tc = temp)) %>% - ungroup() - - } else if (source == "cru"){ - # use daily minimum and maximum temperatures - df_tmp <- df_tmp %>% - rowwise() %>% - dplyr::mutate(vpd = calc_vpd(eact = vapr, tmin = tmin, tmax = tmax)) %>% - ungroup() - } + # For cases where there is no bias correction, + # (of sources cru, watch_wfdei, wfde5; but not ndep) + # vapour pressure deficit has already been computed within `ingest_globalfields()` } } diff --git a/R/ingest_globalfields.R b/R/ingest_globalfields.R index 68b2c44..da9fde0 100644 --- a/R/ingest_globalfields.R +++ b/R/ingest_globalfields.R @@ -92,6 +92,13 @@ ingest_globalfields <- function( dplyr::rename(patm = myvar), by = c("sitename", "date") ) + + # calculate VPD based on humidity, air temperature, and atmospheric pressure + df_out <- df_out %>% + rowwise() %>% + mutate(vapr = calc_vp(qair = qair, patm = patm)) %>% + mutate(vpd = calc_vpd(eact = vapr, tc = temp)) %>% + ungroup() } # precipitation @@ -163,6 +170,13 @@ ingest_globalfields <- function( dplyr::rename(patm = myvar), by = c("sitename", "date") ) + + # calculate VPD based on humidity, air temperature, and atmospheric pressure + df_out <- df_out %>% + rowwise() %>% + mutate(vapr = calc_vp(qair = qair, patm = patm)) %>% + mutate(vpd = calc_vpd(eact = vapr, tc = temp)) %>% + ungroup() } # precipitation