chunk | R Documentation |
In the case of 'Cannot allocate vector of size ...' error message chunk_band
returns list of bands indices, which are suitable for allocation in memory at once, chunk_line
returns list of lines (rows) indices, which are suitable for allocation in memory at once. chunk_expand
is used to expand lines indices and can by applied in focal functions.
chunk_band(obj, mem = 100, mul = 1)
chunk_line(obj, mem = 100, mul = 1)
chunk_expand(ind, size = 3)
obj |
Object of class |
mem |
Numeric. Memory size in GB, which is suitable for allocation. |
mul |
Numeric. Expansion or reduction factor (multiplier) of default value of memory allocation. |
ind |
Integer. Line indices. |
size |
Integer. Size of focal window. |
chunk_band
returns list with sequences of bands
chunk_line
returns list with sequences of lines
chunk_expand
returns list:
src |
expanded set if line indices |
dst |
matching of source indices in the expanded set |
Nikita Platonov platonov@sevin.ru
## 1. Prepare data
session_grid(NULL)
fname <- ursa:::.maketmp(2)
a <- create_envi(fname[1],nband=3,ignorevalue=-99)
for (i in seq(nband(a)))
a[i] <- pixelsize()^(1/i)
close(a)
rm(a)
## 2. Read
a <- open_envi(fname[1])
chB <- chunk_band(a,2)
str(chB)
for (i in chB)
print(a[i])
chL <- chunk_line(a,2.5)
str(chL)
for (j in chL)
print(a[,j])
## 3. Filtering with partial reading
b <- create_envi(a,fname[2])
fsize <- 15
for (j in chL) {
k <- chunk_expand(j,fsize)
b[,j] <- focal_mean(a[,k$src],size=fsize)[,k$dst]
}
d1 <- b[]
## 4. Filtering in memory
d2 <- focal_mean(a[],size=fsize)
close(a,b)
envi_remove(fname)
print(d1-d2)
print(round(d1-d2,4))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.