get_sun_stats() retrieves sun statistics using different models and
data sources.
At the moment, none of the get_sun_stats() methods uses real-world data.
All of them are based on models.
Each API have its peculiarities. We recommend checking the API documentation for a better understanding of the mechanisms behind them (see the Details section).
Usage
get_sun_stats(
latitude,
longitude,
date = Sys.Date(),
tz = "UTC",
method = "suncalc"
)Arguments
- latitude
A number indicating the latitude of the desired location in decimal degrees.
- longitude
A number indicating the longitude of the desired location in decimal degrees.
- date
(optional) A
Datevalue indicating the moment in time (default:Sys.Date()).- tz
(optional) A string indicating the time zone of the results. See
timezonesto learn more (default:"UTC").- method
(optional) A string indicating which method or API to use. Valid values are:
"suncalc"and"sunrise-sunset.org". See the Details section to learn more (default:"suncalc").
Value
A list object with the following elements:
date: ADatevector with the same value of thedateparameter.latitude: A number with the same value of thelatitudeparameter.longitude: A number with the same value of thelongitudeparameter.tz: A string with the same value of thetzparameter.sunrise_start: Anhmsvalue indicating the moment when the top edge of the sun appears on the horizon.sunrise_end: Anhmsvalue indicating the moment when bottom edge of the sun touches the horizon.golden_hour_end: Anhmsvalue indicating the moment when the morning golden hour (soft light, best time for photography) ends.solar_noon: Anhmsvalue indicating the moment when sun is in the highest position.golden_hour_start: Anhmsvalue indicating the moment when the evening golden hour (soft light, best time for photography) starts.sunset_start: Anhmsvalue indicating the moment when the bottom edge of the sun touches the horizon.sunset_end: Anhmsvalue indicating the moment when the sun disappears below the horizon. This is also the moment when the evening civil twilight starts.dusk: Anhmsvalue indicating the moment when the dusk starts. This is also the moment when the evening nautical twilight starts.nautical_dusk: Anhmsvalue indicating the moment when nautical dusk starts. This is also the moment when the evening astronomical twilight starts.night_start: Anhmsvalue indicating the moment when the night starts (dark enough for astronomical observations).nadir: Anhmsvalue indicating the darkest moment of the night, i.e., when the sun is in the lowest position.night_end: Anhmsvalue indicating the moment when the night ends. This is also the moment when the morning astronomical twilight starts.nautical_dawn: Anhmsvalue indicating the moment when nautical dawn starts. This is also the moment when the morning nautical twilight starts.dawn: Anhmsvalue indicating the moment when the dawn starts. This is also the moment when the morning nautical twilight ends and the morning civil twilight starts.
Details
methods argument
At the moment, get_sun_stats() can access the results of two APIs,
described below.
"suncalc": Use the sun statistics provided by thesuncalcpackage."sunrise-sunset.org": Use the sun statistics provided by the Sunrise-Sunset API (requires an internet connection). Click here to learn more.
The "sunrise-sunset.org" method tends to give a close, but usually lower,
result when compared with the "suncalc" method.
Please note that when using method = "sunrise-sunset.org" you need to show
attribution with a link to https://sunrise-sunset.org. Also note that
summer time adjustments are not included in the returned data when using this
method.
See also
Other API functions:
get_from_zenodo()
Examples
latitude <- -23.5489
longitude <- -46.6388
date <- Sys.Date()
tz <- "America/Sao_Paulo"
get_sun_stats(
latitude = latitude,
longitude = longitude,
date = date,
tz = tz,
method = "suncalc"
)
#> $date
#> [1] "2025-09-19"
#>
#> $latitude
#> [1] -23.5489
#>
#> $longitude
#> [1] -46.6388
#>
#> $tz
#> [1] "America/Sao_Paulo"
#>
#> $sunrise_start
#> 06:00:28
#>
#> $sunrise_end
#> 06:02:47
#>
#> $golden_hour_end
#> 06:30:19
#>
#> $solar_noon
#> 12:01:40
#>
#> $golden_hour_start
#> 17:33:02
#>
#> $sunset_start
#> 18:00:33
#>
#> $sunset_end
#> 18:02:53
#>
#> $dusk
#> 18:25:25
#>
#> $nautical_dusk
#> 18:51:38
#>
#> $night_start
#> 19:17:55
#>
#> $nadir
#> 00:01:40
#>
#> $night_end
#> 04:45:25
#>
#> $nautical_dawn
#> 05:11:43
#>
#> $dawn
#> 05:37:55
#>
library(curl)
if (has_internet()) {
get_sun_stats(
latitude = latitude,
longitude = longitude,
date = date,
tz = tz,
method = "sunrise-sunset.org"
)
}
#> $date
#> [1] "2025-09-19"
#>
#> $latitude
#> [1] -23.5489
#>
#> $longitude
#> [1] -46.6388
#>
#> $tz
#> [1] "America/Sao_Paulo"
#>
#> $sunrise_start
#> 05:51:03
#>
#> $sunrise_end
#> NA
#>
#> $golden_hour_end
#> NA
#>
#> $solar_noon
#> 11:53:43
#>
#> $golden_hour_start
#> NA
#>
#> $sunset_start
#> NA
#>
#> $sunset_end
#> 17:56:24
#>
#> $dusk
#> 18:17:47
#>
#> $nautical_dusk
#> 18:44:00
#>
#> $night_start
#> 19:10:17
#>
#> $nadir
#> NA
#>
#> $night_end
#> 04:37:09
#>
#> $nautical_dawn
#> 05:03:27
#>
#> $dawn
#> 05:29:40
#>