Package {MoonShineR}


Title: Predict Moonlight, Sunlight, and/or Twilight Ground Illuminance
Version: 1.2.0
Description: Predicts ground-level illuminance from moonlight, sunlight, and twilight for specified locations and time periods. The package is intended for field studies in ecology and behavior where natural light levels are used as predictor variables. See Poon et al. (2024) <doi:10.1111/2041-210X.14299>. Calculations use astronomical quantities from 'suncalc' and published illuminance models, including Austin et al. (1976) <doi:10.2307/2402251> and Seidelmann (1992) <ISBN:0935702687>.
License: GPL-3
URL: https://lokpoon.github.io/MoonShine_manual/overview.html, https://github.com/Crampton-Lab/MoonShine
Encoding: UTF-8
RoxygenNote: 7.3.1
Depends: R (≥ 3.5.0)
Imports: suncalc, magrittr, dplyr, lubridate, REdaS, ggplot2, progress
NeedsCompilation: no
Packaged: 2026-10-29 15:44:14 UTC; lokpoon
Author: Lok Poon ORCID iD [aut, cre], Ian T. Jenks [aut], William G. R. Crampton ORCID iD [aut]
Maintainer: Lok Poon <poonchiulok@gmail.com>
Repository: CRAN
Date/Publication: 2026-10-29 19:50:02 UTC

MoonShineR Package

Description

Predict and plot light levels (ground illuminance) from moonlight, sunlight, and twilight.

Author(s)

Maintainer: Lok Poon poonchiulok@gmail.com (ORCID)

Authors:

See Also

Useful links:


Create a plot from the illuminance prediction data frame

Description

Usage

plot_lux(
  df = NULL,
  illuminance_type_plot = "total_illuminance_all",
  plot_y_max = 0.3,
  plot_daytime_gray_mask = TRUE,
  plot_eclipse_red_mask = TRUE,
  plot_twilight = "astro",
  vertical_time_label = TRUE,
  time_label_interval_hr = 24,
  time_label_shift_hr = 0
)

Arguments

df

data.frame. Data frame returned by predict_lux().

illuminance_type_plot

character. Choose one type of illuminance to plot. See options below. Default is "total_illuminance_all".

plot_y_max

numeric or "AUTO". Upper limit of the y-axis. Use "AUTO" to let ggplot choose the scale automatically. Default is 0.3.

plot_daytime_gray_mask

logical. If TRUE, , shows daytime portions of the plotted line in gray; FALSE disables this masking. Default is TRUE.

plot_eclipse_red_mask

logical. If TRUE, adds red shading during lunar eclipses to warn that predicted illuminance may be overestimated because eclipse-related dimming is not modeled; FALSE disables the shading. Default is TRUE.

plot_twilight

character. Select the twilight interval to shade gray: "astro" for astronomical twilight (longest), "nautic" for nautical twilight (intermediate), "civil" for civil twilight (shortest), or "none" to disable twilight shading. Default is "astro".

vertical_time_label

logical. If TRUE, rotate date–time labels vertically.

time_label_interval_hr

numeric. Interval between date–time labels, in hours.

time_label_shift_hr

numeric. Shift the x-axis start time by the specified number of hours to improve the placement of date–time labels. Negative values move the start time earlier than the first data point, leaving space at the left edge of the plot.

Value

A ggplot object showing predicted ground illuminance through time. The type of illuminance plotted, corresponding to a specific combination of moonlight, sunlight, and twilight, depends on the illuminance_type_plot argument in the plot_lux() function and corresponds to one of the illuminance columns in the data frame produced by predict_lux().

illuminance_type_plot options:

Notes:

Examples

# Plot a data frame generated by predict_lux(), named moonlight_output.
# First create a set predictions with predict_lux().
moonlight_output <- predict_lux(latitude = -4.21528, longitude = -69.94056, site_elev = 0,
                    time_zone = "EST", date_start = "2023-03-03", time_start = "18:00:00",
                    duration_day = 5.5, time_interval_minutes = 20, darksky_value = 0.0008,
                    output_directory = NULL, export_table = FALSE)

# Plot the combined illuminance of moonlight, twilight, and sunlight.
plot_lux(df = moonlight_output, illuminance_type_plot = "total_illuminance_all",
         plot_y_max = 0.3,  plot_daytime_gray_mask = TRUE, plot_eclipse_red_mask = TRUE,
         plot_twilight = "astro", vertical_time_label = TRUE, time_label_interval_hr = 24,
         time_label_shift_hr = -10)

Predict moonlight, sunlight, and twilight ground illuminance

Description

Usage

predict_lux(
  latitude = NULL,
  longitude = NULL,
  site_elev = 0,
  time_zone = NULL,
  date_start = NULL,
  time_start = "00:00:00",
  duration_day = NULL,
  time_interval_minutes = 5,
  darksky_value = 8e-04,
  output_directory = NULL,
  export_table = FALSE,
  show_progress = TRUE
)

Arguments

latitude

numeric. Latitude in decimal degrees (e.g., -4.21528).

longitude

numeric. Longitude in decimal degrees (e.g., -69.94056).

site_elev

numeric. Site elevation in meters above sea level (default 0). The elevation correction applies to moonlight predictions but not to sunlight or twilight predictions. Elevation for a given location can be obtained from https://www.dcode.fr/earth-elevation.

time_zone

character. Time zone for the specified location (e.g., "EST" for a fixed UTC-5 offset). Set time_zone consistently with the date and time being simulated. To list recognized time zones in R, enter OlsonNames(). A fixed-offset zone avoids daylight saving time changes, whereas a location-based zone such as "America/New_York" applies them; choose according to the intended interpretation of local time.

date_start

character. Starting date of the simulation ("YYYY-MM-DD").

time_start

character. Starting time of the simulation ("hh:mm:ss"). Default is "00:00:00".

duration_day

numeric. Duration of the simulation in days.

time_interval_minutes

numeric Time interval between successive illuminance predictions, in minutes. For example, 5 calculates illuminance every 5 minutes. Smaller intervals require more computation time. Default is 5.

darksky_value

numeric. A baseline illuminance (in lux) added to the model to represent other approximately constant nocturnal light sources (e.g., starlight and airglow). Default is 0.0008. Set it to zero to omit this background component.

output_directory

character. Directory for exported output files. If export_table = FALSE, no CSV table is exported.

export_table

logical. If TRUE, export the output data frame as a CSV file to output_directory; if FALSE, do not export the table. Default is FALSE.

show_progress

logical. If TRUE, display a progress bar; FALSE disables it. Default is TRUE.

Value

A data frame containing predicted ground illuminance values for each time step, based on different combinations of moonlight, sunlight, and twilight. Other columns include various astronomical values.

Columns found in the output data.frame/.csv table:

Attribution

References

Examples

# Predict the nighttime moonlight illuminance in Leticia, Colombia,
# for 5.5 days starting on 2023-03-03 at 6 pm (UTC -5).

moonlight_output <- predict_lux(latitude = -4.21528, longitude = -69.94056, site_elev = 0,
                    time_zone = "EST", date_start = "2023-03-03", time_start = "18:00:00",
                    duration_day = 5.5, time_interval_minutes = 20, darksky_value = 0.0008,
                    output_directory = NULL, export_table = FALSE, show_progress = TRUE)

moonlight_output # Display the completed data frame.