attributes_speclib: Handling supplementary information (SI) of spectra

Description Usage Arguments Details Value Author(s) See Also Examples

Description

Supplementary information (SI) can be any additional data available for each spectrum in a Speclib- or Nri-object. These functions are used to set or return SI-data of a Speclib or Nri-object. Note that SI-data is automatically subsetted if indexing and extracting single spectra from a Speclib- or Nri-object. SI-data may encompass (several) raster files which must have the same extent, resolution and x- and y-dimensions as the raster file used as spectral information.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
## S4 method for signature 'Speclib'
SI(object)

## S4 method for signature 'Speclib,ANY,ANY'
SI(object, i, j)

## S4 replacement method for signature 'Speclib,data.frame'
SI(object) <- value

## S4 replacement method for signature 'Speclib,matrix'
SI(object) <- value

## S4 method for signature 'Nri'
SI(object)

## S4 replacement method for signature 'Nri,data.frame'
SI(object) <- value

## S4 replacement method for signature 'Nri,matrix'
SI(object) <- value

Arguments

object

Object of class Speclib or Nri.

i

Index of rows to keep. Note that in combination with raster files in the SI, it is MUCH faster to pass row index instead of cutting the resulting data frame. Thus, SI(object, i) should be used instead of SI(object)[i,].

j

Index of columns to keep. See comment above for usage with raster files in the SI.

value

Data frame with nrow(value) == nspectra(object), NULL or vector with length nspectra(object). Alternatively, objects of class RasterLayer are accepted. Please note that the function does not check for integrity in the latter case (e.g., no error will occur if number of spectra does not match number of pixel in the RasterLayer-object).

Details

Names of items in SI are used within the function subset to select/deselect spectra via logical expression. Values can be accessed via the "\$"-sign (see examples).

Value

For SI<-, the updated object. SI returns a data frame with SI data.

Author(s)

Lukas Lehnert

See Also

Speclib, Nri

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
data(spectral_data)

## Returning SI
si_spec <- SI(spectral_data)
head(si_spec)

## Adding new SI item
SI(spectral_data)$MeasurementID <- c(1:nspectra(spectral_data))
head(SI(spectral_data))

## Replacing SI
SI(spectral_data) <- SI(spectral_data)[,c(1:3)]
head(SI(spectral_data))

## Example for raster file in SI

## Create raster file using PROSAIL
## Run PROSAIL
parameter <- data.frame(N = c(rep.int(seq(0.5, 1.4, 0.1), 6)),
                        LAI = c(rep.int(0.5, 10), rep.int(1, 10), 
                                rep.int(1.5, 10), rep.int(2, 10), 
                                rep.int(2.5, 10), rep.int(3, 10)))
spectra <- PROSAIL(parameterList = parameter)

## Create SpatialPixelsDataFrame and fill data with spectra from 
## PROSAIL
rows <- round(nspectra(spectra)/10, 0)
cols <- ceiling(nspectra(spectra)/rows)
grd <- SpatialGrid(GridTopology(cellcentre.offset = c(1,1,1), 
                                cellsize = c(1,1,1), 
                                cells.dim = c(cols, rows, 1)))
x <- SpatialPixelsDataFrame(grd, 
                            data = as.data.frame(spectra(spectra)))

## Write data to example file (example_in.tif) in workingdirectory
writeGDAL(x, fname = "example_in.tif", drivername = "GTiff")

infile <- "example_in.tif"
wavelength <- wavelength(spectra)
ra <- speclib(infile, wavelength)
tr <- blockSize(ra)

## Write LAI to separate raster file
LAI <- SI(spectra)$LAI
SI_file <- "example_SI.tif" 
SI_raster <- setValues(raster(infile), LAI)
SI_raster <- writeRaster(SI_raster, SI_file)

## Read LAI file and calculate NDVI for each pixel where LAI >= 1
outfile <- "example_result_ndvi.tif" 
SI(ra) <- raster(SI_file)
names(SI(ra)) <- "LAI"
res <- writeStart(ra, outfile, overwrite = TRUE, nl = 1)
for (i in 1:tr$n) 
{
  v <- getValuesBlock(ra, row=tr$row[i], nrows=tr$nrows[i])
  mask(v) <- c(1350, 1450)
  LAI <- SI(v)$LAI
  v <- as.matrix(vegindex(v, index="NDVI"))
  v[LAI <= 1] <- NA
  res <- writeValues(res, v, tr$row[i])
}
res <- writeStop(res)

hsdar documentation built on Nov. 17, 2017, 4:35 a.m.