SHARE
TWEET

Untitled

a guest May 25th, 2019 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. get_vpd_day_fluxnet2015 <- function(dir){
  2.  
  3.   ## loop over all HH files in the directory 'dir'
  4.   out <- purrr::map( as.list(list.files(dir, pattern = "HH")),
  5.               ~get_vpd_day_fluxnet2015_byfile(paste0(dir, .)))
  6.  
  7.   return(out)
  8. }
  9.  
  10. get_vpd_day_fluxnet2015_byfile <- function(filename_hh){
  11.  
  12.   df <- readr::read_csv(filename_hh) %>%
  13.     dplyr::mutate( date_start = lubridate::ymd_hm( TIMESTAMP_START ),
  14.                    date_end   = lubridate::ymd_hm( TIMESTAMP_END ) ) %>%
  15.     dplyr::mutate( date = date_start ) %>%
  16.    
  17.     ## retain only daytime data = when incoming shortwave radiation is positive
  18.     dplyr::filter(SW_IN_F>0) %>%
  19.    
  20.     ## take mean over daytime values
  21.     dplyr::mutate(date_day = lubridate::as_date(date_start)) %>%
  22.     dplyr::group_by(date_day) %>%
  23.     dplyr::summarise(VPD_F_DAY = mean(VPD_F, na.rm=TRUE),
  24.                      VPD_F_DAY_QC = sum(is.element(VPD_F_QC, c(0,1)))/n(),
  25.                      VPD_F_DAY_MDS = mean(VPD_F_MDS, na.rm=TRUE),
  26.                      VPD_F_DAY_MDS_QC = sum(is.element(VPD_F_MDS_QC, c(0,1)))/n(),
  27.                      VPD_DAY_ERA = mean(VPD_ERA, na.rm=TRUE) ) %>%
  28.     dplyr::rename(date = date_day)
  29.  
  30.   filename_dd <- filename_hh %>%
  31.     stringr::str_replace("HH", "DD") %>%
  32.     stringr::str_replace(".csv", "_VPD_DAY.csv")
  33.  
  34.   out <- write_csv(df, path=filename_dd)
  35.   return(out)
  36. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top