tests/predict.R

suppressPackageStartupMessages(library(stars))
# predict:
tif = system.file("tif/L7_ETMs.tif", package = "stars")
(x = read_stars(tif))
st_crs(x) = st_crs(x) # cleans trailing space
model = lm(x~L7_ETMs.tif, head(as.data.frame(x), 50))
x = predict(x, model)

(y = read_stars(tif, proxy = TRUE))
(yp = predict(y, model))
all.equal(x, st_as_stars(yp))

yy = st_set_dimensions(y, 3, values = paste0("band", 1:6))
(y_spl = split(yy, 3))
as.data.frame(st_as_stars(split(yy, 3)))[1:3,]

Try the stars package in your browser

Any scripts or data that you put into this service are public.

stars documentation built on Sept. 11, 2023, 5:10 p.m.