if (FALSE) {
caim <- read_caim() %>% normalize()
z <- zenith_image(ncol(caim), lens())
a <- azimuth_image(z)
# Manual method after Lang et al. (2010)
# ImageJ can be used to digitize points
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")
head(sky_points)
plot(caim$Blue)
points(sky_points$col, nrow(caim) - sky_points$row, col = 2, pch = 10)
xy <- c(210, 451) #originally captured with click() after x11()
sun_coord <- zenith_azimuth_from_row_col(z, z, c(nrow(z) - xy[2],xy[1]))
points(sun_coord$row_col[2], nrow(caim) - sun_coord$row_col[1],
col = 3, pch = 1)
rl <- extract_rl(caim$Blue, z, a, sky_points)
set.seed(7)
model <- fit_cie_sky_model(caim$Blue, z, a, rl$sky_points,
rl$zenith_dn, sun_coord,
general_sky_type = "Clear",
rmse = FALSE,
twilight = FALSE,
method = "SANN")
summary(model$mle2_output)
plot(model$obs, model$pred)
abline(0,1)
r2 <- lm(model$pred~model$obs) %>% summary(.) %>% .$r.squared
r2
sky_cie <- cie_sky_model_raster(z, a,
model$sun_coord$zenith_azimuth,
model$coef) * model$zenith_dn
plot(sky_cie)
plot(caim$Blue/sky_cie)
# A quick demonstration of how to use interpolation to improve sky modelling
# after Lang et al. (2010)
sky <- interpolate_sky_points(rl$sky_points, caim$Blue, rmax = ncol(caim)/7)
plot(sky)
sky <- sky * rl$zenith_dn * (1 - r2) + sky_cie * r2
sky <- terra::cover(sky, sky_cie)
plot(sky)
plot(caim$Blue/sky)
# how to provide a custom starting coefficient
model <- fit_cie_sky_model(caim$Blue, z, a, rl$sky_points,
rl$zenith_dn, sun_coord,
custom_sky_coef = model$coef,
method = "SANN")
plot(model$obs, model$pred, ylim = range(model$obs))
abline(0,1)
}
Run the code above in your browser using DataLab