sunTime: Convert clock times to sun times

View source: R/sunTime.R

sunTimeR Documentation

Convert clock times to sun times

Description

Converts a vector of clock times to "sun times", by mapping sunrise to \pi/2 and sunset to 3\pi/2. Sunrise and sunset times are determined based on the dates and locations provided. See Nouvellet et al (2012) for a discussion. Requires the suntools package.

Usage

sunTime(clockTime, Dates, Coords)

Arguments

clockTime

a vector of times of observations in radians, ie. scaled to [0, 2\pi].

Dates

a POSIXct object with the dates of the observations; the time zone must be set to the time zone used for 'clockTime'.

Coords

a SpatialPoints object with the locations of the observations, or with a single point giving a approximate location for the study area; the coordinates must be geographical coordinates, eg, WGS84, with long before lat.

Value

Returns a vector of "sun times" in radians, where \pi/2 corresponds to sunrise and 3\pi/2 to sunset.

Author(s)

Mike Meredith.

References

Nouvellet et al (2012) Noisy clocks and silent sunrises: measurement methods of daily activity pattern. Journal of Zoology 286:179-184.

Examples

# Check that sp and suntools packages are installed
if(requireNamespace("sp") && requireNamespace("suntools")) {
  # Get example data:
  data(simCalls)
  str(simCalls)

  # Convert dates to a POSIXct object with the right time zone (GMT):
  Dates <- as.POSIXct(simCalls$dates, tz="GMT")

  # Create a SpatialPoints object with the location
  coords <- matrix(c(-3, 56), nrow=1)
  Coords <- sp::SpatialPoints(coords, proj4string=sp::CRS("+proj=longlat +datum=WGS84"))

  st <- sunTime(simCalls$time, Dates, Coords)

  exPar<-par(mfrow=c(2,1))
	densityPlot(st, col='red', lwd=2, xaxt='n', main="Sun time")
		axis(1, at=c(0, 6, 12, 18, 24),
		labels=c("midnight", "sunrise", "noon", "sunset", "midnight"))
	densityPlot(simCalls$time, lwd=2, main="Clock time")
  par(exPar)
}

overlap documentation built on May 29, 2024, 8:31 a.m.