extract_dn: Extract digital numbers from sky points

View source: R/extract_dn.R

extract_dnR Documentation

Extract digital numbers from sky points

Description

Obtain digital numbers from a raster at positions defined by sky points, with optional local averaging.

Usage

extract_dn(r, sky_points, use_window = TRUE)

Arguments

r

terra::SpatRaster. Image from which sky_points were sampled (or any raster with identical dimensions).

sky_points

data.frame with columns row and col (raster coordinates).

use_window

logical of length one. If TRUE (default), use a 3 \times 3 local mean around each point; if FALSE, use only the central pixel.

Details

Wraps terra::extract() to support a 3 \times 3 window centered on each target pixel (local mean). When it is disabled, only the central pixel value is retrieved.

Value

data.frame containing the original sky_points plus one column per layer in r (named after the layers).

Note

For instructions on manually digitizing sky points, see the “Digitizing sky points with ImageJ” and “Digitizing sky points with QGIS” sections in fit_cie_model().

See Also

extract_sky_points()

Examples

## Not run: 
caim <- read_caim()
r <- caim$Blue
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")
head(sky_points)
plot(caim$Blue)
points(sky_points$col, nrow(caim) - sky_points$row, col = 2, pch = 10)

sky_points <- extract_dn(caim, sky_points)
head(sky_points)

# To aggregate DNs across points (excluding 'row' and 'col'):
apply(sky_points[, -(1:2)], 2, mean, na.rm = TRUE)

## End(Not run)

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