R/log_lux.R

Defines functions log_lux

Documented in log_lux

#' Simulate illuminance value
#'
#' Calculates log(lux) values for a give location, date, time
#' and sky conditions.
#'
#' @param par Three parameters specifying the illuminance model.
#' @param data A data frame with the required drivers for the illuminance model.
#' @param ... optional other parameters to forward
#'
#' @return Sky illuminance as log(lux).
#' @export

log_lux <- function(
    par,
    data,
    ...
) {

  # split out model parameters
  lat <- par[1]
  lon <- par[2]
  sky <- exp(par[3])

  # run model
  illuminance <- skylight::skylight(
    longitude = lon,
    latitude = lat,
    date = data$date_time,
    sky_condition = sky
  )$total_illuminance

  # return log lux
  return(log(illuminance))

}

Try the skytrackr package in your browser

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

skytrackr documentation built on Nov. 5, 2025, 6:47 p.m.