sky_grid_segmentation: Assign sky-grid labels

View source: R/sky_grid_segmentation.R

sky_grid_segmentationR Documentation

Assign sky-grid labels

Description

Segment a hemispherical view into equal-angle bins in zenith and azimuth, assigning each pixel a grid-cell ID.

Usage

sky_grid_segmentation(z, a, angle_width, first_ring_different = FALSE)

Arguments

z

terra::SpatRaster generated with zenith_image().

a

terra::SpatRaster generated with azimuth_image().

angle_width

numeric vector of length one. Angle in deg that must divide both 0–360 and 0–90 into an integer number of segments. Retrieve a set of valid values by running lapply(c(45, 30, 18, 10), function(a) vapply(0:6, function(x) a/2^x, 1)).

first_ring_different

logical vector of length one. If TRUE, do not subdivide the first ring.

Details

The intersection of zenith rings and azimuth sectors forms a grid whose cells are circular trapezoids. By default, IDs encode both components as sectorID * 1000 + ringID. If first_ring_different = TRUE, the zenith ring is not subdivided.

The code below outputs a comprehensive list of valid values for angle_width. For convenience, the column radians_denom can be used to provide angle_width as 180 / radians_denom_i, where radians_denom_i is a value taken from radians_denom.

df <- data.frame(degrees = 90 / 1:180)

deg_to_pi_expr <- function(deg) {
  frac <- MASS::fractions(deg / 180)
  strsplit(as.character(frac), "/")[[1]][2] %>% as.numeric()
}

df$radians_denom <- sapply(df$degrees, function(deg) deg_to_pi_expr(deg))

z <- zenith_image(10, lens())
a <- azimuth_image(z)
u <- c()
for (i in 1:nrow(df)) {
  u <- c(u, tryCatch(is((sky_grid_segmentation(z, a,
                            180/df$radians_denom[i])), "SpatRaster"),
                     error = function(e) FALSE))
}
df <- df[u, ]
df

Value

Single-layer terra::SpatRaster with integer labels. The object carries attributes angle_width and first_ring_different.

See Also

sky_grid_centers(), ring_segmentation(), sector_segmentation()

Examples

caim <- read_caim()
z <- zenith_image(ncol(caim), lens())
a <- azimuth_image(z)
g <- sky_grid_segmentation(z, a, 15)
plot(g == 24005)
## Not run: 
display_caim(g = g)

## End(Not run)

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