getDaylightHours: Calculate the sunrise and sunset hours for a time and place

Description Usage Arguments Value Examples

View source: R/getDaylightHours.R

Description

Returns the sunrise and sunset hours for specified dates within a bounding box based on sun ephemerides calculations. Sunrise is calculated using the midpoint of the east edge of the bounding box while sunset is calculated using the midpoint of the west edge.

The bounding box may be specified via any of the following methods:

If more than one of the above are specified, the order of preference for determining the bounding box is:

  1. longitude, latitude passed in – location +/- 0.1 degrees

  2. bbox passed in – use unchanged

  3. timezone passed in – use bbox of the timezone

  4. datetime is POSIXct – use bbox of the timezone attribute

Usage

1
2
3
4
5
6
7
8
getDaylightHours(
  datetime = NULL,
  longitude = NULL,
  latitude = NULL,
  bbox = NULL,
  timezone = NULL,
  isJulian = FALSE
)

Arguments

datetime

Datetime as a Ymd HMS or Julian formatted string, or a POSIXct.

longitude

Longitude of the location in decimal degrees E.

latitude

Latitude of the location in decimal degrees N.

bbox

Bounding box for the region.

timezone

Timezone used to interpret datetime.

isJulian

Logical flag determining whether datetime should be interpreted as a Julian date with day of year as a decimal number. Defaults to FALSE.

Value

List containing POSIXct sunrise and sunset times for the specified date.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
library(MazamaSatelliteUtils)
library(MazamaSpatialUtils)

# Get sunrise and sunset by lat/lon and datetime
getDaylightHours(
  datetime = "2019-09-06", 
  longitude = -123.245, 
  latitude = 42.861
)

# Get sunrise and sunset by bbox and datetime
getDaylightHours(
  datetime = "2019-09-06",
  bbox = c(-124.566, -116.463, 41.991, 46.292) # Oregon
) 

# Get sunrise and sunset by datetime and timezone
getDaylightHours(
  datetime = "2019-09-06",
  timezone = "America/Los_Angeles"
)

# Get sunrise and sunset for a vector of datetimes
getDaylightHours(
  datetime = c("2019-06-21", "2019-09-23", "2019-12-22"),
  longitude = -123.245, 
  latitude = 42.861
)

MazamaScience/MazamaSatelliteUtils documentation built on Dec. 17, 2021, 3:20 a.m.