fit_coneshaped_model: Fit cone-shaped model

View source: R/fit_coneshaped_model.R

fit_coneshaped_modelR Documentation

Fit cone-shaped model

Description

Fit a polynomial model to predict relative radiance from spherical coordinates using data sampled from a canopy photograph.

Usage

fit_coneshaped_model(sky_points, method = "zenith_n_azimuth")

Arguments

sky_points

data.frame returned by extract_rr(). If it is generated by other means, it must have columns row, col, z, a, and rr.

method

character. Model type to fit:

"zenith_only"

Quadratic polynomial in zenith angle.

"zenith_n_azimuth"

Quadratic polynomial in zenith plus sinusoidal terms in azimuth.

Details

This model requires only sky_points, making it useful in workflows where sun position cannot be reliably estimated, such as in apply_by_direction(). Otherwise, fit_cie_model() is a better choice.

Depending on method, it can fit:

A zenith-only quadratic model

sDN = a + b\theta + c\theta^2

A zenith-plus-azimuth model, adding sinusoidal terms

sDN = a + b\theta + c\theta^2 + d\sin(\phi) + e\cos(\phi)

See \insertCiteDiaz2018;textualrcaiman for details on the full model.

Value

List with the following components:

fun

Function taking zenith and azimuth (degrees) and returning predicted relative radiance.

model

lm object fitted by stats::lm().

Returns NULL (with a warning) if the number of input points is fewer than 20.

References

\insertAllCited

Examples

## Not run: 
caim <- read_caim()
z <- zenith_image(ncol(caim), lens())
a <- azimuth_image(z)
m <- !is.na(z)
r <- caim$Blue

bin <- binarize_by_region(r, ring_segmentation(z, 15), "thr_isodata") &
  select_sky_region(z, 0, 88)

g <- sky_grid_segmentation(z, a, 10, first_ring_different = TRUE)
sky_points <- extract_sky_points(r, bin, g, dist_to_black = 3)
plot(bin)
points(sky_points$col, nrow(caim) - sky_points$row, col = 2, pch = 10)
rr <- extract_rr(r, z, a, sky_points)

model <- fit_coneshaped_model(rr$sky_points)
summary(model$model)
sky_cs <- model$fun(z, a) * rr$zenith_dn
plot(sky_cs)

z_mini <- zenith_image(50, lens())
sky_cs <- model$fun(z_mini, azimuth_image(z_mini))
persp(sky_cs, theta = 90, phi = 20)


## End(Not run)

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