preprocess: Tile Preprocess

Description Usage Arguments Value Examples

Description

The function is a wrapper that allows the user to perform a user-define function to each pixel spectrum. It can be called internally in mosaic_sam using the FUN argument when processing mosaics.

As exemplified below, the function allows you to interact with other R packages that provide common features to analyze spectral data. Beware that you will need to adjust the wavenumbers manually if you are resampling... unless that 'data' is an object of class SpectralPack.

Usage

1
2
3
4
5
6
7
preprocess(data, FUN)

## S4 method for signature 'Tile,'function''
preprocess(data, FUN)

## S4 method for signature 'SpectralPack,'function''
preprocess(data, FUN)

Arguments

data

An object of class Tile or SpectralPack.

FUN

A function to apply to the Spectra slot.

Value

The same object but with the Spectra slot updated by FUN. SpectralPack objects return the wavelengths adjusted to the new extent, numbered from 1 to n (original values are lost).

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
x <- tile_read(base::system.file("extdata/tile.bsp", package = "uFTIR"))
x <- preprocess(x, function(x){x+1})

# The function allows interacting with other R packages that provide common features
# for spectra analysis. For example, you can use the package "signal" to run
# a Savitzky-Golay filter.

if(requireNamespace("signal", quietly = TRUE)){

# for Tile objects. NOTE that after the preprocess x@wavenumbers does not match dim(x@Spectra)[3]
x <- tile_read(base::system.file("extdata/tile.bsp", package = "uFTIR"))
x <- preprocess(x, function(x){signal::sgolayfilt(x)})
dim(x@Spectra)[3] == length(x@wavenumbers) # BEWARE!

# for SpectralPack objects
x <- tile_read(base::system.file("extdata/tile.bsp", package = "uFTIR"))
x <- tile_base_corr(x)
x <- wavealign(x, primpke)
preprocess(x, function(x){signal::sgolayfilt(x)})

# Here the problem with the wavenumbers is gone
dim(x@Readings@Spectra)[3] == length(x@Readings@wavenumbers)
dim(x@Reference@Spectra)[3] == length(x@Reference@wavenumbers)
length(x@Readings@wavenumbers) == length(x@Reference@wavenumbers)

}

uFTIR documentation built on Oct. 25, 2021, 9:08 a.m.