chunk: Get indices for partial image reading/writing

chunkR Documentation

Get indices for partial image reading/writing

Description

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.

Usage

chunk_band(obj, mem = 100, mul = 1)
chunk_line(obj, mem = 100, mul = 1)
chunk_expand(ind, size = 3)

Arguments

obj

Object of class ursaRaster

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.

Value

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

Author(s)

Nikita Platonov platonov@sevin.ru

Examples

 ## 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))

ursa documentation built on Oct. 17, 2023, 5:11 p.m.

Related to chunk in ursa...