Create and add columns for time to and time since sunrise/sunset to tag data. Can take a motus database table, but will always return a collected data frame. Requires data containing at least latitude, longitude, and time.
Usage
timeToSunriset(
df_src,
lat = "recvDeployLat",
lon = "recvDeployLon",
ts = "ts",
units = "hours",
data
)
Arguments
- df_src
Data frame, SQLite connection, or SQLite table. An SQLite connection would be the result of
tagme(XXX)
orDBI::dbConnect(RSQLite::SQLite(), "XXX.motus")
; an SQLite table would be the result ofdplyr::tbl(tags, "alltags")
; a data frame could be the result ofdplyr::tbl(tags, "alltags") %>% dplyr::collect()
.- lat
Character. Name of column with latitude values, defaults to
recvDeployLat
- lon
Character. Name of column with longitude values, defaults to
recvDeployLon
- ts
Character. Name of column with time as numeric or POSIXct, defaults to
ts
- units
Character. Units to display time difference, defaults to "hours", options include "secs", "mins", "hours", "days", "weeks".
- data
Defunct, use
src
,df_src
, ordf
instead.
Value
Original data (as a flat data frame), with the following additional columns:
sunrise
- Time of sunrise in UTC for that row's date and locationsunset
- Time of sunset in UTC for that row's date and locationts_to_set
- Time to next sunset, inunits
ts_since_set
- Time to previous sunset, inunits
ts_to_rise
- Time to next sunrise after, inunits
ts_since_rise
- Time to previous sunrise, inunits
Details
Uses sunRiseSet()
to perform sunrise/sunset calculates, see ?sunRiseSet
for details regarding how local dates are assessed from UTC timestamps.
Examples
# Download sample project 176 to .motus database (username/password are "motus.sample")
if (FALSE) sql_motus <- tagme(176, new = TRUE)
# Or use example data base in memory
sql_motus <- tagmeSample()
# Get sunrise and sunset information for alltags view with units in minutes
sunrise <- timeToSunriset(sql_motus, units = "mins")
#> 'df_src' is a complete motus data base, using 'alltags' view