R/swe.pistocchi.R

Defines functions swe.pistocchi

Documented in swe.pistocchi

swe.pistocchi <- function(data){
  
  if(!inherits(data,"data.frame"))
    stop("swe.pistocchi: data must be given as data.frame")
  
  if(!any((is.element(colnames(data), c("hs","date")))))
    stop("swe.pistocchi: data must contain at least two columns named 'hs' and 'date'")
  
  Hobs <- data$hs
  if(any(is.na(Hobs)))
    stop("swe.pistocchi: snow depth data must not be NA")
  if(!all(Hobs >= 0))
    stop("swe.pistocchi: snow depth data must not be negative")
  if(!is.numeric(Hobs))
    stop("swe.pistocchi: snow depth data must be numeric")
  
  if(!inherits(data$date,"character"))
    stop("swe.pistocchi: date column must be of class character")
  # 
  # z <- zoo(Hobs,as.Date(data$date))
  # if(!is.regular(z, strict = TRUE))
  #   stop("swe.jonas: date column must be strictly regular")
  # 
  
  
  # dos: integer day from 1.9. - 31.8.}
  dos <- ifelse( month(data$date)>8 & month(data$date) <=12,yday(data$date) - 243, yday(data$date) +122 )
  rho_0 <- 200                 # [kg/m3] bulk snow density at DOY = -61 (31 October)
  K <- 1                       # [kg/m3/day] rate of (bulk snow) density increase
  doy <- dos - 122
  rho <- rho_0 + K*(doy + 61)  # [kg/m3] bulk snow density
  swe <- rho*data$hs           # [kg/m2] snow water equivalent
  return(swe)
}

Try the swemod package in your browser

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

swemod documentation built on Nov. 11, 2019, 3 p.m.