R Under development (unstable) (2024-07-13 r86895 ucrt) -- "Unsuffered Consequences" Copyright (C) 2024 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > Sys.setenv(TZ="UTC") > suppressPackageStartupMessages(library(sf)) > suppressPackageStartupMessages(library(stars)) > tif = system.file("tif/L7_ETMs.tif", package = "stars") > (r = read_stars(tif, proxy = TRUE)) stars_proxy object with 1 attribute in 1 file(s): $L7_ETMs.tif [1] "[...]/L7_ETMs.tif" dimension(s): from to offset delta refsys point x/y x 1 349 288776 28.5 SIRGAS 2000 / UTM zone 25S FALSE [x] y 1 352 9120761 -28.5 SIRGAS 2000 / UTM zone 25S FALSE [y] band 1 6 NA NA NA NA > if (interactive()) { + plot(r) + } > dim(r) x y band 349 352 6 > r[,,,2:3] stars_proxy object with 1 attribute in 1 file(s): $L7_ETMs.tif [1] "[...]/L7_ETMs.tif" dimension(s): from to offset delta refsys point x/y x 1 349 288776 28.5 SIRGAS 2000 / UTM zone 25S FALSE [x] y 1 352 9120761 -28.5 SIRGAS 2000 / UTM zone 25S FALSE [y] band 2 3 NA NA NA NA > r+r stars_proxy object with 1 attribute in 1 file(s): $L7_ETMs.tif [1] "[...]/L7_ETMs.tif" dimension(s): from to offset delta refsys point x/y x 1 349 288776 28.5 SIRGAS 2000 / UTM zone 25S FALSE [x] y 1 352 9120761 -28.5 SIRGAS 2000 / UTM zone 25S FALSE [y] band 1 6 NA NA NA NA call_list: [[1]] e1 + e2 attr(,".Environment") This object has pending lazy operations: dimensions as printed may not reflect this. > st_as_stars(sin(r), downsample = 2) stars object with 3 dimensions and 1 attribute attribute(s): Min. 1st Qu. Median Mean 3rd Qu. Max. L7_ETMs.tif -0.9999902 -0.676772 0.0353983 0.01655317 0.7210377 0.9999119 dimension(s): from to offset delta refsys point x/y x 1 117 288776 85.01 SIRGAS 2000 / UTM zone 25S FALSE [x] y 1 118 9120761 -85.02 SIRGAS 2000 / UTM zone 25S FALSE [y] band 1 6 NA NA NA NA > aperm(r, c(3,2,1)) stars_proxy object with 1 attribute in 1 file(s): $L7_ETMs.tif [1] "[...]/L7_ETMs.tif" dimension(s): from to offset delta refsys point x/y x 1 349 288776 28.5 SIRGAS 2000 / UTM zone 25S FALSE [x] y 1 352 9120761 -28.5 SIRGAS 2000 / UTM zone 25S FALSE [y] band 1 6 NA NA NA NA call_list: [[1]] aperm(a = a, perm = perm) attr(,".Environment") This object has pending lazy operations: dimensions as printed may not reflect this. > if (interactive()) { + plot(r) + } > (xx = c(r,r)) stars_proxy object with 2 attributes in 2 file(s): $L7_ETMs.tif [1] "[...]/L7_ETMs.tif" $L7_ETMs.tif [1] "[...]/L7_ETMs.tif" dimension(s): from to offset delta refsys point x/y x 1 349 288776 28.5 SIRGAS 2000 / UTM zone 25S FALSE [x] y 1 352 9120761 -28.5 SIRGAS 2000 / UTM zone 25S FALSE [y] band 1 6 NA NA NA NA > st_redimension(xx) stars_proxy object with 1 attribute in 2 file(s): $L7_ETMs.tif.L7_ETMs.tif [1] "[...]/L7_ETMs.tif" "[...]/L7_ETMs.tif" dimension(s): from to offset delta refsys point x 1 349 288776 28.5 SIRGAS 2000 / UTM zone 25S FALSE y 1 352 9120761 -28.5 SIRGAS 2000 / UTM zone 25S FALSE band 1 6 NA NA NA NA new_dim 1 2 NA NA NA NA values x/y x NULL [x] y NULL [y] band NULL new_dim L7_ETMs.tif, L7_ETMs.tif > st_as_stars(r) stars object with 3 dimensions and 1 attribute attribute(s): Min. 1st Qu. Median Mean 3rd Qu. Max. L7_ETMs.tif 1 54 69 68.91242 86 255 dimension(s): from to offset delta refsys point x/y x 1 349 288776 28.5 SIRGAS 2000 / UTM zone 25S FALSE [x] y 1 352 9120761 -28.5 SIRGAS 2000 / UTM zone 25S FALSE [y] band 1 6 NA NA NA NA > (y = st_apply(r, 1:2, max)) stars_proxy object with 1 attribute in 1 file(s): $L7_ETMs.tif [1] "[...]/L7_ETMs.tif" dimension(s): from to offset delta refsys point x/y x 1 349 288776 28.5 SIRGAS 2000 / UTM zone 25S FALSE [x] y 1 352 9120761 -28.5 SIRGAS 2000 / UTM zone 25S FALSE [y] band 1 6 NA NA NA NA call_list: [[1]] st_apply(X = X, MARGIN = MARGIN, FUN = FUN, CLUSTER = CLUSTER, PROGRESS = PROGRESS, FUTURE = FUTURE, rename = rename, .fname = .fname) attr(,".Environment") This object has pending lazy operations: dimensions as printed may not reflect this. > (yy = st_as_stars(y, downsample = 1)) stars object with 2 dimensions and 1 attribute attribute(s): Min. 1st Qu. Median Mean 3rd Qu. Max. max 55 85 96 99.38568 113 255 dimension(s): from to offset delta refsys point x/y x 1 175 288776 56.84 SIRGAS 2000 / UTM zone 25S FALSE [x] y 1 176 9120761 -57 SIRGAS 2000 / UTM zone 25S FALSE [y] > (y = adrop(st_apply(r, c("x", "y"), max))) stars_proxy object with 1 attribute in 1 file(s): $L7_ETMs.tif [1] "[...]/L7_ETMs.tif" dimension(s): from to offset delta refsys point x/y x 1 349 288776 28.5 SIRGAS 2000 / UTM zone 25S FALSE [x] y 1 352 9120761 -28.5 SIRGAS 2000 / UTM zone 25S FALSE [y] band 1 6 NA NA NA NA call_list: [[1]] st_apply(X = X, MARGIN = MARGIN, FUN = FUN, CLUSTER = CLUSTER, PROGRESS = PROGRESS, FUTURE = FUTURE, rename = rename, .fname = .fname) attr(,".Environment") [[2]] adrop(x = x, drop = drop) attr(,".Environment") This object has pending lazy operations: dimensions as printed may not reflect this. > (yy = st_as_stars(y, downsample = 1)) stars object with 2 dimensions and 1 attribute attribute(s): Min. 1st Qu. Median Mean 3rd Qu. Max. max 55 85 96 99.38568 113 255 dimension(s): from to offset delta refsys point x/y x 1 175 288776 56.84 SIRGAS 2000 / UTM zone 25S FALSE [x] y 1 176 9120761 -57 SIRGAS 2000 / UTM zone 25S FALSE [y] > plot(yy) > (y = adrop(st_apply(r, c("x", "band"), max))) stars_proxy object with 1 attribute in 1 file(s): $L7_ETMs.tif [1] "[...]/L7_ETMs.tif" dimension(s): from to offset delta refsys point x/y x 1 349 288776 28.5 SIRGAS 2000 / UTM zone 25S FALSE [x] y 1 352 9120761 -28.5 SIRGAS 2000 / UTM zone 25S FALSE [y] band 1 6 NA NA NA NA call_list: [[1]] st_apply(X = X, MARGIN = MARGIN, FUN = FUN, CLUSTER = CLUSTER, PROGRESS = PROGRESS, FUTURE = FUTURE, rename = rename, .fname = .fname) attr(,".Environment") [[2]] adrop(x = x, drop = drop) attr(,".Environment") This object has pending lazy operations: dimensions as printed may not reflect this. > (yy = st_as_stars(y, downsample = 1)) stars object with 2 dimensions and 1 attribute attribute(s): Min. 1st Qu. Median Mean 3rd Qu. Max. max 77 111 133 137.8505 157 255 dimension(s): from to offset delta refsys point x 1 175 288776 56.84 SIRGAS 2000 / UTM zone 25S FALSE band 1 6 NA NA NA NA Warning message: In FUN(X[[i]], ...) : st_apply on x/y dimensions applied to downsampled image(s) > rm(yy) > > (xx = c(r,r)) stars_proxy object with 2 attributes in 2 file(s): $L7_ETMs.tif [1] "[...]/L7_ETMs.tif" $L7_ETMs.tif [1] "[...]/L7_ETMs.tif" dimension(s): from to offset delta refsys point x/y x 1 349 288776 28.5 SIRGAS 2000 / UTM zone 25S FALSE [x] y 1 352 9120761 -28.5 SIRGAS 2000 / UTM zone 25S FALSE [y] band 1 6 NA NA NA NA > names(xx) = c("a", "b") > xx["a"] stars_proxy object with 1 attribute in 1 file(s): $a [1] "[...]/L7_ETMs.tif" dimension(s): from to offset delta refsys point x/y x 1 349 288776 28.5 SIRGAS 2000 / UTM zone 25S FALSE [x] y 1 352 9120761 -28.5 SIRGAS 2000 / UTM zone 25S FALSE [y] band 1 6 NA NA NA NA > pt = st_point(c(x = 290462.103109179, y = 9114202.32594085)) > buf = st_buffer(st_sfc(pt, crs = st_crs(r)), 1500) > buf = st_sfc(st_polygon(list(st_buffer(pt, 1500)[[1]], st_buffer(pt, 1000)[[1]])), + crs = st_crs(r)) > r = r[buf] # crops > r = r[buf, epsilon = 1e-5] # crops with shrinked bounding box > > # c: > f = system.file("netcdf/avhrr-only-v2.19810902.nc", package = "starsdata") > if (FALSE && f != "") { + files = c("avhrr-only-v2.19810901.nc", + "avhrr-only-v2.19810902.nc", + "avhrr-only-v2.19810903.nc", + "avhrr-only-v2.19810904.nc", + "avhrr-only-v2.19810905.nc", + "avhrr-only-v2.19810906.nc", + "avhrr-only-v2.19810907.nc", + "avhrr-only-v2.19810908.nc", + "avhrr-only-v2.19810909.nc") + l = list() + for (f in files) { + from = system.file(paste0("netcdf/", f), package = "starsdata") + l[[f]] = read_stars(from, sub = c("sst", "anom"), proxy = TRUE) + } + ret = do.call(c, l) + print(ret) + all = system.file(paste0("netcdf/", files), package = "starsdata") + ret = read_stars(all, sub = c("sst", "anom")) + print(ret) + print(st_redimension(ret)) # collapse the two attributes into new dimension + + try(ret <- c(l[[1]], l[[2]], l[[3]], along = list(times = as.Date("1981-09-01") + 0:2))) + #print(ret) + #ret = adrop(adrop(c(l[[1]], l[[2]], l[[3]], along = "times"))) + #print(ret) + ret <- st_redimension(l[[1]], along = list(times = as.Date("1981-09-01") + 0:1)) + print(ret) + } > > # demonstrate that environments work: > x = read_stars(tif, proxy = TRUE) > f = function(x) { + g = function(xx) { + ndvi = function(z1, z2, z3, z4, z5, z6) (z2-z1)/(z2+z1) + st_apply(xx, 1:2, ndvi) + } + g(x) + } > (x = f(x)) stars_proxy object with 1 attribute in 1 file(s): $L7_ETMs.tif [1] "[...]/L7_ETMs.tif" dimension(s): from to offset delta refsys point x/y x 1 349 288776 28.5 SIRGAS 2000 / UTM zone 25S FALSE [x] y 1 352 9120761 -28.5 SIRGAS 2000 / UTM zone 25S FALSE [y] band 1 6 NA NA NA NA call_list: [[1]] st_apply(X = X, MARGIN = MARGIN, FUN = FUN, CLUSTER = CLUSTER, PROGRESS = PROGRESS, FUTURE = FUTURE, rename = rename, .fname = .fname) attr(,".Environment") This object has pending lazy operations: dimensions as printed may not reflect this. > st_as_stars(x) stars object with 2 dimensions and 1 attribute attribute(s): Min. 1st Qu. Median Mean 3rd Qu. Max. ndvi -0.2828283 -0.1081081 -0.08287293 -0.08464615 -0.05882353 0.09259259 dimension(s): from to offset delta refsys point x/y x 1 349 288776 28.5 SIRGAS 2000 / UTM zone 25S FALSE [x] y 1 352 9120761 -28.5 SIRGAS 2000 / UTM zone 25S FALSE [y] > > proc.time() user system elapsed 2.09 0.25 2.28