View source: R/interpolate_spherical.R
interpolate_spherical | R Documentation |
Interpolate values from canopy photographs using inverse distance weighting (IDW) with k-nearest neighbors, computing distances in spherical coordinates that map the sky vault. Optionally blend with a model surface to fill voids.
interpolate_spherical(
sky_points,
z,
a,
filling_source = NULL,
w = 1,
k = 3,
p = 2,
angular_radius = 20,
rule = "any",
size = 50
)
sky_points |
|
z |
terra::SpatRaster generated with |
a |
terra::SpatRaster generated with |
filling_source |
optional numeric terra::SpatRaster with one
layer. Surface used to complement |
w |
numeric vector of length one. Weight assigned to |
k |
numeric vector of length one. Number of neighbors. |
p |
numeric vector of length one. Inverse distance weighting exponent. |
angular_radius |
numeric vector of length one. The maximum radius for searching k-nearest neighbors (KNN) in degrees. |
rule |
character vector of length one. Either |
size |
numeric vector of length one. Number of rows and columns of the low-resolution grid used before resampling to full resolution. |
Distances are great-circle distances on the sky vault. When filling_source
is
provided, local IDW estimates are blended with that surface following Eq. 6
in \insertCiteLang2010;textualrcaiman. For efficiency, interpolation runs
on a temporary low-resolution grid of size size
.
Numeric terra::SpatRaster with one layer of interpolated
values and the geometry of z
.
This function assumes that sky_points
and the
terra::SpatRaster inputs are spatially aligned and share the same
geometry. No checks are performed to enforce this.
## Not run:
caim <- read_caim()
z <- zenith_image(ncol(caim), lens())
a <- azimuth_image(z)
# Manual method following Lang et al. (2010)
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)
# x11()
# plot(caim$Blue)
# sun_angles <- click(c(z, a), 1) %>% as.numeric()
sun_angles <- c(z = 49.5, a = 27.4) #taken with above lines then hardcoded
sun_row_col <- row_col_from_zenith_azimuth(z, a,
sun_angles["z"],
sun_angles["a"])
points(sun_row_col[2], nrow(caim) - sun_row_col[1],
col = "yellow", pch = 8, cex = 3)
rr <- extract_rr(caim$Blue, z, a, sky_points)
set.seed(7)
model <- fit_cie_model(rr, sun_angles,
general_sky_type = "Clear")
sky_cie <- cie_image(z, a, model$sun_angles, model$coef)
sky_rr <- interpolate_spherical(rr$sky_points, z, a,
filling_source = sky_cie,
w = 1,
k = 10,
p = 2,
angular_radius = 20,
rule = "any",
size = 50)
plot(r/sky_rr/rr$zenith_dn)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.