sun | R Documentation |
The sun()
function calculates beam (direct), diffuse and ground reflected solar irradiation for a given day and set of topographic and atmospheric conditions. The function relies on the GRASS module r.sun
, the manual page for which contains a detailed explanation (see grassHelp("r.sun")
)
sun(
elevation,
coeff_bh,
coeff_dh,
slope,
aspect,
hh,
horizon_step = 90,
albedo = 0.2,
linke = 3,
day = 1,
step = 0.5,
declination = NULL,
solar_constant = 1367,
distance_step = 1,
npartitions = 1,
beam_rad = TRUE,
diff_rad = TRUE,
refl_rad = TRUE,
glob_rad = TRUE,
insol_time = TRUE,
lowMemory = FALSE
)
elevation |
A |
coeff_bh |
A |
coeff_dh |
A |
slope |
A |
aspect |
A |
hh |
A "stack" of |
horizon_step |
Numeric >0: Difference between angular steps in which horizon height is measured. One horizon height raster will be made per value from 0 to 360 - |
albedo |
A |
linke |
A |
day |
Positive integer between 1 to 365, inclusive: Day of year for which to calculate ir/radiation. Default is 1 (January 1st). |
step |
Positive integer between 0 and 24, inclusive. Time step in hours for all-day radiation sums. Decimal values are OK. |
declination |
Numeric or |
solar_constant |
Positive numeric: The solar constant (solar energy hitting the top of the atmosphere). Default is 1367. Units are W / m^2. |
distance_step |
Positive numeric between 0.5 and 1.5, inclusive: Sampling distance coefficient. Default is 1. |
npartitions |
Positive numeric. Number of chunks in which to read input files. Default is 1. |
beam_rad |
Logical: If |
diff_rad |
Logical: If |
refl_rad |
Logical: If |
glob_rad |
Logical:. If |
insol_time |
Logical: If |
lowMemory |
Logical: If |
A raster or raster stack stack with the same extent, resolution, and coordinate reference system as elevation
. Assuming all possible rasters are generated they represent:
beam_rad
: Beam radiation (Watt-hours/m2/day)
diff_rad
: Diffuse radiation (Watt-hours/m2/day)
refl_rad
: Reflected radiation (Watt-hours/m2/day)
glob_rad
: Global radiation (Watt-hours/m2/day)
insol_time
: Insolation duration (hours)
terrain()
, horizonHeight()
, GRASS manual page for module r.sun
(see grassHelp("r.sun")
)
if (grassStarted()) {
# Setup
library(terra)
# Example data
madElev <- fastData("madElev")
# Convert a SpatRaster to a GRaster
elev <- fast(madElev)
### Calculate input rasters
###########################
# Values below are just a guess
coeff_bh <- coeff_dh <- elev
coeff_bh[] <- 0.4
coeff_dh[] <- 0.6
slope <- terrain(elev, "slope")
aspect <- terrain(elev, "aspect", northIs0 = FALSE)
horizon_step <- 90
hh <- horizonHeight(elev, step = horizon_step, northIs0 = FALSE)
### calculate solar ir/radiance
###############################
solar <- sun(
elevation = elev,
coeff_bh = coeff_bh,
coeff_dh = coeff_dh,
slope = slope,
aspect = aspect,
hh = hh,
horizon_step = horizon_step,
albedo = 0.2,
linke = 1.5,
day = 1,
step = 0.5,
declination = NULL,
solar_constant = 1367,
distance_step = 1,
npartitions = 1,
beam_rad = TRUE,
diff_rad = TRUE,
refl_rad = TRUE,
glob_rad = TRUE,
insol_time = TRUE,
lowMemory = FALSE
)
solar
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.