This method returns a spectral object of the same class as the one supplied as argument but with the spectral data normalized to 1.0 at a specific wavelength.
Usage
normalize(x, ...)
normalise(x, ...)
# S3 method for default
normalize(x, ...)
# S3 method for source_spct
normalize(
x,
...,
range = NULL,
norm = "max",
unit.out = getOption("photobiology.radiation.unit", default = "energy"),
keep.scaling = FALSE,
na.rm = FALSE
)
# S3 method for response_spct
normalize(
x,
...,
range = NULL,
norm = "max",
unit.out = getOption("photobiology.radiation.unit", default = "energy"),
keep.scaling = FALSE,
na.rm = FALSE
)
# S3 method for filter_spct
normalize(
x,
...,
range = NULL,
norm = "max",
qty.out = getOption("photobiology.filter.qty", default = "transmittance"),
keep.scaling = FALSE,
na.rm = FALSE
)
# S3 method for reflector_spct
normalize(
x,
...,
range = NULL,
norm = "max",
qty.out = NULL,
keep.scaling = FALSE,
na.rm = FALSE
)
# S3 method for solute_spct
normalize(
x,
...,
range = NULL,
norm = "max",
keep.scaling = FALSE,
na.rm = FALSE
)
# S3 method for raw_spct
normalize(
x,
...,
range = NULL,
norm = "max",
keep.scaling = FALSE,
na.rm = FALSE
)
# S3 method for cps_spct
normalize(
x,
...,
range = NULL,
norm = "max",
keep.scaling = FALSE,
na.rm = FALSE
)
# S3 method for generic_spct
normalize(
x,
...,
range = NULL,
norm = "max",
col.names,
keep.scaling = FALSE,
na.rm = FALSE
)
# S3 method for source_mspct
normalize(
x,
...,
range = NULL,
norm = "max",
unit.out = getOption("photobiology.radiation.unit", default = "energy"),
keep.scaling = FALSE,
na.rm = FALSE,
.parallel = FALSE,
.paropts = NULL
)
# S3 method for response_mspct
normalize(
x,
...,
range = NULL,
norm = "max",
unit.out = getOption("photobiology.radiation.unit", default = "energy"),
keep.scaling = FALSE,
na.rm = FALSE,
.parallel = FALSE,
.paropts = NULL
)
# S3 method for filter_mspct
normalize(
x,
...,
range = NULL,
norm = "max",
qty.out = getOption("photobiology.filter.qty", default = "transmittance"),
keep.scaling = FALSE,
na.rm = FALSE,
.parallel = FALSE,
.paropts = NULL
)
# S3 method for reflector_mspct
normalize(
x,
...,
range = x,
norm = "max",
qty.out = NULL,
keep.scaling = FALSE,
na.rm = FALSE,
.parallel = FALSE,
.paropts = NULL
)
# S3 method for raw_mspct
normalize(
x,
...,
range = x,
norm = "max",
keep.scaling = FALSE,
na.rm = FALSE,
.parallel = FALSE,
.paropts = NULL
)
# S3 method for cps_mspct
normalize(
x,
...,
range = x,
norm = "max",
keep.scaling = FALSE,
na.rm = FALSE,
.parallel = FALSE,
.paropts = NULL
)
Arguments
- x
An R object
- ...
not used in current version
- range
An R object on which
range()
returns a numeric vector of length 2 with the limits of a range of wavelengths in nm, with min and max wavelengths (nm) used to set boundaries for search for normalization.- norm
numeric Normalization wavelength (nm) or character string "max", or "min" for normalization at the corresponding wavelength, "update" to update the normalization after modifying units of expression, quantity or range but respecting the previously used criterion, or "skip" to force return of
x
unchanged.- unit.out
character Allowed values "energy", and "photon", or its alias "quantum"
- keep.scaling
logical or numeric Flag to indicate if any existing scaling should be preserved or not. The default,
FALSE
, preserves the behaviour of versions (<= 0.10.9). If numeric, the spectrum is scaled to this value before normalization and marked as not scaled.- na.rm
logical indicating whether
NA
values should be stripped before calculating the summary (e.g. "max") used for normalization.- qty.out
character string Allowed values are "transmittance", and "absorbance" indicating on which quantity to apply the normalization.
- col.names
character vector containing the names of columns or variables to which to apply the normalization.
- .parallel
if TRUE, apply function in parallel, using parallel backend provided by foreach
- .paropts
a list of additional options passed into the foreach function when parallel computation is enabled. This is important if (for example) your code relies on external data or packages: use the .export and .packages arguments to supply them so that all cluster nodes have the correct environment set up for computing.
Value
A copy of x
, with spectral data values normalized to one for
the criterion specified by the argument passed to norm
with
information about the normalization applied saved in attributes
"normalized"
and "normalization"
.
A copy of x
with the values of the spectral quantity rescaled
to 1 at the normalization wavelength. If the normalization wavelength is
not already present in x
, it is added by interpolation---i.e. the
returned value may be one row longer than x
. Attributes
normalized
and normalization
are set to keep a log of the
computations applied.
Details
By default normalization is done based on the maximum of the spectral data. It is possible to also do the normalization based on a user-supplied wavelength expressed in nanometres or the minimum. It is also possible to update an existing normalization for different units of expression or after a conversion to a related spectral quantity.
By default the function is applied to the whole spectrum, but by passing a range of wavelengths as input, the search can be limited to a region of interest within the spectrum.
In 'photobiology' (>= 0.10.8) detailed information about the normalization is stored in an attribute. In 'photobiology' (>= 0.10.10) applying a new normalization to an already normalized spectrum recomputes the multiplier factors stored in the attributes whenever possible. This ensures that the returned object is identical independently of the previous application of a different normalization.
Methods (by class)
normalize(default)
: Default for generic functionnormalize(source_spct)
: Normalize asource_spct
object.normalize(response_spct)
: Normalize a response spectrum.normalize(filter_spct)
: Normalize a filter spectrum.normalize(reflector_spct)
: Normalize a reflector spectrum.normalize(solute_spct)
: Normalize a solute spectrum.normalize(raw_spct)
: Normalize a raw spectrum.normalize(cps_spct)
: Normalize a cps spectrum.normalize(generic_spct)
: Normalize a raw spectrum.normalize(source_mspct)
: Normalize the members of a source_mspct object.normalize(response_mspct)
: Normalize the members of a response_mspct object.normalize(filter_mspct)
: Normalize the members of a filter_mspct object.normalize(reflector_mspct)
: Normalize the members of a reflector_mspct object.normalize(raw_mspct)
: Normalize the members of a raw_mspct object.normalize(cps_mspct)
: Normalize the members of a cps_mspct object.
Note
If the spectrum passed as argument to x
has been previously
scaled, in 'photobiology' (<= 0.10.9) the scaling attribute was always
removed and no normalization factors returned. In 'photobiology'
(>= 0.10.10) scaling information can be preserved by passing
keep.scaling = TRUE
(experimental feature).
normalise()
is a synonym for this normalize()
method.
1) By default if x
contains one or more NA
values and the
normalization is based on a summary quantity, the returned spectrum will
contain only NA
values. If na.rm == TRUE
then the summary
quantity will be calculated after striping NA
values, and only the
values that were NA
in x
will be NA
values in the returned
spectrum. 2) When a numeric value is passed as argument to keep.scaling,
the scaling uses f = "total"
or f = "mean"
depending on the
class of x
. Prescaling is only occasionally needed.
The argument passed to parameter keep.scaling
affects only the
metadata stored in the "normalization"
and "scaling"
attributes of the returned object.
Method normalize
is implemented for solute_spct
objects
but as the spectral data stored in them are a description of an intensive
property of a substance, care should be taken of when normalization is
applied. To represent solutions of specific concentrations
of solutes, filter_spct
objects can be used instead.
See also
Other rescaling functions:
fscale()
,
fshift()
,
getNormalized()
,
getScaled()
,
is_normalized()
,
is_scaled()
,
setNormalized()
,
setScaled()
Examples
normalize(sun.spct)
#> Object: source_spct [522 x 2]
#> Wavelength range 280-800 nm, step 0.9230769-1 nm
#> Label: sunlight, simulated
#> Measured on 2010-06-22 09:51:00 UTC
#> Measured at 60.20911 N, 24.96474 E; Kumpula, Helsinki, FI
#> Time unit 1s
#> Spectral data normalized to s.e.irrad = 1 at 451 nm (max in 280-800 nm)
#>
#> # A tibble: 522 × 2
#> w.length s.e.irrad
#> <dbl> <dbl>
#> 1 280 0
#> 2 281. 0
#> 3 282. 0
#> 4 283. 0
#> 5 284. 0
#> 6 285. 0
#> 7 286. 0
#> 8 286. 0
#> 9 287. 0
#> 10 288. 0
#> # ℹ 512 more rows
normalise(sun.spct) # equivalent
#> Object: source_spct [522 x 2]
#> Wavelength range 280-800 nm, step 0.9230769-1 nm
#> Label: sunlight, simulated
#> Measured on 2010-06-22 09:51:00 UTC
#> Measured at 60.20911 N, 24.96474 E; Kumpula, Helsinki, FI
#> Time unit 1s
#> Spectral data normalized to s.e.irrad = 1 at 451 nm (max in 280-800 nm)
#>
#> # A tibble: 522 × 2
#> w.length s.e.irrad
#> <dbl> <dbl>
#> 1 280 0
#> 2 281. 0
#> 3 282. 0
#> 4 283. 0
#> 5 284. 0
#> 6 285. 0
#> 7 286. 0
#> 8 286. 0
#> 9 287. 0
#> 10 288. 0
#> # ℹ 512 more rows
normalize(sun.spct, norm = "max")
#> Object: source_spct [522 x 2]
#> Wavelength range 280-800 nm, step 0.9230769-1 nm
#> Label: sunlight, simulated
#> Measured on 2010-06-22 09:51:00 UTC
#> Measured at 60.20911 N, 24.96474 E; Kumpula, Helsinki, FI
#> Time unit 1s
#> Spectral data normalized to s.e.irrad = 1 at 451 nm (max in 280-800 nm)
#>
#> # A tibble: 522 × 2
#> w.length s.e.irrad
#> <dbl> <dbl>
#> 1 280 0
#> 2 281. 0
#> 3 282. 0
#> 4 283. 0
#> 5 284. 0
#> 6 285. 0
#> 7 286. 0
#> 8 286. 0
#> 9 287. 0
#> 10 288. 0
#> # ℹ 512 more rows
normalize(sun.spct, norm = 400)
#> Object: source_spct [522 x 2]
#> Wavelength range 280-800 nm, step 0.9230769-1 nm
#> Label: sunlight, simulated
#> Measured on 2010-06-22 09:51:00 UTC
#> Measured at 60.20911 N, 24.96474 E; Kumpula, Helsinki, FI
#> Time unit 1s
#> Spectral data normalized to s.e.irrad = 1 at 400 nm (wavelength)
#>
#> # A tibble: 522 × 2
#> w.length s.e.irrad
#> <dbl> <dbl>
#> 1 280 0
#> 2 281. 0
#> 3 282. 0
#> 4 283. 0
#> 5 284. 0
#> 6 285. 0
#> 7 286. 0
#> 8 286. 0
#> 9 287. 0
#> 10 288. 0
#> # ℹ 512 more rows