setNormalized: Set the "normalized" and "normalization" attributes

View source: R/spct.normalize.r

setNormalizedR Documentation

Set the "normalized" and "normalization" attributes

Description

Function to write the "normalized" attribute of an existing generic_spct object.

Usage

setNormalized(
  x,
  norm = FALSE,
  norm.type = NA_character_,
  norm.factors = NA_real_,
  norm.cols = NA_character_,
  norm.range = rep(NA_real_, 2),
  verbose = getOption("verbose_as_default", default = FALSE)
)

setNormalised(
  x,
  norm = FALSE,
  norm.type = NA_character_,
  norm.factors = NA_real_,
  norm.cols = NA_character_,
  norm.range = rep(NA_real_, 2),
  verbose = getOption("verbose_as_default", default = FALSE)
)

Arguments

x

a generic_spct object.

norm

logical or numeric If FALSE or 0 existing normalization metadata is is deleted from x. Otherwise, a positive numeric value is interpreted as the normalization wavelength (nm, nanometres).

norm.type

character Type of normalization applied.

norm.factors

numeric The scaling factor(s) so that dividing the spectral values by this factor reverts the normalization.

norm.cols

character The name(s) of the columns in x that have been normalized.

norm.range

numeric The wavelength range used for normalization (nm).

verbose

logical Flag enabling or silencing informative warnings.

Details

This function is used internally, although occasionally users may want to use it to "pretend" that spectral data have not been normalized. Use normalize() methods to apply a normalization and simultaneously set the metadata attributes. Function setNormalized() only saves to the attributes the metadata corresponding to an already applied normalization. The metadata provides a trace of the transformations applied to spectral data that makes it possible to undo the normalization. The metadata is also used in other by functions in package 'ggspectra' when automatically generating axis labels.

If norm = FALSE is passed in the call any normalization metadata present in x are reset and, thus, x marked as not normalized, without undoing the effect of the normalization.

If x is not a generic_spct object, x is not modified.

Value

The object passed as argument to x is modified by reference by adding attributes normalized and normalization, unless the argument passed to x is an anonymous expression. A copy of the modified x is always returned invisibly, even when setting by reference fails.

With a single spectrum in x, attribute normalization is set to a named list, and in the case of multiple spectra in long form, it is set a named list or named lists, unless norm = FALSE is passed, in which case the normalization attribute is deleted if already present. The named list for each spectrum contains the fields:

norm.type

character vector of length one, one of "max", "min", "wavelength".

norm.wl

numeric, normalization wavelength in nanometres.

norm.factors

numeric, multiplier constans used to scale the normalized spectral data.

norm.cols

character, the name of the columns of x that have been normalized.

norm.range

numeric vector of length 2, with min and maximum w.length values used to constrain the normalization.

Spectral objects, to allow choice in the trade-off between storage space and computation effort, can contain multiple columns of spectral data (e.g., s.e.irrad and s.q.irard), each one with its own normalization. Only one value is allowed for norm.type, but norm.wl and norm.factors are vectors of the same length as norm.cols as their numeric values depend on the unit/base of expression.

Attribute normalized is set to TRUE unless norm = FALSE is passed.

Note

Passing a logical as argument to norm is deprecated but accepted silently for backwards compatibility.

setNormalised() is another name for setNormalized().

See Also

Other rescaling functions: fscale(), fshift(), getNormalized(), getScaled(), is_normalized(), is_scaled(), normalize(), setScaled()

Examples

norm_sun.spct <- normalize(sun.spct, norm = "max")
is_normalized(norm_sun.spct)
# rarely useful: pretend that the spectrum has not been normalized
pretended_sun.spct <- setNormalized(norm_sun.spct, norm = FALSE)
is_normalized(pretended_sun.spct)


photobiology documentation built on March 15, 2026, 9:06 a.m.