Passer au contenu

Creates and adds a sunrise and sunset column to a data.frame containing latitude, longitude, and a date/time as POSIXct or numeric.

Utilisation

sunRiseSet(data, lat = "recvDeployLat", lon = "recvDeployLon", ts = "ts")

Arguments

data

a selected table from .motus detection data, eg. "alltags", or a data.frame of detection data including at a minimum variables for date/time, latitude, and longitude

lat

variable with latitude values, defaults to recvDeployLat

lon

variable with longitude values, defaults to recvDeployLon

ts

variable with time in UTC as numeric or POSIXct, defaults to ts

Valeur de retour

the original dataframe provided, with the following additional columns:

  • sunrise: sunrise time for the date and location provided by ts and lat/lon per row

  • sunset: sunset time for the date and location provided by ts and lat/lon per row

Exemples

# You can use either a selected tbl from .motus eg. "alltags", or a
# data.frame, instructions to convert a .motus file to all formats are below.

# download and access data from project 176 in sql format
# usename and password are both "motus.sample"
if (FALSE) sql.motus <- tagme(176, new = TRUE, update = TRUE)

# OR use example sql file included in `motus`
sql.motus <- tagme(176, update = FALSE, 
                   dir = system.file("extdata", package = "motus"))

# Extract alltags, collect (flatten to data frame), add sunrise/sunset cols:
sun <- sunRiseSet(sql.motus)
#> 'data' is a complete motus data base, using 'alltags' view

# For other views, extract them first:
library(dplyr)
tbl.alltagsGPS <- tbl(sql.motus, "alltagsGPS") 

# Add sunrise/sunset (after flattening to data frame)
sun <- sunRiseSet(tbl.alltagsGPS)

# Or, submit a flattened data frame:
df.alltagsGPS <- collect(tbl.alltagsGPS)

# Add sunrise/sunset
sun <- sunRiseSet(df.alltagsGPS)

# Get sunrise and sunset information from tbl.alltags using gps lat/lon
# Note this only works if there are non-NA values in gpsLat/gpsLon
if (FALSE) sun <- sunRiseSet(tbl.alltagsGPS, lat = "gpsLat", lon = "gpsLon")