optim_sun_angles: Optimize sun angular coordinates

View source: R/optim_sun_angles.R

optim_sun_anglesR Documentation

Optimize sun angular coordinates

Description

Refine the solar position in a fitted CIE sky model by optimizing zenith and azimuth to best match observed relative radiance.

Usage

optim_sun_angles(model, method = c("Nelder-Mead", "BFGS", "CG", "SANN"))

Arguments

model

list returned by fit_cie_model().

method

character vector. One or more optimization methods supported by stats::optim(). Each is applied independently.

Details

Evaluates one or more methods from stats::optim() starting at model$sun_angles. After each optimization the model is re‑fitted and the process repeats until the change in solar position is < 1 deg. The best result across methods is kept.

Value

List like model, potentially with updated sun_angles and metric, and a new method_sun indicating the best optimization method. If no improvement is found, method_sun is NULL.

Note

The objective function penalizes solutions that move the sun position by more than 10 deg from the initial estimate to discourage unrealistic shifts.

Examples

## Not run: 
caim <- read_caim()
z <- zenith_image(ncol(caim), lens())
a <- azimuth_image(z)

# See fit_cie_model() for details on below file
path <- system.file("external/sky_points.csv",
                    package = "rcaiman")
sky_points <- read.csv(path)
sky_points <- sky_points[c("Y", "X")]
colnames(sky_points) <- c("row", "col")
sun_angles <- c(z = 39.5, a = 17.4)

rr <- extract_rr(caim$Blue, z, a, sky_points)

set.seed(7)
model <- fit_cie_model(rr, sun_angles, general_sky_type = "Clear")

print(model$sun_angles)
print(model$metric)

plot(model$rr$sky_points$rr, model$rr$sky_points$pred)
abline(0,1)
lm(model$rr$sky_points$pred~model$rr$sky_points$rr) %>% summary()

model <- optim_sun_angles(model)
print(model$sun_angles)
print(model$metric)
model$method_sun

## End(Not run)

rcaiman documentation built on Sept. 9, 2025, 5:42 p.m.