Package 'photobiology'

Title: Photobiological Calculations
Description: Definitions of classes, methods, operators and functions for use in photobiology and radiation meteorology and climatology. Calculation of effective (weighted) and not-weighted irradiances/doses, fluence rates, transmittance, reflectance, absorptance, absorbance and diverse ratios and other derived quantities from spectral data. Local maxima and minima: peaks, valleys and spikes. Conversion between energy-and photon-based units. Wavelength interpolation. Astronomical calculations related solar angles and day length. Colours and vision. This package is part of the 'r4photobiology' suite, Aphalo, P. J. (2015) <doi:10.19232/uv4pb.2015.1.14>.
Authors: Pedro J. Aphalo [aut, cre] , Titta K. Kotilainen [ctb] , Glenn Davis [ctb], Agnese Fazio [ctb]
Maintainer: Pedro J. Aphalo <[email protected]>
License: GPL (>= 2)
Version: 0.12.0
Built: 2025-02-01 23:19:59 UTC
Source: https://github.com/aphalo/photobiology

Help Index


photobiology: Photobiological Calculations

Description

logo

Definitions of classes, methods, operators and functions for use in photobiology and radiation meteorology and climatology. Calculation of effective (weighted) and not-weighted irradiances/doses, fluence rates, transmittance, reflectance, absorptance, absorbance and diverse ratios and other derived quantities from spectral data. Local maxima and minima: peaks, valleys and spikes. Conversion between energy-and photon-based units. Wavelength interpolation. Astronomical calculations related solar angles and day length. Colours and vision. This package is part of the 'r4photobiology' suite, Aphalo, P. J. (2015) doi:10.19232/uv4pb.2015.1.14.

Details

Package ‘photobiology’ is at the core of a suite of R packages supporting computations and plotting relevant to photobiology (described at https://www.r4photobiology.info/). Package 'photobiology' has its main focus in the characterization of the light environment, the description of optical properties of objects and substances and description of light responses of organisms and devices used to measure light. The facilities for spectral data storage and manipulations are widely useful in photobiology, chemistry, geophysics, radiation climatology and remote sensing. Astronomical computations for the sun are also implemented. The design of object classes for spectral data supports reproducibility by facilitating the consistent use of units and physical quantities and consistent embedding of metadata. Data are expressed throughout using SI base units, except for wavelengths which are consistently expressed in nanometres [nmnm]. Please see the vignette 0: The R for Photobiology Suite for a description of the suite.

Acknowledgements

This work was funded by the Academy of Finland (decision 252548). COST Action FA9604 ‘UV4Growth’ facilitated discussions and exchanges of ideas that lead to the development of this package. The contributions of Andy McLeod, Lars Olof Björn, Nigel Paul, Lasse Ylianttila, T. Matthew Robson and Titta Kotilainen were specially significant. Tutorials by Hadley Wickham and comments on my presentation at UseR!2015 allowed me to significantly improve the coding and functionality.

Author(s)

Maintainer: Pedro J. Aphalo [email protected] (ORCID)

Other contributors:

References

Aphalo, P. J., Albert, A., Björn, L. O., McLeod, A. R., Robson, T. M., Rosenqvist, E. (Eds.). (2012). Beyond the Visible: A handbook of best practice in plant UV photobiology (1st ed., p. xx + 174). Helsinki: University of Helsinki, Department of Biosciences, Division of Plant Biology. ISBN 978-952-10-8363-1 (PDF), 978-952-10-8362-4 (paperback). Open access PDF download available at doi:10.31885/9789521083631.

Aphalo, Pedro J. (2015) The r4photobiology suite. UV4Plants Bulletin, 2015:1, 21-29. doi:10.19232/uv4pb.2015.1.14.

Maia, R., Eliason, C. M., Bitton, P. P., Doucet, S. M., Shawkey, M. D. (2013) pavo: an R package for the analysis, visualization and organization of spectral data. Methods in Ecology and Evolution, 4(10):906-913. doi:10.1111/2041-210X.12069.

See Also

Useful links:

Examples

# irradiance of the whole spectrum
irrad(sun.spct)
# photon irradiance 400 nm to 700 nm
q_irrad(sun.spct, waveband(c(400,700)))
# energy irradiance 400 nm to 700 nm
e_irrad(sun.spct, waveband(c(400,700)))
# simulating the effect of a filter on solar irradiance
e_irrad(sun.spct * yellow_gel.spct, waveband(c(400,500)))
e_irrad(sun.spct * yellow_gel.spct, waveband(c(500,700)))
# daylength
sunrise_time(lubridate::today(tzone = "Europe/Helsinki"), tz = "Europe/Helsinki",
             geocode = data.frame(lat = 60, lon = 25),
             unit.out = "hour")
day_length(lubridate::today(tzone = "Europe/Helsinki"), tz = "Europe/Helsinki",
           geocode = data.frame(lat = 60, lon = 25),
           unit.out = "hour")
# colour as seen by humans
color_of(sun.spct)
color_of(sun.spct * yellow_gel.spct)
# filter transmittance
transmittance(yellow_gel.spct)
transmittance(yellow_gel.spct, waveband(c(400,500)))
transmittance(yellow_gel.spct, waveband(c(500,700)))

Arithmetic Operators

Description

Power operator for spectra.

Usage

## S3 method for class 'generic_spct'
e1 ^ e2

Arguments

e1

an object of class "generic_spct"

e2

a numeric vector. possibly of length one.

See Also

Other math operators and functions: MathFun, convolve_each(), div-.generic_spct, log(), minus-.generic_spct, mod-.generic_spct, plus-.generic_spct, round(), sign(), slash-.generic_spct, times-.generic_spct


CIE A illuminant data

Description

A dataset containing wavelengths at a 5 nm interval (300 nm to 830 nm) and the corresponding spectral energy irradiance normalized to 1 at 560 nm. Spectrum approximates typical, domestic, tungsten-filament lighting and 'corresponds' to a black body a 2856 K. CIE standard illuminant A is intended to represent typical, domestic, tungsten-filament lighting. Original data from CIE downloaded on 2024-11-30.

Usage

A.illuminant.spct

Format

A source spectrum with 531 rows and 2 variables.

  • w.length (nm)

  • s.e.irrad (rel. units)

Note

This and other CIE illuminant spectra can be downloaded from https://cie.co.at/data-tables as .CSV files.

Author(s)

CIE

References

CIE 2018, CIE standard illuminant A - 1 nm, International Commission on Illumination (CIE), Vienna, Austria, doi:10.25039/CIE.DS.8jsxjrsn.

See Also

Other Spectral data examples: D50.illuminant.spct, D65.illuminant.spct, Ler_leaf.spct, black_body.spct, ccd.spct, clear.spct, filter_cps.mspct, green_leaf.spct, phenylalanine.spct, photodiode.spct, sun.spct, sun_daily.spct, sun_evening.spct, two_filters.spct, two_sensors.mspct, water.spct, white_led.source_spct

Examples

A.illuminant.spct

Convert absorbance into transmittance

Description

Function that converts absorbance (a.u.) into transmittance (fraction).

Usage

A2T(x, action, byref, ...)

## Default S3 method:
A2T(x, action = NULL, byref = FALSE, ...)

## S3 method for class 'numeric'
A2T(x, action = NULL, byref = FALSE, ...)

## S3 method for class 'filter_spct'
A2T(x, action = "add", byref = FALSE, ...)

## S3 method for class 'filter_mspct'
A2T(x, action = "add", byref = FALSE, ..., .parallel = FALSE, .paropts = NULL)

Arguments

x

an R object.

action

a character string "add" or "replace".

byref

logical indicating if new object will be created by reference or by copy of x.

...

not used in current version.

.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 a column Tfr added and A and Afr possibly deleted except for w.length. If action = "replace", in all cases, the additional columns are removed, even if no column needs to be added.

Methods (by class)

  • A2T(default): Default method for generic function

  • A2T(numeric): method for numeric vectors

  • A2T(filter_spct): Method for filter spectra

  • A2T(filter_mspct): Method for collections of filter spectra

See Also

Other quantity conversion functions: Afr2T(), T2A(), T2Afr(), any2T(), as_quantum(), e2q(), e2qmol_multipliers(), e2quantum_multipliers(), q2e()


Absorbance

Description

Function to calculate the mean, total, or other summary of absorbance for spectral data stored in a filter_spct or in an object_spct.

Usage

absorbance(spct, w.band, quantity, wb.trim, use.hinges, ...)

## Default S3 method:
absorbance(spct, w.band, quantity, wb.trim, use.hinges, ...)

## S3 method for class 'filter_spct'
absorbance(
  spct,
  w.band = NULL,
  quantity = "average",
  wb.trim = getOption("photobiology.waveband.trim", default = TRUE),
  use.hinges = NULL,
  naming = "default",
  ...
)

## S3 method for class 'object_spct'
absorbance(
  spct,
  w.band = NULL,
  quantity = "average",
  wb.trim = getOption("photobiology.waveband.trim", default = TRUE),
  use.hinges = NULL,
  naming = "default",
  ...
)

## S3 method for class 'filter_mspct'
absorbance(
  spct,
  w.band = NULL,
  quantity = "average",
  wb.trim = getOption("photobiology.waveband.trim", default = TRUE),
  use.hinges = NULL,
  naming = "default",
  ...,
  attr2tb = NULL,
  idx = "spct.idx",
  .parallel = FALSE,
  .paropts = NULL
)

## S3 method for class 'object_mspct'
absorbance(
  spct,
  w.band = NULL,
  quantity = "average",
  wb.trim = getOption("photobiology.waveband.trim", default = TRUE),
  use.hinges = NULL,
  naming = "default",
  ...,
  attr2tb = NULL,
  idx = "spct.idx",
  .parallel = FALSE,
  .paropts = NULL
)

Arguments

spct

an R object.

w.band

waveband or list of waveband objects or a numeric vector of length two. The waveband(s) determine the region(s) of the spectrum that are summarized. If a numeric range is supplied a waveband object is constructed on the fly from it.

quantity

character string One of "average" or "mean", "total", "contribution", "contribution.pc", "relative" or "relative.pc".

wb.trim

logical if TRUE wavebands crossing spectral data boundaries are trimmed, if FALSE, they are discarded.

use.hinges

logical Flag indicating whether to insert "hinges" into the spectral data before integration so as to reduce interpolation errors at the boundaries of the wavebands.

...

other arguments (possibly used by derived methods).

naming

character one of "long", "default", "short" or "none". Used to select the type of names to assign to returned value.

attr2tb

character vector, see add_attr2tb for the syntax for attr2tb passed as is to formal parameter col.names.

idx

character Name of the column with the names of the members of the collection of spectra.

.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 named numeric vector in the case of methods for individual spectra, with one value for each waveband passed to parameter w.band. A data.frame in the case of collections of spectra, containing one column for each waveband object, an index column with the names of the spectra, and optionally additional columns with metadata values retrieved from the attributes of the member spectra.

By default values are only integrated, but depending on the argument passed to parameter quantity they can be re-expressed as relative fractions or percentages. In the case of vector output, names attribute is set to the name of the corresponding waveband unless a named list is supplied in which case the names of the list members are used.

Methods (by class)

  • absorbance(default): Default for generic function

  • absorbance(filter_spct): Specialization for filter spectra

  • absorbance(object_spct): Specialization for object spectra

  • absorbance(filter_mspct): Calculates absorbance from a filter_mspct

  • absorbance(object_mspct): Calculates absorbance from a object_mspct

Note

The use.hinges parameter controls speed optimization. The defaults should be suitable in most cases. Only the range of wavelengths in the wavebands is used and all BSWFs are ignored.

Examples

absorbance(polyester.spct, new_waveband(400,700))
absorbance(yellow_gel.spct, new_waveband(400,700))
absorbance(yellow_gel.spct, split_bands(c(400,700), length.out = 3))
absorbance(yellow_gel.spct, split_bands(c(400,700), length.out = 3),
        quantity = "average")
absorbance(yellow_gel.spct, split_bands(c(400,700), length.out = 3),
        quantity = "total")
absorbance(yellow_gel.spct, split_bands(c(400,700), length.out = 3),
        quantity = "relative")
absorbance(yellow_gel.spct, split_bands(c(400,700), length.out = 3),
        quantity = "relative.pc")
absorbance(yellow_gel.spct, split_bands(c(400,700), length.out = 3),
        quantity = "contribution")
absorbance(yellow_gel.spct, split_bands(c(400,700), length.out = 3),
        quantity = "contribution.pc")

Absorptance

Description

Function to calculate the mean, total, or other summary of absorptance for spectral data stored in a filter_spct or in an object_spct. Absorptance is a different quantity than absorbance.

Usage

absorptance(spct, w.band, quantity, wb.trim, use.hinges, ...)

## Default S3 method:
absorptance(spct, w.band, quantity, wb.trim, use.hinges, ...)

## S3 method for class 'filter_spct'
absorptance(
  spct,
  w.band = NULL,
  quantity = "average",
  wb.trim = getOption("photobiology.waveband.trim", default = TRUE),
  use.hinges = NULL,
  naming = "default",
  ...
)

## S3 method for class 'object_spct'
absorptance(
  spct,
  w.band = NULL,
  quantity = "average",
  wb.trim = getOption("photobiology.waveband.trim", default = TRUE),
  use.hinges = NULL,
  naming = "default",
  ...
)

## S3 method for class 'filter_mspct'
absorptance(
  spct,
  w.band = NULL,
  quantity = "average",
  wb.trim = getOption("photobiology.waveband.trim", default = TRUE),
  use.hinges = NULL,
  naming = "default",
  ...,
  attr2tb = NULL,
  idx = "spct.idx"
)

## S3 method for class 'object_mspct'
absorptance(
  spct,
  w.band = NULL,
  quantity = "average",
  wb.trim = getOption("photobiology.waveband.trim", default = TRUE),
  use.hinges = NULL,
  naming = "default",
  ...,
  attr2tb = NULL,
  idx = "spct.idx",
  .parallel = FALSE,
  .paropts = NULL
)

Arguments

spct

an R object.

w.band

waveband or list of waveband objects or a numeric vector of length two. The waveband(s) determine the region(s) of the spectrum that are summarized. If a numeric range is supplied a waveband object is constructed on the fly from it.

quantity

character string One of "average" or "mean", "total", "contribution", "contribution.pc", "relative" or "relative.pc".

wb.trim

logical if TRUE wavebands crossing spectral data boundaries are trimmed, if FALSE, they are discarded.

use.hinges

logical Flag indicating whether to insert "hinges" into the spectral data before integration so as to reduce interpolation errors at the boundaries of the wavebands.

...

other arguments (possibly used by derived methods).

naming

character one of "long", "default", "short" or "none". Used to select the type of names to assign to returned value.

attr2tb

character vector, see add_attr2tb for the syntax for attr2tb passed as is to formal parameter col.names.

idx

character Name of the column with the names of the members of the collection of spectra.

.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 named numeric vector in the case of methods for individual spectra, with one value for each waveband passed to parameter w.band. A data.frame in the case of collections of spectra, containing one column for each waveband object, an index column with the names of the spectra, and optionally additional columns with metadata values retrieved from the attributes of the member spectra.

By default values are only integrated, but depending on the argument passed to parameter quantity they can be re-expressed as relative fractions or percentages. In the case of vector output, names attribute is set to the name of the corresponding waveband unless a named list is supplied in which case the names of the list members are used.

Methods (by class)

  • absorptance(default): Default for generic function

  • absorptance(filter_spct): Specialization for filter spectra

  • absorptance(object_spct): Specialization for object spectra

  • absorptance(filter_mspct): Calculates absorptance from a filter_mspct

  • absorptance(object_mspct): Calculates absorptance from a object_mspct

Note

The use.hinges parameter controls speed optimization. The defaults should be suitable in most cases. Only the range of wavelengths in the wavebands is used and all BSWFs are ignored.

Examples

absorptance(black_body.spct, new_waveband(400,500))
absorptance(white_body.spct, new_waveband(300,400))
absorptance(black_body.spct, split_bands(c(400,700), length.out = 3))
absorptance(black_body.spct, split_bands(c(400,700), length.out = 3),
        quantity = "average")
absorptance(black_body.spct, split_bands(c(400,700), length.out = 3),
        quantity = "total")
absorptance(black_body.spct, split_bands(c(400,700), length.out = 3),
        quantity = "relative")
absorptance(black_body.spct, split_bands(c(400,700), length.out = 3),
        quantity = "relative.pc")
absorptance(black_body.spct, split_bands(c(400,700), length.out = 3),
        quantity = "contribution")
absorptance(black_body.spct, split_bands(c(400,700), length.out = 3),
        quantity = "contribution.pc")

Copy attributes from members of a generic_mspct

Description

Copy metadata attributes from members of a generic_mspct object into a tibble or data.frame.

Usage

add_attr2tb(
  tb = NULL,
  mspct,
  col.names = NULL,
  idx = "spct.idx",
  unnest = FALSE
)

when_measured2tb(mspct, tb = NULL, col.names = "when.measured", idx = NULL)

geocode2tb(mspct, tb = NULL, col.names = "geocode", idx = "spct.idx")

lonlat2tb(mspct, tb = NULL, col.names = c("lon", "lat"), idx = "spct.idx")

lon2tb(mspct, tb = NULL, col.names = "lon", idx = "spct.idx")

lat2tb(mspct, tb = NULL, col.names = "lat", idx = "spct.idx")

address2tb(mspct, tb = NULL, col.names = "address", idx = "spct.idx")

what_measured2tb(
  mspct,
  tb = NULL,
  col.names = "what.measured",
  idx = "spct.idx"
)

how_measured2tb(mspct, tb = NULL, col.names = "how.measured", idx = "spct.idx")

normalized2tb(mspct, tb = NULL, col.names = "normalized", idx = "spct.idx")

scaled2tb(mspct, tb = NULL, col.names = "scaled", idx = "spct.idx")

instr_desc2tb(mspct, tb = NULL, col.names = "instr.desc", idx = "spct.idx")

instr_settings2tb(
  mspct,
  tb = NULL,
  col.names = "instr.settings",
  idx = "spct.idx"
)

BSWF_used2tb(mspct, tb = NULL, col.names = "BSWF.used", idx = "spct.idx")

filter_properties2tb(
  mspct,
  tb = NULL,
  col.names = "filter.properties",
  idx = "spct.idx"
)

solute_properties2tb(
  mspct,
  tb = NULL,
  col.names = "solute.properties",
  idx = "spct.idx"
)

Tfr_type2tb(mspct, tb = NULL, col.names = "Tfr.type", idx = "spct.idx")

Rfr_type2tb(mspct, tb = NULL, col.names = "Rfr.type", idx = "spct.idx")

time_unit2tb(mspct, tb = NULL, col.names = "time.unit", idx = "spct.idx")

comment2tb(mspct, tb = NULL, col.names = "comment", idx = "spct.idx")

Arguments

tb

tibble or data.frame to which to add the data (optional).

mspct

generic_mspct Any collection of spectra.

col.names

named character vector Name(s) of metadata attributes to copy, while if named, the names provide the name for the column.

idx

character Name of the column with the names of the members of the collection of spectra.

unnest

logical Flag controlling if metadata attributes that are lists of values should be returned in a list column or in separate columns.

Details

The attributes are copied to a column in a tibble or data frame. If the tb formal parameter receives NULL as argument, a new tibble will be created. If an existing data.frame or tibble is passed as argument, new columns are added to it. However, the number of rows in the argument passed to tb must match the number of spectra in the argument passed to mspct. Only in the case of method add_attr2tb() if the argument to col.names is a named vector, the names of members are used as names for the columns created. This permits setting any valid name for the new columns. If the vector passed to col.names has no names the names of the attributes are used for the new columns. If the fields of the attributes are unnested their names are used as names for the columns.

Valid accepted as argument to col.names are NULL, "lon", "lat", "address", "geocode", "where.measured", "when.measured", "what.measured", "how.measured", "comment", "normalised", "normalized", "scaled", "bswf.used", "instr.desc", "instr.settings", solute.properties, "filter.properties", "Tfr.type", "Rfr.type", "time.unit".

Value

A tibble With the metadata attributes in separate new variables.

Note

The order of the first two arguments is reversed in add_attr2tb() compared to the other functions. This is to allow its use in 'pipes', while the functions for single attributes are expected to be used mostly to create new tibbles.

See Also

Other measurement metadata functions: getFilterProperties(), getHowMeasured(), getInstrDesc(), getInstrSettings(), getSoluteProperties(), getWhatMeasured(), getWhenMeasured(), getWhereMeasured(), get_attributes(), isValidInstrDesc(), isValidInstrSettings(), select_spct_attributes(), setFilterProperties(), setHowMeasured(), setInstrDesc(), setInstrSettings(), setSoluteProperties(), setWhatMeasured(), setWhenMeasured(), setWhereMeasured(), spct_attr2tb(), spct_metadata(), subset_attributes(), trimInstrDesc(), trimInstrSettings()

Examples

library(dplyr)

my.mspct <- source_mspct(list(sun1 = sun.spct, sun2 = sun.spct * 2))
q_irrad(my.mspct) %>%
  add_attr2tb(my.mspct, c(lat = "latitude",
                          lon = "longitude",
                          when.measured = "time"))

when_measured2tb(my.mspct)

Convert transmittance into absorptance.

Description

Function that converts transmittance (fraction) into absorptance (fraction). If reflectance (fraction) is available, it allows conversions between internal and total absorptance.

Usage

Afr2T(x, action, byref, clean, ...)

## Default S3 method:
Afr2T(x, action = NULL, byref = FALSE, clean = FALSE, ...)

## S3 method for class 'numeric'
Afr2T(x, action = NULL, byref = FALSE, clean = FALSE, Rfr = NA_real_, ...)

## S3 method for class 'filter_spct'
Afr2T(x, action = "add", byref = FALSE, clean = FALSE, ...)

## S3 method for class 'object_spct'
Afr2T(x, action = "add", byref = FALSE, clean = FALSE, ...)

## S3 method for class 'filter_mspct'
Afr2T(
  x,
  action = "add",
  byref = FALSE,
  clean = FALSE,
  ...,
  .parallel = FALSE,
  .paropts = NULL
)

## S3 method for class 'object_mspct'
Afr2T(
  x,
  action = "add",
  byref = FALSE,
  clean = FALSE,
  ...,
  .parallel = FALSE,
  .paropts = NULL
)

Arguments

x

an R object

action

character Allowed values "replace" and "add"

byref

logical indicating if new object will be created by reference or by copy of x

clean

logical replace off-boundary values before conversion

...

not used in current version

Rfr

numeric vector. Spectral reflectance o reflectance factor. Set to zero if x is internal reflectance,

.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 a column Tfr added and other columns possibly deleted except for w.length. If action = "replace", in all cases, the additional columns are removed, even if no column needs to be added.

Methods (by class)

  • Afr2T(default): Default method for generic function

  • Afr2T(numeric): Default method for generic function

  • Afr2T(filter_spct): Method for filter spectra

  • Afr2T(object_spct): Method for object spectra

  • Afr2T(filter_mspct): Method for collections of filter spectra

  • Afr2T(object_mspct): Method for collections of object spectra

See Also

Other quantity conversion functions: A2T(), T2A(), T2Afr(), any2T(), as_quantum(), e2q(), e2qmol_multipliers(), e2quantum_multipliers(), q2e()

Examples

T2Afr(Ler_leaf.spct)

Convert filter quantities.

Description

Functions that convert or add related physical quantities to filter_spct or object_spct objects. transmittance (fraction) into absorptance (fraction).

Usage

any2T(x, action = "add", clean = FALSE)

any2A(x, action = "add", clean = FALSE)

any2Afr(x, action = "add", clean = FALSE)

Arguments

x

an filter_spct or a filter_mspct object.

action

character Allowed values "replace" and "add".

clean

logical replace off-boundary values before conversion

Details

These functions are dispatchers for A2T, Afr2T, T2A, and T2Afr. The dispatch is based on the names of the variables stored in x. They do not support in-place modification of x.

Value

A copy of x with the columns for the different quantities added or replaced. If action = "replace", in all cases, the additional columns are removed, even if no column needs to be added.

See Also

Other quantity conversion functions: A2T(), Afr2T(), T2A(), T2Afr(), as_quantum(), e2q(), e2qmol_multipliers(), e2quantum_multipliers(), q2e()

Examples

any2Afr(Ler_leaf.spct)
any2T(Ler_leaf.spct)
any2T(polyester.spct)

Convert spectral photon irradiance into spectral energy irradiance

Description

Convert a spectral photon irradiance [mols1m2nm1mol\,s^{-1}\,m^{-2}\,nm^{-1}] into a spectral energy irradiance [Wm2nm1W\,m^{-2}\,nm^{-1}].

Usage

as_energy(w.length, s.qmol.irrad)

Arguments

w.length

numeric vector of wavelengths [nmnm]).

s.qmol.irrad

numeric vector of spectral photon irradiance values.

Value

A numeric vector of spectral (energy) irradiances.

See Also

Other low-level functions operating on numeric vectors.: as_quantum_mol(), calc_multipliers(), div_spectra(), energy_irradiance(), energy_ratio(), insert_hinges(), integrate_xy(), interpolate_spectrum(), irradiance(), l_insert_hinges(), oper_spectra(), photon_irradiance(), photon_ratio(), photons_energy_ratio(), prod_spectra(), s_e_irrad2rgb(), split_energy_irradiance(), split_photon_irradiance(), subt_spectra(), sum_spectra(), trim_tails(), v_insert_hinges(), v_replace_hinges()

Examples

with(sun.spct, as_energy(w.length, s.q.irrad))

Convert spectral energy irradiance into spectral photon irradiance

Description

Convert spectral energy irradiance [W m-2 nm-1] into spectral photon irradiance expressed as number of photons [s-1 m-2 nm-1]

Usage

as_quantum(w.length, s.e.irrad)

Arguments

w.length

numeric vector of wavelengths (nm).

s.e.irrad

numeric vector of spectral (energy) irradiance values.

Value

A numeric vector of spectral photon irradiances.

See Also

Other quantity conversion functions: A2T(), Afr2T(), T2A(), T2Afr(), any2T(), e2q(), e2qmol_multipliers(), e2quantum_multipliers(), q2e()

Examples

with(sun.data, as_quantum(w.length, s.e.irrad))

Convert spectral energy irradiance into spectral photon irradiance

Description

Convert spectral energy irradiance [Wm2nm1W\,m^{-2}\,nm^{-1}] into a spectral photon irradiance expressed in number of molds of photons [mols1m2nm1mol\,s^{-1}\,m^{-2}\,nm^{-1}].

Usage

as_quantum_mol(w.length, s.e.irrad)

Arguments

w.length

numeric vector of wavelengths (nm).

s.e.irrad

numeric vector of spectral (energy) irradiance values.

Value

a numeric vector of spectral photon irradiances.

See Also

Other low-level functions operating on numeric vectors.: as_energy(), calc_multipliers(), div_spectra(), energy_irradiance(), energy_ratio(), insert_hinges(), integrate_xy(), interpolate_spectrum(), irradiance(), l_insert_hinges(), oper_spectra(), photon_irradiance(), photon_ratio(), photons_energy_ratio(), prod_spectra(), s_e_irrad2rgb(), split_energy_irradiance(), split_photon_irradiance(), subt_spectra(), sum_spectra(), trim_tails(), v_insert_hinges(), v_replace_hinges()

Examples

with(sun.data, as_quantum_mol(w.length, s.e.irrad))

Coerce to a collection-of-spectra

Description

Return a copy of an R object with its class set to a given type of spectrum.

Usage

as.calibration_mspct(x, ...)

## Default S3 method:
as.calibration_mspct(x, ...)

## S3 method for class 'data.frame'
as.calibration_mspct(x, ...)

## S3 method for class 'calibration_spct'
as.calibration_mspct(x, ...)

## S3 method for class 'list'
as.calibration_mspct(x, ..., ncol = 1, byrow = FALSE)

## S3 method for class 'matrix'
as.calibration_mspct(
  x,
  w.length,
  spct.data.var = "irrad.mult",
  multiplier = 1,
  byrow = NULL,
  spct.names = "spct_",
  ...
)

Arguments

x

a list of spectral objects or a list of objects such as data frames that can be converted into spectral objects.

...

passed to individual spectrum object constructor

ncol

integer Number of 'virtual' columns in data

byrow

logical If ncol > 1 how to read in the data

w.length

numeric A vector of wavelengthvalues sorted in strictly ascending order (nm).

spct.data.var

character The name of the variable that will contain the spectral data. This indicates what physical quantity is stored in the matrix and the units of expression used.

multiplier

numeric A multiplier to be applied to the values in x to do unit or scale conversion.

spct.names

character Vector of names to be assigned to collection members, either of length 1, or with length equal to the number of spectra.

Value

A copy of x converted into a calibration_mspctt object.

Methods (by class)

  • as.calibration_mspct(default):

  • as.calibration_mspct(data.frame):

  • as.calibration_mspct(calibration_spct):

  • as.calibration_mspct(list):

  • as.calibration_mspct(matrix):

Note

When x is a square matrix an explicit argument is needed for byrow to indicate how data in x should be read. In every case the length of the w.length vector must match one of the dimensions of x.

See Also

Other Coercion methods for collections of spectra: as.chroma_mspct(), as.cps_mspct(), as.filter_mspct(), as.generic_mspct(), as.object_mspct(), as.raw_mspct(), as.reflector_mspct(), as.response_mspct(), as.solute_mspct(), as.source_mspct(), split2mspct(), subset2mspct()


Coerce to a spectrum

Description

Return a copy of an R object with its class set to a given type of spectrum.

Usage

as.calibration_spct(x, ...)

## Default S3 method:
as.calibration_spct(x, ...)

Arguments

x

an R object.

...

other arguments passed to "set" functions.

Value

A copy of x converted into a calibration_spct object.

Methods (by class)

  • as.calibration_spct(default):

See Also

setGenericSpct

Other constructors of spectral objects: as.chroma_spct(), as.cps_spct(), as.filter_spct(), as.generic_spct(), as.object_spct(), as.raw_spct(), as.reflector_spct(), as.response_spct(), as.solute_spct(), as.source_spct(), source_spct()


Coerce to a collection-of-spectra

Description

Return a copy of an R object with its class set to a given type of spectrum.

Usage

as.chroma_mspct(x, ...)

## Default S3 method:
as.chroma_mspct(x, ...)

## S3 method for class 'data.frame'
as.chroma_mspct(x, ...)

## S3 method for class 'chroma_spct'
as.chroma_mspct(x, ...)

## S3 method for class 'list'
as.chroma_mspct(x, ..., ncol = 1, byrow = FALSE)

Arguments

x

a list of spectral objects or a list of objects such as data frames that can be converted into spectral objects.

...

passed to individual spectrum object constructor

ncol

integer Number of 'virtual' columns in data

byrow

logical If ncol > 1 how to read in the data

Value

A copy of x converted into a chroma_mspct object.

Methods (by class)

  • as.chroma_mspct(default):

  • as.chroma_mspct(data.frame):

  • as.chroma_mspct(chroma_spct):

  • as.chroma_mspct(list):

See Also

Other Coercion methods for collections of spectra: as.calibration_mspct(), as.cps_mspct(), as.filter_mspct(), as.generic_mspct(), as.object_mspct(), as.raw_mspct(), as.reflector_mspct(), as.response_mspct(), as.solute_mspct(), as.source_mspct(), split2mspct(), subset2mspct()


Coerce to a spectrum

Description

Return a copy of an R object with its class set to a given type of spectrum.

Usage

as.chroma_spct(x, ...)

## Default S3 method:
as.chroma_spct(x, ...)

Arguments

x

an R object.

...

other arguments passed to "set" functions.

Value

A copy of x converted into a chroma_spct object.

Methods (by class)

  • as.chroma_spct(default):

See Also

setGenericSpct

Other constructors of spectral objects: as.calibration_spct(), as.cps_spct(), as.filter_spct(), as.generic_spct(), as.object_spct(), as.raw_spct(), as.reflector_spct(), as.response_spct(), as.solute_spct(), as.source_spct(), source_spct()


Coerce to a collection-of-spectra

Description

Return a copy of an R object with its class set to a given type of spectrum.

Usage

as.cps_mspct(x, ...)

## Default S3 method:
as.cps_mspct(x, ...)

## S3 method for class 'data.frame'
as.cps_mspct(x, ...)

## S3 method for class 'cps_spct'
as.cps_mspct(x, ...)

## S3 method for class 'list'
as.cps_mspct(x, ..., ncol = 1, byrow = FALSE)

## S3 method for class 'matrix'
as.cps_mspct(
  x,
  w.length,
  spct.data.var = "cps",
  multiplier = 1,
  byrow = NULL,
  spct.names = "spct_",
  ...
)

Arguments

x

a list of spectral objects or a list of objects such as data frames that can be converted into spectral objects.

...

passed to individual spectrum object constructor

ncol

integer Number of 'virtual' columns in data

byrow

logical If ncol > 1 how to read in the data

w.length

numeric A vector of wavelengthvalues sorted in strictly ascending order (nm).

spct.data.var

character The name of the variable that will contain the spectral data. This indicates what physical quantity is stored in the matrix and the units of expression used.

multiplier

numeric A multiplier to be applied to the values in x to do unit or scale conversion.

spct.names

character Vector of names to be assigned to collection members, either of length 1, or with length equal to the number of spectra.

Value

A copy of x converted into a cps_mspct object.

Methods (by class)

  • as.cps_mspct(default):

  • as.cps_mspct(data.frame):

  • as.cps_mspct(cps_spct):

  • as.cps_mspct(list):

  • as.cps_mspct(matrix):

Note

When x is a square matrix an explicit argument is needed for byrow to indicate how data in x should be read. In every case the length of the w.length vector must match one of the dimensions of x.

See Also

Other Coercion methods for collections of spectra: as.calibration_mspct(), as.chroma_mspct(), as.filter_mspct(), as.generic_mspct(), as.object_mspct(), as.raw_mspct(), as.reflector_mspct(), as.response_mspct(), as.solute_mspct(), as.source_mspct(), split2mspct(), subset2mspct()


Coerce to a spectrum

Description

Return a copy of an R object with its class set to a given type of spectrum.

Usage

as.cps_spct(x, ...)

## Default S3 method:
as.cps_spct(x, ...)

Arguments

x

an R object.

...

other arguments passed to "set" functions.

Value

A copy of x converted into a cps_spct object.

Methods (by class)

  • as.cps_spct(default):

See Also

setGenericSpct

Other constructors of spectral objects: as.calibration_spct(), as.chroma_spct(), as.filter_spct(), as.generic_spct(), as.object_spct(), as.raw_spct(), as.reflector_spct(), as.response_spct(), as.solute_spct(), as.source_spct(), source_spct()


Coerce to a collection-of-spectra

Description

Return a copy of an R object with its class set to a given type of spectrum.

Usage

as.filter_mspct(x, ...)

## Default S3 method:
as.filter_mspct(x, ...)

## S3 method for class 'data.frame'
as.filter_mspct(x, Tfr.type = c("total", "internal"), strict.range = TRUE, ...)

## S3 method for class 'filter_spct'
as.filter_mspct(x, ...)

## S3 method for class 'list'
as.filter_mspct(
  x,
  Tfr.type = c("total", "internal"),
  strict.range = TRUE,
  ...,
  ncol = 1,
  byrow = FALSE
)

## S3 method for class 'matrix'
as.filter_mspct(
  x,
  w.length,
  spct.data.var = "Tfr",
  multiplier = 1,
  byrow = NULL,
  spct.names = "spct_",
  ...
)

Arguments

x

a list of spectral objects or a list of objects such as data frames that can be converted into spectral objects.

...

passed to individual spectrum object constructor

Tfr.type

a character string, either "total" or "internal"

strict.range

logical Flag indicating how off-range values are handled

ncol

integer Number of 'virtual' columns in data

byrow

logical If ncol > 1 how to read in the data

w.length

numeric A vector of wavelengthvalues sorted in strictly ascending order (nm).

spct.data.var

character The name of the variable that will contain the spectral data. This indicates what physical quantity is stored in the matrix and the units of expression used.

multiplier

numeric A multiplier to be applied to the values in x to do unit or scale conversion.

spct.names

character Vector of names to be assigned to collection members, either of length 1, or with length equal to the number of spectra.

Value

A copy of x converted into a filter_mspct object.

Methods (by class)

  • as.filter_mspct(default):

  • as.filter_mspct(data.frame):

  • as.filter_mspct(filter_spct):

  • as.filter_mspct(list):

  • as.filter_mspct(matrix):

Note

When x is a square matrix an explicit argument is needed for byrow to indicate how data in x should be read. In every case the length of the w.length vector must match one of the dimensions of x.

See Also

Other Coercion methods for collections of spectra: as.calibration_mspct(), as.chroma_mspct(), as.cps_mspct(), as.generic_mspct(), as.object_mspct(), as.raw_mspct(), as.reflector_mspct(), as.response_mspct(), as.solute_mspct(), as.source_mspct(), split2mspct(), subset2mspct()


Coerce or convert into a filter spectrum

Description

Return a possibly modified copy of an R object with its class set to a filter spectrum. In the case of conversion from a solute_spct object, compute the spectral quantity based on additional input from user.

Usage

as.filter_spct(x, ...)

## Default S3 method:
as.filter_spct(
  x,
  Tfr.type = c("total", "internal"),
  strict.range = getOption("photobiology.strict.range", default = FALSE),
  ...
)

## S3 method for class 'solute_spct'
as.filter_spct(
  x,
  Tfr.type = "internal",
  strict.range = getOption("photobiology.strict.range", default = FALSE),
  Rfr.constant = NA_real_,
  comment = NULL,
  molar.concentration = NULL,
  mass.concentration = NULL,
  path.length = 1,
  ...
)

Arguments

x

an R object.

...

other arguments passed to "set" functions.

Tfr.type

a character string, either "total" or "internal".

strict.range

logical Flag indicating whether off-range values result in an error instead of a warning.

Rfr.constant

numeric The value of the reflection factor (/1) to be set.

comment

character A string to be added as a comment attribute to the object created. If not supplied, the comment will be copied from x.

molar.concentration, mass.concentration

numeric Concentration to be used to compute transmittance of the solute in solution [molm3=mmoldm3mol\,m^{-3} = mmol\,dm^{-3} or kgm3=gdm3kg\,m^{-3} = g\,dm^{-3}, respectively].

path.length

numeric The length of the light path (mm) used to compute transmittance of the solute in a solution.

Value

A copy of x converted into a filter_spct. object.

Methods (by class)

  • as.filter_spct(default):

  • as.filter_spct(solute_spct):

See Also

setGenericSpct

Other constructors of spectral objects: as.calibration_spct(), as.chroma_spct(), as.cps_spct(), as.generic_spct(), as.object_spct(), as.raw_spct(), as.reflector_spct(), as.response_spct(), as.solute_spct(), as.source_spct(), source_spct()


Coerce to a collection-of-spectra

Description

Return a copy of an R object with its class set to a given type of spectrum.

Usage

as.generic_mspct(x, ...)

## Default S3 method:
as.generic_mspct(x, ...)

## S3 method for class 'data.frame'
as.generic_mspct(x, force.spct.class = FALSE, ...)

## S3 method for class 'generic_spct'
as.generic_mspct(x, force.spct.class = FALSE, ...)

## S3 method for class 'list'
as.generic_mspct(x, force.spct.class = FALSE, ..., ncol = 1, byrow = FALSE)

## S3 method for class 'matrix'
as.generic_mspct(
  x,
  w.length,
  member.class,
  spct.data.var,
  multiplier = 1,
  byrow = NULL,
  spct.names = "spct_",
  ...
)

mat2mspct(
  x,
  w.length,
  member.class,
  spct.data.var,
  multiplier = 1,
  byrow = NULL,
  spct.names = "spct_",
  ...
)

Arguments

x

a list of spectral objects or a list of objects such as data frames that can be converted into spectral objects.

...

passed to individual spectrum object constructor

force.spct.class

logical indicating whether to change the class of members to generic_spct or retain the existing class.

ncol

integer Number of 'virtual' columns in data

byrow

logical If ncol > 1 how to read in the data

w.length

numeric A vector of wavelengthvalues sorted in strictly ascending order (nm).

member.class

character The name of the class of the individual spectra to be constructed.

spct.data.var

character The name of the variable that will contain the spectral data. This indicates what physical quantity is stored in the matrix and the units of expression used.

multiplier

numeric A multiplier to be applied to the values in x to do unit or scale conversion.

spct.names

character Vector of names to be assigned to collection members, either of length 1, or with length equal to the number of spectra.

Value

A copy of x converted into a generic_mspct object.

Methods (by class)

  • as.generic_mspct(default):

  • as.generic_mspct(data.frame):

  • as.generic_mspct(generic_spct):

  • as.generic_mspct(list):

  • as.generic_mspct(matrix):

Note

Members of generic_mspct objects can be heterogeneous: they can belong to any class derived from generic_spct and class is not enforced. When x is a list of data frames force.spct.class = TRUE needs to be supplied. When x is a square matrix an explicit argument is needed for byrow to indicate how data in x should be read. In every case the length of the w.length vector must match one of the dimensions of x.

See Also

Other Coercion methods for collections of spectra: as.calibration_mspct(), as.chroma_mspct(), as.cps_mspct(), as.filter_mspct(), as.object_mspct(), as.raw_mspct(), as.reflector_mspct(), as.response_mspct(), as.solute_mspct(), as.source_mspct(), split2mspct(), subset2mspct()


Coerce to a spectrum

Description

Return a copy of an R object with its class set to a given type of spectrum.

Usage

as.generic_spct(x, ...)

## Default S3 method:
as.generic_spct(x, ...)

Arguments

x

an R object

...

other arguments passed to "set" functions

Value

A copy of x converted into a generic_spct object.

Methods (by class)

  • as.generic_spct(default):

See Also

setGenericSpct

Other constructors of spectral objects: as.calibration_spct(), as.chroma_spct(), as.cps_spct(), as.filter_spct(), as.object_spct(), as.raw_spct(), as.reflector_spct(), as.response_spct(), as.solute_spct(), as.source_spct(), source_spct()


Coerce a collection of spectra into a matrix

Description

Convert an object of class generic_mspct or a derived class into an R matrix with wavelengths saved as an attribute and spectral data in rows or columns.

Usage

## S3 method for class 'generic_mspct'
as.matrix(x, spct.data.var, byrow = attr(x, "mspct.byrow"), ...)

mspct2mat(x, spct.data.var, byrow = attr(x, "mspct.byrow"), ...)

Arguments

x

generic_mspct object.

spct.data.var

character The name of the variable containing the spectral data.

byrow

logical. If FALSE (the default) the matrix is filled with the spectra stored by columns, otherwise the matrix is filled by rows.

...

currently ignored.

Warning!

This conversion preserves the spectral data but discards almost all the metadata contained in the spectral objects. In other words a matrix created with this function cannot be used to recreate the original object unless the same metadata is explicitly supplied when converting the matrix into new collection of spectra.

Note

Only collections of spectra containing spectra with exactly the same w.length values can by converted. If needed, the spectra can be re-expressed before attempting the conversion to a matrix.


Coerce to a collection-of-spectra

Description

Return a copy of an R object with its class set to a given type of spectrum.

Usage

as.object_mspct(x, ...)

## Default S3 method:
as.object_mspct(x, ...)

## S3 method for class 'data.frame'
as.object_mspct(
  x,
  Tfr.type = c("total", "internal"),
  Rfr.type = c("total", "specular"),
  strict.range = TRUE,
  ...
)

## S3 method for class 'object_spct'
as.object_mspct(x, ...)

## S3 method for class 'list'
as.object_mspct(
  x,
  Tfr.type = c("total", "internal"),
  Rfr.type = c("total", "specular"),
  strict.range = TRUE,
  ...,
  ncol = 1,
  byrow = FALSE
)

Arguments

x

a list of spectral objects or a list of objects such as data frames that can be converted into spectral objects.

...

passed to individual spectrum object constructor

Tfr.type

a character string, either "total" or "internal"

Rfr.type

a character string, either "total" or "specular"

strict.range

logical Flag indicating how off-range values are handled

ncol

integer Number of 'virtual' columns in data

byrow

logical If ncol > 1 how to read in the data

Value

A copy of x converted into a object_mspct object.

Methods (by class)

  • as.object_mspct(default):

  • as.object_mspct(data.frame):

  • as.object_mspct(object_spct):

  • as.object_mspct(list):

See Also

Other Coercion methods for collections of spectra: as.calibration_mspct(), as.chroma_mspct(), as.cps_mspct(), as.filter_mspct(), as.generic_mspct(), as.raw_mspct(), as.reflector_mspct(), as.response_mspct(), as.solute_mspct(), as.source_mspct(), split2mspct(), subset2mspct()


Coerce to a spectrum

Description

Return a copy of an R object with its class set to a given type of spectrum.

Usage

as.object_spct(x, ...)

## Default S3 method:
as.object_spct(
  x,
  Tfr.type = c("total", "internal"),
  Rfr.type = c("total", "specular"),
  strict.range = getOption("photobiology.strict.range", default = FALSE),
  ...
)

Arguments

x

an R object.

...

other arguments passed to "set" functions.

Tfr.type

a character string, either "total" or "internal".

Rfr.type

a character string, either "total" or "specular".

strict.range

logical Flag indicating whether off-range values result in an error instead of a warning.

Value

A copy of x converted into a object_spct object.

Methods (by class)

  • as.object_spct(default):

See Also

setGenericSpct

Other constructors of spectral objects: as.calibration_spct(), as.chroma_spct(), as.cps_spct(), as.filter_spct(), as.generic_spct(), as.raw_spct(), as.reflector_spct(), as.response_spct(), as.solute_spct(), as.source_spct(), source_spct()


Coerce to a collection-of-spectra

Description

Return a copy of an R object with its class set to a given type of spectrum.

Usage

as.raw_mspct(x, ...)

## Default S3 method:
as.raw_mspct(x, ...)

## S3 method for class 'data.frame'
as.raw_mspct(x, ...)

## S3 method for class 'raw_spct'
as.raw_mspct(x, ...)

## S3 method for class 'list'
as.raw_mspct(x, ..., ncol = 1, byrow = FALSE)

## S3 method for class 'matrix'
as.raw_mspct(
  x,
  w.length,
  spct.data.var = "counts",
  multiplier = 1,
  byrow = NULL,
  spct.names = "spct_",
  ...
)

Arguments

x

a list of spectral objects or a list of objects such as data frames that can be converted into spectral objects.

...

passed to individual spectrum object constructor

ncol

integer Number of 'virtual' columns in data

byrow

logical If ncol > 1 how to read in the data

w.length

numeric A vector of wavelengthvalues sorted in strictly ascending order (nm).

spct.data.var

character The name of the variable that will contain the spectral data. This indicates what physical quantity is stored in the matrix and the units of expression used.

multiplier

numeric A multiplier to be applied to the values in x to do unit or scale conversion.

spct.names

character Vector of names to be assigned to collection members, either of length 1, or with length equal to the number of spectra.

Value

A copy of x converted into a raw_mspct object.

Methods (by class)

  • as.raw_mspct(default):

  • as.raw_mspct(data.frame):

  • as.raw_mspct(raw_spct):

  • as.raw_mspct(list):

  • as.raw_mspct(matrix):

Note

When x is a square matrix an explicit argument is needed for byrow to indicate how data in x should be read. In every case the length of the w.length vector must match one of the dimensions of x.

See Also

Other Coercion methods for collections of spectra: as.calibration_mspct(), as.chroma_mspct(), as.cps_mspct(), as.filter_mspct(), as.generic_mspct(), as.object_mspct(), as.reflector_mspct(), as.response_mspct(), as.solute_mspct(), as.source_mspct(), split2mspct(), subset2mspct()


Coerce to a spectrum

Description

Return a copy of an R object with its class set to a given type of spectrum.

Usage

as.raw_spct(x, ...)

## Default S3 method:
as.raw_spct(x, ...)

Arguments

x

an R object.

...

other arguments passed to "set" functions.

Value

A copy of x converted into a raw_spct object.

Methods (by class)

  • as.raw_spct(default):

See Also

setGenericSpct

Other constructors of spectral objects: as.calibration_spct(), as.chroma_spct(), as.cps_spct(), as.filter_spct(), as.generic_spct(), as.object_spct(), as.reflector_spct(), as.response_spct(), as.solute_spct(), as.source_spct(), source_spct()


Coerce to a collection-of-spectra

Description

Return a copy of an R object with its class set to a given type of spectrum.

Usage

as.reflector_mspct(x, ...)

## Default S3 method:
as.reflector_mspct(x, ...)

## S3 method for class 'data.frame'
as.reflector_mspct(
  x,
  Rfr.type = c("total", "specular"),
  strict.range = TRUE,
  ...
)

## S3 method for class 'reflector_spct'
as.reflector_mspct(x, ...)

## S3 method for class 'list'
as.reflector_mspct(
  x,
  Rfr.type = c("total", "specular"),
  strict.range = TRUE,
  ...,
  ncol = 1,
  byrow = FALSE
)

## S3 method for class 'matrix'
as.reflector_mspct(
  x,
  w.length,
  spct.data.var = "Rfr",
  multiplier = 1,
  byrow = NULL,
  spct.names = "spct_",
  ...
)

Arguments

x

a list of spectral objects or a list of objects such as data frames that can be converted into spectral objects.

...

passed to individual spectrum object constructor

Rfr.type

a character string, either "total" or "specular"

strict.range

logical Flag indicating how off-range values are handled

ncol

integer Number of 'virtual' columns in data

byrow

logical If ncol > 1 how to read in the data

w.length

numeric A vector of wavelengthvalues sorted in strictly ascending order (nm).

spct.data.var

character The name of the variable that will contain the spectral data. This indicates what physical quantity is stored in the matrix and the units of expression used.

multiplier

numeric A multiplier to be applied to the values in x to do unit or scale conversion.

spct.names

character Vector of names to be assigned to collection members, either of length 1, or with length equal to the number of spectra.

Value

A copy of x converted into a reflector_mspct object.

Methods (by class)

  • as.reflector_mspct(default):

  • as.reflector_mspct(data.frame):

  • as.reflector_mspct(reflector_spct):

  • as.reflector_mspct(list):

  • as.reflector_mspct(matrix):

Note

When x is a square matrix an explicit argument is needed for byrow to indicate how data in x should be read. In every case the length of the w.length vector must match one of the dimensions of x.

See Also

Other Coercion methods for collections of spectra: as.calibration_mspct(), as.chroma_mspct(), as.cps_mspct(), as.filter_mspct(), as.generic_mspct(), as.object_mspct(), as.raw_mspct(), as.response_mspct(), as.solute_mspct(), as.source_mspct(), split2mspct(), subset2mspct()


Coerce to a spectrum

Description

Return a copy of an R object with its class set to a given type of spectrum.

Usage

as.reflector_spct(x, ...)

## Default S3 method:
as.reflector_spct(
  x,
  Rfr.type = c("total", "specular"),
  strict.range = getOption("photobiology.strict.range", default = FALSE),
  ...
)

Arguments

x

an R object.

...

other arguments passed to "set" functions.

Rfr.type

a character string, either "total" or "specular".

strict.range

logical Flag indicating whether off-range values result in an error instead of a warning.

Value

A copy of x converted into a reflector_spct object.

Methods (by class)

  • as.reflector_spct(default):

See Also

setGenericSpct

Other constructors of spectral objects: as.calibration_spct(), as.chroma_spct(), as.cps_spct(), as.filter_spct(), as.generic_spct(), as.object_spct(), as.raw_spct(), as.response_spct(), as.solute_spct(), as.source_spct(), source_spct()


Coerce to a collection-of-spectra

Description

Return a copy of an R object with its class set to a given type of spectrum.

Usage

as.response_mspct(x, ...)

## Default S3 method:
as.response_mspct(x, ...)

## S3 method for class 'data.frame'
as.response_mspct(x, time.unit = "second", ...)

## S3 method for class 'response_spct'
as.response_mspct(x, ...)

## S3 method for class 'list'
as.response_mspct(x, time.unit = "second", ..., ncol = 1, byrow = FALSE)

## S3 method for class 'matrix'
as.response_mspct(
  x,
  w.length,
  spct.data.var = "s.e.response",
  multiplier = 1,
  byrow = NULL,
  spct.names = "spct_",
  ...
)

Arguments

x

a list of spectral objects or a list of objects such as data frames that can be converted into spectral objects.

...

passed to individual spectrum object constructor

time.unit

character A string, "second", "day" or "exposure"

ncol

integer Number of 'virtual' columns in data

byrow

logical If ncol > 1 how to read in the data

w.length

numeric A vector of wavelengthvalues sorted in strictly ascending order (nm).

spct.data.var

character The name of the variable that will contain the spectral data. This indicates what physical quantity is stored in the matrix and the units of expression used.

multiplier

numeric A multiplier to be applied to the values in x to do unit or scale conversion.

spct.names

character Vector of names to be assigned to collection members, either of length 1, or with length equal to the number of spectra.

Value

A copy of x converted into a response_mspct object.

Methods (by class)

  • as.response_mspct(default):

  • as.response_mspct(data.frame):

  • as.response_mspct(response_spct):

  • as.response_mspct(list):

  • as.response_mspct(matrix):

Note

When x is a square matrix an explicit argument is needed for byrow to indicate how data in x should be read. In every case the length of the w.length vector must match one of the dimensions of x.

See Also

Other Coercion methods for collections of spectra: as.calibration_mspct(), as.chroma_mspct(), as.cps_mspct(), as.filter_mspct(), as.generic_mspct(), as.object_mspct(), as.raw_mspct(), as.reflector_mspct(), as.solute_mspct(), as.source_mspct(), split2mspct(), subset2mspct()


Coerce to a spectrum

Description

Return a copy of an R object with its class set to a given type of spectrum.

Usage

as.response_spct(x, ...)

## Default S3 method:
as.response_spct(x, time.unit = "second", ...)

Arguments

x

an R object.

...

other arguments passed to "set" functions.

time.unit

character string indicating the time unit used for spectral irradiance or exposure ("second", "day" or "exposure") or an object of class duration as defined in package lubridate.

Value

A copy of x converted into a response_spct object.

Methods (by class)

  • as.response_spct(default):

See Also

setGenericSpct

Other constructors of spectral objects: as.calibration_spct(), as.chroma_spct(), as.cps_spct(), as.filter_spct(), as.generic_spct(), as.object_spct(), as.raw_spct(), as.reflector_spct(), as.solute_spct(), as.source_spct(), source_spct()


Coerce to a collection-of-spectra

Description

Return a copy of an R object with its class set to a given type of spectrum.

Usage

as.solute_mspct(x, ...)

## Default S3 method:
as.solute_mspct(x, ...)

## S3 method for class 'data.frame'
as.solute_mspct(
  x,
  K.type = c("attenuation", "absorption", "scattering"),
  strict.range = TRUE,
  ...
)

## S3 method for class 'solute_spct'
as.solute_mspct(x, ...)

## S3 method for class 'list'
as.solute_mspct(
  x,
  K.type = c("attenuation", "absorption", "scattering"),
  strict.range = TRUE,
  ...,
  ncol = 1,
  byrow = FALSE
)

## S3 method for class 'matrix'
as.solute_mspct(
  x,
  w.length,
  spct.data.var = "K.mole",
  multiplier = 1,
  byrow = NULL,
  spct.names = "spct_",
  ...
)

Arguments

x

a list of spectral objects or a list of objects such as data frames that can be converted into spectral objects.

...

passed to individual spectrum object constructor

K.type

a character string, either "attenuation", "absorption" or "scattering"

strict.range

logical Flag indicating how off-range values are handled

ncol

integer Number of 'virtual' columns in data

byrow

logical If ncol > 1 how to read in the data

w.length

numeric A vector of wavelength values sorted in strictly ascending order (nm).

spct.data.var

character The name of the variable that will contain the spectral data. This indicates what physical quantity is stored in the matrix and the units of expression used.

multiplier

numeric A multiplier to be applied to the values in x to do unit or scale conversion.

spct.names

character Vector of names to be assigned to collection members, either of length 1, or with length equal to the number of spectra.

Value

A copy of x converted into a filter_mspct object.

Methods (by class)

  • as.solute_mspct(default):

  • as.solute_mspct(data.frame):

  • as.solute_mspct(solute_spct):

  • as.solute_mspct(list):

  • as.solute_mspct(matrix):

Note

When x is a square matrix an explicit argument is needed for byrow to indicate how data in x should be read. In every case the length of the w.length vector must match one of the dimensions of x.

See Also

Other Coercion methods for collections of spectra: as.calibration_mspct(), as.chroma_mspct(), as.cps_mspct(), as.filter_mspct(), as.generic_mspct(), as.object_mspct(), as.raw_mspct(), as.reflector_mspct(), as.response_mspct(), as.source_mspct(), split2mspct(), subset2mspct()


Coerce to a solute spectrum

Description

Return a possibly modified copy of an R object with its class set to solute_spct (a solute spectrum). In the case of conversion from a filter_spct object, compute spectral molar attenuation based on additional input from user.

Usage

as.solute_spct(x, ...)

## Default S3 method:
as.solute_spct(
  x,
  K.type = c("attenuation", "absorption", "scattering"),
  strict.range = getOption("photobiology.strict.range", default = FALSE),
  ...
)

## S3 method for class 'filter_spct'
as.solute_spct(
  x,
  K.type = c("attenuation", "absorption", "scattering"),
  name = NA_character_,
  mass = NA_character_,
  formula = NULL,
  structure = grDevices::as.raster(matrix()),
  ID = NA_character_,
  solvent.name = NA_character_,
  solvent.ID = NA_character_,
  strict.range = getOption("photobiology.strict.range", default = FALSE),
  comment = NULL,
  molar.concentration = NULL,
  mass.concentration = NULL,
  path.length = 1,
  ...
)

Arguments

x

an R object.

...

other arguments passed to "set" functions.

K.type

a character string, one of "attenuation", "absorption" or "scattering".

strict.range

logical Flag indicating whether off-range values result in an error instead of a warning.

name, solvent.name

character The names of the substance and of the solvent. A named character vector, with member names such as "IUPAC" for the authority.

mass

numeric The mass in Dalton (Da = g/mol).

formula

character The molecular formula.

structure

raster A bitmap of the structure.

ID, solvent.ID

character The IDs of the substance and of the solvent. A named character vector, with member names such as "ChemSpider" or "PubChen" for the authority.

comment

character A string to be added as a comment attribute to the object created. If not supplied, the comment will be copied from x.

molar.concentration, mass.concentration

numeric Concentration to be used to compute transmittance of the solute in solution [molm3=mmoldm3mol\,m^{-3} = mmol\,dm^{-3} or kgm3=gdm3kg\,m^{-3} = g\,dm^{-3}, respectively].

path.length

numeric The length of the light path (mm) used to compute transmittance of the solute in a solution.

Value

A copy of x converted into a solute_spct object.

Methods (by class)

  • as.solute_spct(default):

  • as.solute_spct(filter_spct):

See Also

setSoluteSpct

Other constructors of spectral objects: as.calibration_spct(), as.chroma_spct(), as.cps_spct(), as.filter_spct(), as.generic_spct(), as.object_spct(), as.raw_spct(), as.reflector_spct(), as.response_spct(), as.source_spct(), source_spct()


Coerce to a collection-of-spectra

Description

Return a copy of an R object with its class set to a given type of spectrum.

Usage

as.source_mspct(x, ...)

## Default S3 method:
as.source_mspct(x, ...)

## S3 method for class 'data.frame'
as.source_mspct(
  x,
  time.unit = c("second", "day", "exposure"),
  bswf.used = c("none", "unknown"),
  strict.range = getOption("photobiology.strict.range", default = FALSE),
  ...
)

## S3 method for class 'source_spct'
as.source_mspct(x, ...)

## S3 method for class 'list'
as.source_mspct(
  x,
  time.unit = c("second", "day", "exposure"),
  bswf.used = c("none", "unknown"),
  strict.range = getOption("photobiology.strict.range", default = FALSE),
  ...,
  ncol = 1,
  byrow = FALSE
)

## S3 method for class 'matrix'
as.source_mspct(
  x,
  w.length,
  spct.data.var = "s.e.irrad",
  multiplier = 1,
  byrow = NULL,
  spct.names = "spct_",
  ...
)

Arguments

x

a list of spectral objects or a list of objects such as data frames that can be converted into spectral objects.

...

passed to individual spectrum object constructor

time.unit

character A string, "second", "day" or "exposure"

bswf.used

character

strict.range

logical Flag indicating how off-range values are handled

ncol

integer Number of 'virtual' columns in data

byrow

logical If ncol > 1 how to read in the data

w.length

numeric A vector of wavelengthvalues sorted in strictly ascending order (nm).

spct.data.var

character The name of the variable that will contain the spectral data. This indicates what physical quantity is stored in the matrix and the units of expression used.

multiplier

numeric A multiplier to be applied to the values in x to do unit or scale conversion.

spct.names

character Vector of names to be assigned to collection members, either of length 1, or with length equal to the number of spectra.

Value

A copy of x converted into a source_mspct object.

Methods (by class)

  • as.source_mspct(default):

  • as.source_mspct(data.frame):

  • as.source_mspct(source_spct):

  • as.source_mspct(list):

  • as.source_mspct(matrix):

Note

When x is a square matrix an explicit argument is needed for byrow to indicate how data in x should be read. In every case the length of the w.length vector must match one of the dimensions of x.

See Also

Other Coercion methods for collections of spectra: as.calibration_mspct(), as.chroma_mspct(), as.cps_mspct(), as.filter_mspct(), as.generic_mspct(), as.object_mspct(), as.raw_mspct(), as.reflector_mspct(), as.response_mspct(), as.solute_mspct(), split2mspct(), subset2mspct()


Coerce to a spectrum

Description

Return a copy of an R object with its class set to a given type of spectrum.

Usage

as.source_spct(x, ...)

## Default S3 method:
as.source_spct(
  x,
  time.unit = c("second", "day", "exposure"),
  bswf.used = c("none", "unknown"),
  strict.range = getOption("photobiology.strict.range", default = FALSE),
  ...
)

Arguments

x

an R object.

...

other arguments passed to "set" functions.

time.unit

character string indicating the time unit used for spectral irradiance or exposure ("second", "day" or "exposure") or an object of class duration as defined in package lubridate.

bswf.used

character A string indicating the BSWF used, if any, for spectral effective irradiance or exposure ("none" or the name of the BSWF).

strict.range

logical Flag indicating whether off-range values result in an error instead of a warning.

Value

A copy of x converted into a source_spct object.

Methods (by class)

  • as.source_spct(default):

See Also

setGenericSpct

Other constructors of spectral objects: as.calibration_spct(), as.chroma_spct(), as.cps_spct(), as.filter_spct(), as.generic_spct(), as.object_spct(), as.raw_spct(), as.reflector_spct(), as.response_spct(), as.solute_spct(), source_spct()


Average spectral data.

Description

This function gives the result of integrating spectral data over wavelengths and dividing the result by the spread or span of the wavelengths.

Usage

average_spct(spct)

Arguments

spct

generic_spct

Value

One or more numeric values with no change in scale factor: e.g. [W m-2 nm-1] -> [W m-2 nm-1]. Each value in the returned vector corresponds to a variable in the spectral object, except for wavelength.

Examples

average_spct(sun.spct)

Honeybee xyz chromaticity colour matching function data

Description

A dataset containing wavelengths at a 5 nm interval (300 nm to 700 nm) and the corresponding x, y, and z chromaticity coordinates. Original data from XXX.

A chroma_spct object with variables as follows:

Usage

beesxyzCMF.spct

Format

A data frame with 81 rows and 4 variables

Details

  • w.length (nm)

  • x

  • y

  • z

See Also

Other Visual response data examples: ciev10.spct, ciev2.spct, ciexyzCC10.spct, ciexyzCC2.spct, ciexyzCMF10.spct, ciexyzCMF2.spct, cone_fundamentals10.spct


Theoretical optical bodies

Description

Datasets for a hypothetical objects with transmittance 0/1 (0%), reflectance 0/1 (0%), with transmittance 0/1 (0%), reflectance 1/1 (100%), and with with transmittance 1/1 (100%), reflectance 0/1 (0%).

Format

A object_spct object with 4 rows and 3 variables

Details

  • w.length (nm)

  • Tfr (0..1)

  • Rfr (0..1)

See Also

Other Spectral data examples: A.illuminant.spct, D50.illuminant.spct, D65.illuminant.spct, Ler_leaf.spct, ccd.spct, clear.spct, filter_cps.mspct, green_leaf.spct, phenylalanine.spct, photodiode.spct, sun.spct, sun_daily.spct, sun_evening.spct, two_filters.spct, two_sensors.mspct, water.spct, white_led.source_spct


Combine collections of spectra

Description

Combine two or more generic_mspct objects into a single object.

Usage

## S3 method for class 'generic_mspct'
c(..., recursive = FALSE, ncol = 1, byrow = FALSE)

Arguments

...

one or more generic_mspct objects to combine.

recursive

logical ignored as nesting of collections of spectra is not supported.

ncol

numeric Virtual number of columns

byrow

logical When object has two dimensions, how to map member objects to columns and rows.

Value

A collection of spectra object belonging to the most derived class shared among the combined objects.


Spectral weights

Description

Calculate multipliers for selecting a range of wavelengths and optionally applying a biological spectral weighting function (BSWF) and wavelength normalization. This function returns numeric multipliers that can be used to select a waveband and apply a weight.

Usage

calc_multipliers(
  w.length,
  w.band,
  unit.out = "energy",
  unit.in = "energy",
  use.cached.mult = FALSE,
  fill = 0
)

Arguments

w.length

numeric vector of wavelengths (nm).

w.band

waveband object.

unit.out

character A string: "photon" or "energy", default is "energy".

unit.in

character A string: "photon" or "energy", default is "energy".

use.cached.mult

logical Flag indicating whether multiplier values should be cached between calls.

fill

numeric If fill = NA then values returned for wavelengths outside the range of the waveband are set to NA.

Value

a numeric vector of multipliers of the same length as w.length.

See Also

Other low-level functions operating on numeric vectors.: as_energy(), as_quantum_mol(), div_spectra(), energy_irradiance(), energy_ratio(), insert_hinges(), integrate_xy(), interpolate_spectrum(), irradiance(), l_insert_hinges(), oper_spectra(), photon_irradiance(), photon_ratio(), photons_energy_ratio(), prod_spectra(), s_e_irrad2rgb(), split_energy_irradiance(), split_photon_irradiance(), subt_spectra(), sum_spectra(), trim_tails(), v_insert_hinges(), v_replace_hinges()

Examples

with(sun.data, calc_multipliers(w.length, new_waveband(400,700),"photon"))
with(sun.data, calc_multipliers(w.length, new_waveband(400,700),"photon"), use.cached.mult = TRUE)

Scaled and/or interpolated light-source spectral output

Description

Values calculated by interpolation from user-supplied spectral emission data or by name for light source data included in the packages photobiologySun, photobiologyLamps, or photobiologyLEDs, optionally re-scaling the spectral data values.

Usage

calc_source_output(
  w.length.out,
  w.length.in,
  s.irrad.in,
  unit.in = "energy",
  scaled = NULL,
  fill = NA,
  ...
)

Arguments

w.length.out

numeric vector of wavelengths (nm) for output.

w.length.in

numeric vector of wavelengths (nm) for input.

s.irrad.in

numeric vector of spectral transmittance value (fractions or percent).

unit.in

a character string "energy" or "photon".

scaled

NULL, "peak", "area"; div ignored if !is.null(scaled).

fill

if NA, no extrapolation is done, and NA is returned for wavelengths outside the range of the input. If NULL then the tails are deleted. If 0 then the tails are set to zero.

...

Additional arguments passed to spline if called.

Value

a source_spct with three numeric vectors with wavelength values (w.length), scaled and interpolated spectral energy irradiance (s.e.irrad), scaled and interpolated spectral photon irradiance values (s.q.irrad).

Note

This is a convenience function that adds no new functionality but makes it a little easier to plot lamp spectral emission data consistently. It automates interpolation, extrapolation/trimming and scaling.

Examples

with(sun.data,
     calc_source_output(290:1100,
                        w.length.in = w.length,
                        s.irrad.in = s.e.irrad)
    )

Spectral response of a back-thinned CCD image sensor.

Description

A dataset containing wavelengths at a 1 nm interval and spectral response as quantum efficiency for CCD sensor type S11071/S10420 from Hamamatsu (measured without a quartz window). These vectors are frequently used as sensors in high-UV-sensitivity vector spectrometers. Data digitized from manufacturer's data sheet. The original data is expressed as percent quantum efficiency with a value of 77% at the peak. The data have been re-expressed as fractions of one.

Usage

ccd.spct

Format

A response_spct object with 186 rows and 2 variables

Details

  • w.length (nm).

  • s.q.response (fractional quantum efficiency)

References

Hamamatsu (2014) Datasheet: CCD Image Sensors S11071/S10420-01 Series. Hamamatsu Photonics KK, Hamamatsu, City. http://www.hamamatsu.com/jp/en/S11071-1004.html. Visited 2017-12-15.

See Also

Other Spectral data examples: A.illuminant.spct, D50.illuminant.spct, D65.illuminant.spct, Ler_leaf.spct, black_body.spct, clear.spct, filter_cps.mspct, green_leaf.spct, phenylalanine.spct, photodiode.spct, sun.spct, sun_daily.spct, sun_evening.spct, two_filters.spct, two_sensors.mspct, water.spct, white_led.source_spct

Examples

ccd.spct

Check validity of spectral objects

Description

Check that an R object contains the expected data members and within range values in them. For wavelengths also check if ordered and if unique or not.

Usage

check_spct(x, byref, strict.range, force = FALSE, ...)

## Default S3 method:
check_spct(x, byref = FALSE, strict.range = NA, force = FALSE, ...)

## S3 method for class 'generic_spct'
check_spct(
  x,
  byref = TRUE,
  strict.range = NA,
  force = FALSE,
  multiple.wl = getMultipleWl(x),
  ...
)

## S3 method for class 'calibration_spct'
check_spct(
  x,
  byref = TRUE,
  strict.range = getOption("photobiology.strict.range", default = FALSE),
  force = FALSE,
  multiple.wl = getMultipleWl(x),
  ...
)

## S3 method for class 'raw_spct'
check_spct(
  x,
  byref = TRUE,
  strict.range = getOption("photobiology.strict.range", default = FALSE),
  force = FALSE,
  multiple.wl = getMultipleWl(x),
  ...
)

## S3 method for class 'cps_spct'
check_spct(
  x,
  byref = TRUE,
  strict.range = getOption("photobiology.strict.range", default = FALSE),
  force = FALSE,
  multiple.wl = getMultipleWl(x),
  ...
)

## S3 method for class 'filter_spct'
check_spct(
  x,
  byref = TRUE,
  strict.range = getOption("photobiology.strict.range", default = FALSE),
  force = FALSE,
  multiple.wl = getMultipleWl(x),
  ...
)

## S3 method for class 'solute_spct'
check_spct(
  x,
  byref = TRUE,
  strict.range = getOption("photobiology.strict.range", default = FALSE),
  force = FALSE,
  multiple.wl = getMultipleWl(x),
  ...
)

## S3 method for class 'reflector_spct'
check_spct(
  x,
  byref = TRUE,
  strict.range = getOption("photobiology.strict.range", default = FALSE),
  force = FALSE,
  multiple.wl = getMultipleWl(x),
  ...
)

## S3 method for class 'object_spct'
check_spct(
  x,
  byref = TRUE,
  strict.range = getOption("photobiology.strict.range", default = FALSE),
  force = FALSE,
  multiple.wl = getMultipleWl(x),
  ...
)

## S3 method for class 'response_spct'
check_spct(
  x,
  byref = TRUE,
  strict.range = NA,
  force = FALSE,
  multiple.wl = getMultipleWl(x),
  ...
)

## S3 method for class 'source_spct'
check_spct(
  x,
  byref = TRUE,
  strict.range = getOption("photobiology.strict.range", default = FALSE),
  force = FALSE,
  multiple.wl = getMultipleWl(x),
  ...
)

## S3 method for class 'chroma_spct'
check_spct(
  x,
  byref = TRUE,
  strict.range = getOption("photobiology.strict.range", default = FALSE),
  force = FALSE,
  multiple.wl = getMultipleWl(x),
  ...
)

Arguments

x

An R object

byref

logical indicating if new object will be created by reference or by copy of x

strict.range

logical indicating whether off-range values result in an error instead of a warning, with NA a message is issued on failure.

force

logical If TRUE check is done even if checks are disabled.

...

additional parameters possible in derived methods

multiple.wl

numeric Maximum number of repeated w.length entries with same value.

Details

These methods are exported and can be called by user code if needed, for example, when the checks have been disabled by setting an R option with disable_check_spct.

Methods (by class)

  • check_spct(default): Default for generic function.

  • check_spct(generic_spct): Specialization for generic_spct.

  • check_spct(calibration_spct): Specialization for calibration_spct.

  • check_spct(raw_spct): Specialization for raw_spct.

  • check_spct(cps_spct): Specialization for cps_spct.

  • check_spct(filter_spct): Specialization for filter_spct.

  • check_spct(solute_spct): Specialization for solute_spct.

  • check_spct(reflector_spct): Specialization for reflector_spct.

  • check_spct(object_spct): Specialization for object_spct.

  • check_spct(response_spct): Specialization for response_spct.

  • check_spct(source_spct): Specialization for source_spct.

  • check_spct(chroma_spct): Specialization for chroma_spct.

See Also

Other data validity check functions: check_spectrum(), check_w.length(), enable_check_spct()

Examples

check_spct(sun.spct)

check_spct(sun.spct)
# try(check_spct(-sun.spct))
# try(check_spct((sun.spct[1, "w.length"] <- 1000)))

Sanity check a spectrum

Description

Checks spectral irradiance data in numeric vectors for compliance with assumptions used in calculations.

Usage

check_spectrum(w.length, s.irrad)

Arguments

w.length

numeric vector of wavelengths [nmnm].

s.irrad

numeric Corresponding vector of spectral (energy) irradiances [Wm2nm1W\,m^{-2}\,nm^{-1}].

Value

A single logical value indicating whether test was passed or not

See Also

Other data validity check functions: check_spct(), check_w.length(), enable_check_spct()

Examples

with(sun.data, check_spectrum(w.length, s.e.irrad))

Sanity check of wavelengths (internal function).

Description

This function checks a w.length vector for compliance with assumptions used in calculations.

Usage

check_w.length(w.length)

Arguments

w.length

numeric array of wavelength (nm)

Value

a single logical value indicating whether test was passed or not

See Also

Other data validity check functions: check_spct(), check_spectrum(), enable_check_spct()

Examples

with(sun.data, photobiology:::check_w.length(w.length))

Check the "time.unit" attribute of an existing source_spct object

Description

Function to read the "time.unit" attribute

Usage

checkTimeUnit(x)

Arguments

x

a source_spct object

Value

x possibly with the time.unit attribute modified

Note

if x is not a source_spct or a response_spct object, NA is returned

See Also

Other time attribute functions: convertThickness(), convertTimeUnit(), getTimeUnit(), setTimeUnit()


Linear energy CIE 2008 luminous efficiency function 10 deg data

Description

A dataset containing wavelengths at a 1 nm interval (390 nm to 830 nm) and the corresponding response values for a 10 degrees target. Original data from http://www.cvrl.org/ downloaded on 2014-04-29 The variables are as follows:

  • w.length (nm)

  • s.e.response

Usage

ciev10.spct

Format

A chroma_spct object with 441 rows and 4 variables

Author(s)

CIE

See Also

Other Visual response data examples: beesxyzCMF.spct, ciev2.spct, ciexyzCC10.spct, ciexyzCC2.spct, ciexyzCMF10.spct, ciexyzCMF2.spct, cone_fundamentals10.spct

Examples

ciev10.spct

Linear energy CIE 2008 luminous efficiency function 2 deg data

Description

A dataset containing wavelengths at a 1 nm interval (390 nm to 830 nm) and the corresponding response values for a 2 degrees target. Original data from http://www.cvrl.org/ downloaded on 2014-04-29 The variables are as follows:

Usage

ciev2.spct

Format

A chroma_spct object with 441 rows and 4 variables

Details

  • w.length (nm)

  • s.e.response

Note

These data are not from the official CIE on-line distribution but are retained for backwards compatibility. It is recommended to download the latest version from https://cie.co.at/data-tables.

Author(s)

CIE

See Also

Other Visual response data examples: beesxyzCMF.spct, ciev10.spct, ciexyzCC10.spct, ciexyzCC2.spct, ciexyzCMF10.spct, ciexyzCMF2.spct, cone_fundamentals10.spct

Examples

ciev2.spct

CIE xyz chromaticity coordinates (CC) 10 deg data

Description

A dataset containing wavelengths at a 1 nm interval (390 nm to 830 nm) and the corresponding x, y, and z chromaticity coordinates. Derived from proposed CIE 2006 standard. Original data from http://www.cvrl.org/ downloaded on 2014-04-29 The variables are as follows:

  • w.length (nm)

  • x

  • y

  • z

Usage

ciexyzCC10.spct

Format

A chroma_spct object with 441 rows and 4 variables

Note

These data are not from the official CIE on-line distribution but are retained for backwards compatibility. It is recommended to download the latest version from https://cie.co.at/data-tables.

Author(s)

CIE

See Also

Other Visual response data examples: beesxyzCMF.spct, ciev10.spct, ciev2.spct, ciexyzCC2.spct, ciexyzCMF10.spct, ciexyzCMF2.spct, cone_fundamentals10.spct

Examples

ciexyzCC10.spct

CIE xyz chromaticity coordinates 2 deg data

Description

A dataset containing wavelengths at a 1 nm interval (390 nm to 830 nm) and the corresponding x, y, and z chromaticity coordinates. According to proposed CIE 2006 standard. Original data from http://www.cvrl.org/ downloaded on 2014-04-28 The variables are as follows:

  • w.length (nm)

  • x

  • y

  • z

Usage

ciexyzCC2.spct

Format

A chroma_spct object with 441 rows and 4 variables

Note

These data are not from the official CIE on-line distribution but are retained for backwards compatibility. It is recommended to download the latest version from https://cie.co.at/data-tables.

Author(s)

CIE

See Also

Other Visual response data examples: beesxyzCMF.spct, ciev10.spct, ciev2.spct, ciexyzCC10.spct, ciexyzCMF10.spct, ciexyzCMF2.spct, cone_fundamentals10.spct

Examples

ciexyzCC2.spct

Linear energy CIE xyz colour matching function (CMF) 10 deg data

Description

A dataset containing wavelengths at a 1 nm interval (390 nm to 830 nm) and the corresponding x, y, and z 10 degrees CMF values. Derived from proposed CIE 2006 standard. Original data from http://www.cvrl.org/ downloaded on 2014-04-29 The variables are as follows:

  • w.length (nm)

  • x

  • y

  • z

Usage

ciexyzCMF10.spct

Format

A chroma_spct object with 441 rows and 4 variables

Note

These data are not from the official CIE on-line distribution but are retained for backwards compatibility. It is recommended to download the latest version from https://cie.co.at/data-tables.

These data are not from the official CIE on-line distribution but are retained for backwards compatibility. It is recommended to download the latest version from https://cie.co.at/data-tables.

Author(s)

CIE

See Also

Other Visual response data examples: beesxyzCMF.spct, ciev10.spct, ciev2.spct, ciexyzCC10.spct, ciexyzCC2.spct, ciexyzCMF2.spct, cone_fundamentals10.spct

Examples

ciexyzCMF10.spct

Linear energy CIE xyz colour matching function (CMF) 2 deg data

Description

A dataset containing wavelengths at a 1 nm interval (390 nm to 830 nm) and the corresponding x, y, and z 2 degrees CMF values. Derived from proposed CIE 2006 standard. Original data from http://www.cvrl.org/ downloaded on 2014-04-29 The variables are as follows:

  • w.length (nm)

  • x

  • y

  • z

Usage

ciexyzCMF2.spct

Format

A chroma_spct object with 441 rows and 4 variables

Note

These data are not from the official CIE on-line distribution but are retained for backwards compatibility. It is recommended to download the latest version from https://cie.co.at/data-tables.

Author(s)

CIE

See Also

Other Visual response data examples: beesxyzCMF.spct, ciev10.spct, ciev2.spct, ciexyzCC10.spct, ciexyzCC2.spct, ciexyzCMF10.spct, cone_fundamentals10.spct

Examples

ciexyzCMF2.spct

Query which is the class of a spectrum

Description

Extract class information from a generic spectrum.

Usage

class_spct(x)

Arguments

x

any R object

Details

The value returned is equivalent to the set intersection of the value returned by class(x) and the value returned by spct_classes, but preserving the order of the members of the character vector.

Value

A character vector containing all matching xxxx.spct S3 classes.

Examples

class_spct(sun.spct)
class(sun.spct)

Clean (=replace) off-range values in a spectrum

Description

These functions implement the equivalent of replace() but for spectral objects instead of vectors.

Usage

clean(x, range, range.s.data, fill, ...)

## Default S3 method:
clean(x, range, range.s.data, fill, ...)

## S3 method for class 'source_spct'
clean(
  x,
  range = x,
  range.s.data = c(0, NA),
  fill = range.s.data,
  unit.out = getOption("photobiology.radiation.unit", default = "energy"),
  ...
)

## S3 method for class 'filter_spct'
clean(
  x,
  range = x,
  range.s.data = NULL,
  fill = range.s.data,
  qty.out = getOption("photobiology.filter.qty", default = "transmittance"),
  ...
)

## S3 method for class 'reflector_spct'
clean(x, range = x, range.s.data = c(0, 1), fill = range.s.data, ...)

## S3 method for class 'solute_spct'
clean(x, range = x, range.s.data = c(0, NA), fill = range.s.data, ...)

## S3 method for class 'object_spct'
clean(
  x,
  range = x,
  range.s.data = c(0, 1),
  fill = range.s.data,
  min.Afr = NULL,
  ...
)

## S3 method for class 'response_spct'
clean(
  x,
  range = x,
  range.s.data = c(0, NA),
  fill = range.s.data,
  unit.out = getOption("photobiology.radiation.unit", default = "energy"),
  ...
)

## S3 method for class 'cps_spct'
clean(x, range = x, range.s.data = c(0, NA), fill = range.s.data, ...)

## S3 method for class 'raw_spct'
clean(
  x,
  range = x,
  range.s.data = c(NA_real_, NA_real_),
  fill = range.s.data,
  ...
)

## S3 method for class 'generic_spct'
clean(
  x,
  range = x,
  range.s.data = c(NA_real_, NA_real_),
  fill = range.s.data,
  col.names,
  ...
)

## S3 method for class 'source_mspct'
clean(
  x,
  range = NULL,
  range.s.data = c(0, NA),
  fill = range.s.data,
  unit.out = getOption("photobiology.radiation.unit", default = "energy"),
  ...,
  .parallel = FALSE,
  .paropts = NULL
)

## S3 method for class 'filter_mspct'
clean(
  x,
  range = NULL,
  range.s.data = NULL,
  fill = range.s.data,
  qty.out = getOption("photobiology.filter.qty", default = "transmittance"),
  ...,
  .parallel = FALSE,
  .paropts = NULL
)

## S3 method for class 'reflector_mspct'
clean(
  x,
  range = NULL,
  range.s.data = c(0, 1),
  fill = range.s.data,
  ...,
  .parallel = FALSE,
  .paropts = NULL
)

## S3 method for class 'object_mspct'
clean(
  x,
  range = NULL,
  range.s.data = c(0, 1),
  fill = range.s.data,
  min.Afr = NULL,
  ...,
  .parallel = FALSE,
  .paropts = NULL
)

## S3 method for class 'solute_mspct'
clean(
  x,
  range = NULL,
  range.s.data = c(0, NA),
  fill = range.s.data,
  ...,
  .parallel = FALSE,
  .paropts = NULL
)

## S3 method for class 'response_mspct'
clean(
  x,
  range = NULL,
  range.s.data = c(0, NA),
  fill = range.s.data,
  unit.out = getOption("photobiology.radiation.unit", default = "energy"),
  ...,
  .parallel = FALSE,
  .paropts = NULL
)

## S3 method for class 'cps_mspct'
clean(
  x,
  range = NULL,
  range.s.data = c(0, NA),
  fill = range.s.data,
  ...,
  .parallel = FALSE,
  .paropts = NULL
)

## S3 method for class 'raw_mspct'
clean(
  x,
  range = NULL,
  range.s.data = c(0, NA),
  fill = range.s.data,
  ...,
  .parallel = FALSE,
  .paropts = NULL
)

## S3 method for class 'generic_mspct'
clean(
  x,
  range = x,
  range.s.data = c(NA_real_, NA_real_),
  fill = range.s.data,
  col.names,
  ...,
  .parallel = FALSE,
  .paropts = NULL
)

Arguments

x

an R object

range

numeric vector of wavelengths

range.s.data

numeric vector of length two giving the allowable range for the spectral data.

fill

numeric vector of length 1 or 2, giving the replacement values to use at each extreme of the range.

...

currently ignored

unit.out

character string with allowed values "energy", and "photon", or its alias "quantum"

qty.out

character string with allowed values "energy", and "photon", or its alias "quantum"

min.Afr

numeric Gives the minimum value accepted for the computed absorptance. The default NULL sets a valid value (Afr >= 0) with a warning. If an integer value is passed to digits values are adjusted silently.

col.names

character The name of the variable to clean

.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, possibly with some of the spectral data values replaced by the value passed to fill.

Methods (by class)

  • clean(default): Default for generic function

  • clean(source_spct): Replace off-range values in a source spectrum

  • clean(filter_spct): Replace off-range values in a filter spectrum

  • clean(reflector_spct): Replace off-range values in a reflector spectrum

  • clean(solute_spct): Replace off-range values in a solute spectrum

  • clean(object_spct): Replace off-range values in an object spectrum

  • clean(response_spct): Replace off-range values in a response spectrum

  • clean(cps_spct): Replace off-range values in a counts per second spectrum

  • clean(raw_spct): Replace off-range values in a raw counts spectrum

  • clean(generic_spct): Replace off-range values in a generic spectrum

  • clean(source_mspct):

  • clean(filter_mspct):

  • clean(reflector_mspct):

  • clean(object_mspct):

  • clean(solute_mspct):

  • clean(response_mspct):

  • clean(cps_mspct):

  • clean(raw_mspct):

  • clean(generic_mspct):

Note

In the case of object_spct objects, cleaning is done first on the Rfr and Tfr columns and subsequently Afr estimated and if needed half of deviation of Afr from the expected minimum value subtracted from each of Rfr and Tfr.


Theoretical spectrum of clear and apaque materials

Description

Dataset for hypothetical objects with transmittance 1/1 (100%) and transmittance 0/1 (0%)

Usage

clear.spct

opaque.spct

Format

A filter_spct object with 4 rows and 2 variables

An object of class filter_spct (inherits from generic_spct, tbl_df, tbl, data.frame) with 4 rows and 2 columns.

Details

  • w.length (nm).

  • Tfr (0..1)

See Also

Other Spectral data examples: A.illuminant.spct, D50.illuminant.spct, D65.illuminant.spct, Ler_leaf.spct, black_body.spct, ccd.spct, filter_cps.mspct, green_leaf.spct, phenylalanine.spct, photodiode.spct, sun.spct, sun_daily.spct, sun_evening.spct, two_filters.spct, two_sensors.mspct, water.spct, white_led.source_spct

Examples

clear.spct
opaque.spct

Clip head and/or tail of a spectrum

Description

Clip head and tail of a spectrum based on wavelength limits, no interpolation used at range boundaries.

Usage

clip_wl(x, range, ...)

## Default S3 method:
clip_wl(x, range, ...)

## S3 method for class 'generic_spct'
clip_wl(x, range = NULL, ...)

## S3 method for class 'generic_mspct'
clip_wl(x, range = NULL, ...)

## S3 method for class 'waveband'
clip_wl(x, range = NULL, ...)

## S3 method for class 'list'
clip_wl(x, range = NULL, ...)

Arguments

x

an R object.

range

a numeric vector of length two, or any other object for which function range() will return range of wavelengths expressed in nanometres.

...

ignored (possibly used by derived methods).

Value

a spectrum object or a collection of spectral objects of the same class as x with wavelength heads and tails clipped.

Methods (by class)

  • clip_wl(default): Default for generic function

  • clip_wl(generic_spct): Clip an object of class "generic_spct" or derived.

  • clip_wl(generic_mspct): Clip an object of class "generic_mspct" or derived.

  • clip_wl(waveband): Clip an object of class "waveband".

  • clip_wl(list): Clip a list (of objects of class "waveband").

Note

The condition tested is wl >= range[1] & wl < (range[2] + 1e-13).

See Also

Other trim functions: trim_spct(), trim_waveband(), trim_wl()

Examples

clip_wl(sun.spct, range = c(400, 500))
clip_wl(sun.spct, range = c(NA, 500))
clip_wl(sun.spct, range = c(400, NA))

Form a new collection

Description

Form a collection of spectra from separate objects in the parent frame of the call.

Usage

collect2mspct(
  .list = NULL,
  pattern = "*\\.spct$",
  collection.class = NULL,
  ...
)

Arguments

.list

list of R objects

pattern

character an optional regular expression, ignored if .list is not NULL.

collection.class

character vector

...

additional named arguments passed down to the collection constructor.

Details

This is a convenience function that simplifies the creation of collections from existing objects of class generic_spct or a derived class. A list of objects con be passed as argument, or a search pattern. If a list is passed, no search is done. If collection.class is NULL, then all objects of class generic_spct or of a class derived from it are added to the collection. If objects of only one derived class are to be collected this class or that of the matching collection should be passed as argument to collection.class. Objects of other R classes are silently discarded, which simplifies the specification of search patterns. By default, i.e., if collection.class is NULL, if all the objects collected belong to the same class then the corresponding collection class will be returned, otherwise a generic_mspct object with heterogeneous members will be returned. To force the return of a generic_mspct even when the collected spectra all belong to the same class, pass generic_mspct as argument to collection.class. If the argument to collection.class is a vector containing two of more class names, only the matching spectra will be collected, and a generic_mspct will be returned. The returned object is created with the constructor for the class, and validated.

Value

By default a collection of spectra.

See Also

Other experimental utility functions: drop_user_cols(), thin_wl(), uncollect2spct()

Examples

collect2mspct() # returns empty generic_mspct object

sun1.spct <- sun.spct
sun2.spct <- sun.spct
kk.spct <- 10:30 # ignored
collect2mspct()
collect2mspct(collection.class = "generic_mspct")

pet1.spct <- polyester.spct
collect2mspct()
collect2mspct(collection.class = "source_mspct")
collect2mspct(collection.class = "filter_mspct")
collect2mspct(collection.class = "response_mspct")

Color of an object

Description

Equivalent RGB color of an object such as a spectrum, wavelength or waveband.

Usage

color_of(x, ...)

## Default S3 method:
color_of(x, ...)

## S3 method for class 'numeric'
color_of(x, type = "CMF", chroma.type = type, ...)

## S3 method for class 'list'
color_of(x, short.names = TRUE, type = "CMF", chroma.type = type, ...)

## S3 method for class 'waveband'
color_of(x, short.names = TRUE, type = "CMF", chroma.type = type, ...)

## S3 method for class 'source_spct'
color_of(x, type = "CMF", chroma.type = type, ...)

## S3 method for class 'source_mspct'
color_of(x, ..., idx = "spct.idx")

colour_of(x, ...)

color(x, ...)

fast_color_of_wl(x, type = "CMF", ...)

fast_color_of_wb(x, type = "CMF", ...)

Arguments

x

an R object.

...

ignored (possibly used by derived methods).

type, chroma.type

character telling whether "CMF", "CC", or "both" should be returned for human vision, or an object of class chroma_spct for any other trichromic visual system.

short.names

logical indicating whether to use short or long names for wavebands

idx

character Name of the column with the names of the members of the collection of spectra.

Value

A color definition in hexadecimal format as a character string of 7 characters, "#" followed by the red, blue, and green values in hexadecimal (scaled to 0 ... 255). In the case of the specialization for list, a list of such definitions is returned. In the case of a collection of spectra, a data.frame with one column with such definitions and by default an additional column with names of the spectra as index. In case of missing input the returned value is NA.

Methods (by class)

  • color_of(default): Default method (returns always "black").

  • color_of(numeric): Method that returns Color definitions corresponding to numeric values representing a wavelengths in nm.

  • color_of(list): Method that returns Color of elements in a list.

  • color_of(waveband): Color at midpoint of a waveband object.

  • color_of(source_spct):

  • color_of(source_mspct):

Deprecated

Use of color() is deprecated as this wrapper function may be removed in future versions of the package because of name clashes. Use color_of() instead.

Note

The specialization of color_of() for numeric and function fast_color_of_wl() accept both positive and negative values in x as long as all values have the same sign. This makes its use in 'ggspectra' simpler as the reverse scale transform changes the sign of the data. This should be considered a temporary fix.

When x is a list but not a waveband, if a method color_of is not available for the class of each element of the list, then color_of.default will be called.

Function fast_color_of_wl() should be used only when high performance is needed. It speeds up performance by rounding the wavelength values in the numeric vector passed as argument to x and then retrieves the corresponding pre-computed color definitions if type is either "CMF" or "CC". In other cases it falls-back to calling color_of.numeric(). Returned color definitions always have default names irrespective of names of x, which is different from the behavior of color_of() methods.

Function fast_color_of_wb() accepts waveband objects and lists of waveband objects. If all wavebands are narrow, it issues a vectotized call to fast_color_of_wl() with a vector of waveband midpoint wavelengths.

Examples

wavelengths <- c(300, 420, 500, 600, NA) # nanometres
color_of(wavelengths)
color_of(waveband(c(300,400)))
color_of(list(blue = waveband(c(400,480)), red = waveband(c(600,700))))
color_of(numeric())
color_of(NA_real_)

color_of(sun.spct)

Coarse-grained comparison of two spectra

Description

Compare two spectra using a specified summary function pre-applied to wavelength intervals.

Usage

compare_spct(
  x,
  w.band = 10,
  .summary.fun = NULL,
  ...,
  .comparison.fun = `/`,
  returned.value = "spectrum",
  use.hinges = FALSE,
  short.names = TRUE
)

Arguments

x

A collection of two spectral objects of the same type.

w.band

waveband object or a numeric stepsize in nanometres.

.summary.fun

function. The summary function to use. It must be a method accepting object x as first argument.

...

additional named arguments passed down to .summary.fun.

.comparison.fun

function. The comparison function to use.

returned.value

character One of "data.frame", "spectrum", "tagged.spectrum".

use.hinges

logical Flag indicating whether to insert "hinges" into the returned spectrum when tagging it.

short.names

logical Flag indicating whether to use short or long names for wavebands when tagging.

Details

Summaries are computed for each of the wavebands in w.band by applying function .summary.fun separately to each spectrum, after trimming them to the overlapping wavelength region. Next the matching summaries are compared by means of .comparison.fun. Both the summaries and the result of the comparison are returned. Columns containing summary values are named by concatenating the name each member spectrum with the name of the argument passed to .summary.fun.

Tagging is useful for plotting using wavelength based colours, or when names for wavebands are used as annotations. When tagging is requested, the spectrum is passed to method tag with use.hinges and short.names as additional arguments.

Value

A generic_spct, tagged or not with the wavebdans, or a data.frame object containing the summary values per waveband for each spectrum and the result of applying the comparison function to these summaries.

Examples

compare_spct(source_mspct(list(sun1 = sun.spct, sun2 = sun.spct * 2)))
compare_spct(source_mspct(list(sun1 = sun.spct, sun2 = sun.spct * 2)),
             w.band = NULL)
compare_spct(source_mspct(list(sun1 = sun.spct, sun2 = sun.spct * 2)),
             w.band = list(waveband(c(640, 650)), waveband(c(720, 740))))

compare_spct(filter_mspct(list(pet = polyester.spct,
                               yllw = yellow_gel.spct)),
             w.band = 50,
             .comparison.fun = `<`)

head(
  compare_spct(source_mspct(list(sun1 = sun.spct, sun2 = sun.spct * 2)),
               returned.value = "data.frame")
)
compare_spct(source_mspct(list(sun1 = sun.spct, sun2 = sun.spct * 2)),
             returned.value = "tagged.spectrum")
compare_spct(source_mspct(list(sun1 = sun.spct, sun2 = sun.spct * 2)),
             returned.value = "tagged.spectrum",
             use.hinges = TRUE)

Ten-degree cone fundamentals

Description

A dataset containing wavelengths at a 1 nm interval (390 nm to 830 nm) and the corresponding response values for a 2 degrees target. Original data from http://www.cvrl.org/ downloaded on 2014-04-29 The variables are as follows:

Usage

cone_fundamentals10.spct

cone_fundamentals10.mspct

Format

A chroma_spct object with 440 rows and 4 variables

An object of class response_mspct (inherits from generic_mspct, list) with 3 rows and 1 columns.

Details

  • w.length (nm)

  • x

  • y

  • z

Value

A chroma_spct object.

A response_mspct object containing the same data in three response_spct objects, one for each of x, y and z.

Note

These data are not from the official CIE on-line distribution but are retained for backwards compatibility. It is recommended to download the latest version from https://cie.co.at/data-tables.

The missing data for z in the NIR have been filled with zeros.

Author(s)

CIE

See Also

Other Visual response data examples: beesxyzCMF.spct, ciev10.spct, ciev2.spct, ciexyzCC10.spct, ciexyzCC2.spct, ciexyzCMF10.spct, ciexyzCMF2.spct

Examples

cone_fundamentals10.spct

Convert the "Tfr.type" attribute

Description

Function to set the "Tfr.type" attribute and simultaneously convert the spectral data to correspond to the new type.

Usage

convertTfrType(x, Tfr.type = NULL)

Arguments

x

a filter_spct, object_spct, filter_mspct or object_mspct object.

Tfr.type

character One of "internal" or "total".

Details

Internal transmittance, τ\tau, uses as reference the light entering the object while total transmittance, TT, takes the incident light as reference. The conversion is possible only if total reflectance, ρ\rho, is known. Either as spectral data in an object_spct object, a filter_spct object that is "under-the-hood" an object_spct, or if a fixed reflectance factor applicable to all wavelengths is stored in the filter.properties attribute of the filter_spct object.

Conversions are computed as:

τ=Tρ1ρ\tau = \frac{T - \rho}{1 - \rho}

and

T=τ(1ρ)+ρT = \tau * (1 - \rho) + \rho

For the conversion to take place the object passed as argument to x, must contain a column with transmittance data, named Tfr. Any necessary conversion from absorbance A or from Afr into transmittance, must be done before calling convertTfrType().

Value

x if possible, with the value of the "Tfr.type" attribute modified and the values stored in the Tfr variable converted to the new quantity.

Note

if x is not a filter_spct object, x is returned unchanged. If x does not have the "filter.properties" attribute set if it is missing data, x is returned with Tfr set to NA values.

See Also

setTfrType, filter_spct

Examples

getTfrType(polyester.spct)
filter_properties(polyester.spct)
convertTfrType(polyester.spct, Tfr.type = "internal")

Convert the "thickness" attribute of an existing filter_spct object.

Description

Function to set the "thickness" attribute and simultaneously converting the spectral data to correspond to the new thickness.

Usage

convertThickness(x, thickness = NULL)

Arguments

x

a filter_spct, object_spct, filter_mspct or object_mspct object.

thickness

numeric [mm].

Details

For spectral transmittance at a different thickness to be exactly computed, it needs to be based on internal transmittance. This function will apply converTfrType() to x if needed, but to succeed metadata should be available. Please, see convertTfrType.

Value

x possibly with the "thickness" field of the "filter.properties" attribute modified and Tfr or A computed for the requested thickness.

Note

if x is not a filter_spct, object_spct, filter_mspct or object_mspct object or a collection of such objects, x is returned unchanged. If x does not have the "filter.properties" attribute set or has it with missing member data, x is returned with Tfr set to NA values.

See Also

Other time attribute functions: checkTimeUnit(), convertTimeUnit(), getTimeUnit(), setTimeUnit()

Examples

my.spct <- polyester.spct
filter_properties(my.spct)
convertThickness(my.spct, thickness = 250e-6)

Convert the "time.unit" attribute of an existing source_spct object

Description

Function to set the "time.unit" attribute and simultaneously rescaling the spectral data to be expressed using the new time unit as basis of expression. The change is done by reference ('in place').

Usage

convertTimeUnit(x, time.unit = NULL, ...)

Arguments

x

source_spct or response_spct object

time.unit

a character string, either "second", "hour", "day", "exposure" or "none", or a lubridate::duration

...

(currently ignored)

Value

x possibly with the time.unit attribute modified

Note

if x is not a source_spct or a response_spct object, or time.unit is NULL x is returned unchanged, if the existing or new time.unit cannot be converted to a duration, then the returned spectrum will contain NAs.

See Also

Other time attribute functions: checkTimeUnit(), convertThickness(), getTimeUnit(), setTimeUnit()

Examples

my.spct <- sun.spct
my.spct
convertTimeUnit(my.spct, "day")
my.spct

Convolve function for collections of spectra

Description

Convolve function for collections of spectra which applies an operation on all the individual members of the collection(s) of spectra.

Usage

convolve_each(e1, e2, oper = `*`, sep = "_", ...)

Arguments

e1

an object of class generic_mspct or generic_scpt or numeric

e2

an object of class generic_mspct or generic_scpt or numeric

oper

function, usually but not necessarily an operator with two arguments.

sep

character Used when pasting the names of members of e1 and e2 to form the names of members of the returned collection of spectra.

...

additional arguments passed to oper if present.

Note

At least one of e1 and e2 must be a generic_mspct object or derived.

See Also

Other math operators and functions: MathFun, ^.generic_spct(), div-.generic_spct, log(), minus-.generic_spct, mod-.generic_spct, plus-.generic_spct, round(), sign(), slash-.generic_spct, times-.generic_spct


Copy attributes

Description

Copy attributes from x to y. Methods defined for spectral and waveband objects of classes from package 'photobiology'.

Usage

copy_attributes(x, y, which, ...)

## Default S3 method:
copy_attributes(x, y, which = NULL, ...)

## S3 method for class 'generic_spct'
copy_attributes(x, y, which = NULL, which.not = NULL, copy.class = FALSE, ...)

## S3 method for class 'generic_mspct'
copy_attributes(x, y, which = NULL, which.not = NULL, copy.class = FALSE, ...)

## S3 method for class 'waveband'
copy_attributes(x, y, which = NULL, ...)

Arguments

x, y

R objects

which

character Names of attributes to copy, if NULL all those relevant according to the class of x is used as defaul,

...

not used

which.not

character Names of attributes not to be copied. The names passed here are removed from the list for which, which is most useful when we want to modify the default.

copy.class

logical If TRUE class attributes are also copied.

Value

A copy of y with additional attributes set.

Methods (by class)

  • copy_attributes(default): Default for generic function

  • copy_attributes(generic_spct):

  • copy_attributes(generic_mspct):

  • copy_attributes(waveband):


Conversion from counts per second to physical quantities

Description

Conversion of spectral data expressed as cps into irradiance, transmittance or reflectance.

Usage

cps2irrad(x.sample, pre.fun = NULL, missing.pixs = numeric(0), ...)

cps2Rfr(x.sample, x.white, x.black = NULL, dyn.range = NULL)

cps2Tfr(x.sample, x.clear, x.opaque = NULL, dyn.range = NULL)

Arguments

x.sample, x.clear, x.opaque, x.white, x.black

cps_spct objects.

pre.fun

function A function applied to x.sample before conversion.

missing.pixs

integer Index to positions in the detector array or scan missing in x.sample but present in the embedded calibration data. (Use only for emergency recovery of incomplete data!!)

...

Additional arguments passed to pre.fun.

dyn.range

numeric The effective dynamic range of the instrument, if NULL it is automatically set based on integration time bracketing.

Value

A source_spct, filter_spct or reflector_spct object containing the spectral values expressed in physical units.

Note

In contrast to other classes defined in package 'photobiology', class "cps_spct" can have more than one column of cps counts in cases where the intention is to merge these values as part of the processing at the time the calibration is applied. However, being these functions the final step in the conversion to physical units, they accept as input only objects with a single "cps" column, as merging is expected to have been already done.


Calculate deuterium lamp output spectrum from fitted constants

Description

Calculate values by means of a nth degree polynomial from user-supplied constants (for example from a lamp calibration certificate).

Usage

D2_spectrum(w.length, k = photobiology::D2.UV653, fill = NA_real_)

Arguments

w.length

numeric vector of wavelengths (nm) for output

k

a polynom:polynomial object with n constants for the polynomial

fill

if NA, no extrapolation is done, and NA is returned for wavelengths outside the range 190 nm to 450 nm. If NULL then the tails are deleted. If 0 then the tails are set to zero, etc. NA is default.

Value

a dataframe with four numeric vectors with wavelength values (w.length), energy and photon irradiance (s.e.irrad, s.q.irrad) depending on the argument passed to unit.out (s.irrad).

Note

This is function is valid for wavelengths in the range 180 nm to 495 nm, for wavelengths outside this range NAs are returned.

Examples

D2_spectrum(200)
D2_spectrum(170:220)

Data for typical calibration lamps

Description

A dataset containing fitted constants to be used as input for functions D2_spectrum and FEL_spectrum for computing example spectral curves based on fitted polynomials.

Format

A polynom::polynomial object with 6 constants.

Details

An object of class polynom::polynomial.

Author(s)

Lasse Ylianttila (data)

Examples

D2.UV653
as.character(D2.UV653)

CIE D50 illuminant data

Description

A dataset containing wavelengths at a 5 nm interval (300 nm to 830 nm) and the corresponding spectral energy irradiance normalized to 1 at 560 nm. Spectrum approximates the midday solar spectrum at middle latitude as 'corresponds' to the white point of a black body a 6504 K. Original data from CIE downloaded on 2024-11-30 The variables are as follows:

Usage

D50.illuminant.spct

Format

A source spectrum with 531 rows and 2 variables

  • w.length (nm)

  • s.e.irrad (rel. units)

Note

This and other CIE illuminant spectra can be downloaded from https://cie.co.at/data-tables as .CSV files.

Author(s)

CIE

References

CIE 2022, Relative spectral power distributions of CIE standard illuminants A, D65 and D50 (wavelengths in standard air) (data table), International Commission on Illumination (CIE), Vienna, Austria, doi:10.25039/CIE.DS.etgmuqt5.

See Also

Other Spectral data examples: A.illuminant.spct, D65.illuminant.spct, Ler_leaf.spct, black_body.spct, ccd.spct, clear.spct, filter_cps.mspct, green_leaf.spct, phenylalanine.spct, photodiode.spct, sun.spct, sun_daily.spct, sun_evening.spct, two_filters.spct, two_sensors.mspct, water.spct, white_led.source_spct

Examples

D50.illuminant.spct

CIE D65 illuminant data

Description

A dataset containing wavelengths at a 5 nm interval (300 nm to 830 nm) and the corresponding spectral energy irradiance normalized to 1 at 560 nm. Spectrum approximates the midday solar spectrum at middle latitude as 'corresponds' to the white point of a black body a 6504 K. Original data from CIE downloaded on 2024-11-30 The variables are as follows:

Usage

D65.illuminant.spct

Format

A source spectrum with 531 rows and 2 variables

  • w.length (nm)

  • s.e.irrad (rel. units)

Note

This and other CIE illuminant spectra can be downloaded from https://cie.co.at/data-tables as .CSV files.

Author(s)

CIE

References

CIE 2022, CIE standard illuminant D65, International Commission on Illumination (CIE), Vienna, Austria, doi:10.25039/CIE.DS.hjfjmt59.

See Also

Other Spectral data examples: A.illuminant.spct, D50.illuminant.spct, Ler_leaf.spct, black_body.spct, ccd.spct, clear.spct, filter_cps.mspct, green_leaf.spct, phenylalanine.spct, photodiode.spct, sun.spct, sun_daily.spct, sun_evening.spct, two_filters.spct, two_sensors.mspct, water.spct, white_led.source_spct

Examples

D65.illuminant.spct

Defunct functions and methods

Description

Functions listed here have been removed or deleted, and temporarily replaced by stubs that report this when they are called.

Usage

f_mspct(...)

mutate_mspct(...)

calc_filter_multipliers(...)

T2T(...)

getAfrType(...)

setAfrType(...)

sample_spct(...)

sample_mspct(...)

Arguments

...

ignored

Note

Function f_mspct() has been renamed msdply().

Function mutate_mspct() has been renamed msmsply().

Function calc_filter_multipliers() has been removed.

Function calc_filter_multipliers() has been removed.

Method getAfrType() has been removed.

Method setAfrType() has been removed.

Function sample_spct() has been removed.

Function sample_mspct() has been removed.


Remove spikes from spectrum

Description

Function that returns an R object with observations corresponding to spikes replaced by values computed from neighboring pixels. Spikes are values in spectra that are unusually high compared to neighbors. They are usually individual values or very short runs of similar "unusual" values. Spikes caused by cosmic radiation are a frequent problem in Raman spectra. Another source of spikes are "hot pixels" in CCD and diode array detectors.

Usage

despike(x, z.threshold, max.spike.width, window.width, method, na.rm, ...)

## Default S3 method:
despike(
  x,
  z.threshold = NA,
  max.spike.width = NA,
  window.width = NA,
  method = "run.mean",
  na.rm = FALSE,
  ...
)

## S3 method for class 'numeric'
despike(
  x,
  z.threshold = 9,
  max.spike.width = 8,
  window.width = 11,
  method = "run.mean",
  na.rm = FALSE,
  ...
)

## S3 method for class 'data.frame'
despike(
  x,
  z.threshold = 9,
  max.spike.width = 8,
  window.width = 11,
  method = "run.mean",
  na.rm = FALSE,
  ...,
  y.var.name = NULL,
  var.name = y.var.name
)

## S3 method for class 'generic_spct'
despike(
  x,
  z.threshold = 9,
  max.spike.width = 8,
  window.width = 11,
  method = "run.mean",
  na.rm = FALSE,
  y.var.name = NULL,
  var.name = y.var.name,
  ...
)

## S3 method for class 'source_spct'
despike(
  x,
  z.threshold = 9,
  max.spike.width = 8,
  window.width = 11,
  method = "run.mean",
  na.rm = FALSE,
  unit.out = getOption("photobiology.radiation.unit", default = "energy"),
  ...
)

## S3 method for class 'response_spct'
despike(
  x,
  z.threshold = 9,
  max.spike.width = 8,
  window.width = 11,
  method = "run.mean",
  na.rm = FALSE,
  unit.out = getOption("photobiology.radiation.unit", default = "energy"),
  ...
)

## S3 method for class 'filter_spct'
despike(
  x,
  z.threshold = 9,
  max.spike.width = 8,
  window.width = 11,
  method = "run.mean",
  na.rm = FALSE,
  filter.qty = getOption("photobiology.filter.qty", default = "transmittance"),
  ...
)

## S3 method for class 'reflector_spct'
despike(
  x,
  z.threshold = 9,
  max.spike.width = 8,
  window.width = 11,
  method = "run.mean",
  na.rm = FALSE,
  ...
)

## S3 method for class 'solute_spct'
despike(
  x,
  z.threshold = 9,
  max.spike.width = 8,
  window.width = 11,
  method = "run.mean",
  na.rm = FALSE,
  ...
)

## S3 method for class 'cps_spct'
despike(
  x,
  z.threshold = 9,
  max.spike.width = 8,
  window.width = 11,
  method = "run.mean",
  na.rm = FALSE,
  ...
)

## S3 method for class 'raw_spct'
despike(
  x,
  z.threshold = 9,
  max.spike.width = 8,
  window.width = 11,
  method = "run.mean",
  na.rm = FALSE,
  ...
)

## S3 method for class 'generic_mspct'
despike(
  x,
  z.threshold = 9,
  max.spike.width = 8,
  window.width = 11,
  method = "run.mean",
  na.rm = FALSE,
  ...,
  y.var.name = NULL,
  var.name = y.var.name,
  .parallel = FALSE,
  .paropts = NULL
)

## S3 method for class 'source_mspct'
despike(
  x,
  z.threshold = 9,
  max.spike.width = 8,
  window.width = 11,
  method = "run.mean",
  na.rm = FALSE,
  unit.out = getOption("photobiology.radiation.unit", default = "energy"),
  ...,
  .parallel = FALSE,
  .paropts = NULL
)

## S3 method for class 'response_mspct'
despike(
  x,
  z.threshold = 9,
  max.spike.width = 8,
  window.width = 11,
  method = "run.mean",
  na.rm = FALSE,
  unit.out = getOption("photobiology.radiation.unit", default = "energy"),
  ...,
  .parallel = FALSE,
  .paropts = NULL
)

## S3 method for class 'filter_mspct'
despike(
  x,
  z.threshold = 9,
  max.spike.width = 8,
  window.width = 11,
  method = "run.mean",
  na.rm = FALSE,
  filter.qty = getOption("photobiology.filter.qty", default = "transmittance"),
  ...,
  .parallel = FALSE,
  .paropts = NULL
)

## S3 method for class 'reflector_mspct'
despike(
  x,
  z.threshold = 9,
  max.spike.width = 8,
  window.width = 11,
  method = "run.mean",
  na.rm = FALSE,
  ...,
  .parallel = FALSE,
  .paropts = NULL
)

## S3 method for class 'solute_mspct'
despike(
  x,
  z.threshold = 9,
  max.spike.width = 8,
  window.width = 11,
  method = "run.mean",
  na.rm = FALSE,
  ...,
  .parallel = FALSE,
  .paropts = NULL
)

## S3 method for class 'cps_mspct'
despike(
  x,
  z.threshold = 9,
  max.spike.width = 8,
  window.width = 11,
  method = "run.mean",
  na.rm = FALSE,
  ...,
  .parallel = FALSE,
  .paropts = NULL
)

## S3 method for class 'raw_mspct'
despike(
  x,
  z.threshold = 9,
  max.spike.width = 8,
  window.width = 11,
  method = "run.mean",
  na.rm = FALSE,
  ...,
  .parallel = FALSE,
  .paropts = NULL
)

Arguments

x

an R object

z.threshold

numeric Modified Z values larger than z.threshold are considered to correspond to spikes.

max.spike.width

integer Wider regions with high Z values are not detected as spikes.

window.width

integer. The full width of the window used for the running mean used as replacement.

method

character The name of the method: "run.mean" is running mean as described in Whitaker and Hayes (2018); "adj.mean" is mean of adjacent neighbors (isolated bad pixels only).

na.rm

logical indicating whether NA values should be treated as spikes and replaced.

...

Arguments passed by name to find_spikes().

var.name, y.var.name

character Names of columns where to look for spikes to remove.

unit.out

character One of "energy" or "photon"

filter.qty

character One of "transmittance" or "absorbance"

.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.

Details

Spikes are detected based on a modified Z score calculated from the differenced spectrum. The Z threshold used should be adjusted to the characteristics of the input and desired sensitivity. The lower the threshold the more stringent the test becomes, resulting in most cases in more spikes being detected. A modified version of the algorithm is used if a value different from NULL is passed as argument to max.spike.width. In such a case, an additional step filters out broader spikes (or falsely detected steep slopes) from the returned values.

Simple interpolation replaces values of isolated bad pixels by the mean of their two closest neighbors. The running mean approach allows the replacement of short runs of bad pixels by the running mean of neighboring pixels within a window of user-specified width. The first approach works well for spectra from array spectrometers to correct for hot and dead pixels in an instrument. The second approach is most suitable for Raman spectra in which spikes triggered by radiation are wider than a single pixel but usually not more than five pixels wide.

When the argument passed to x contains multiple spectra, the spikes are searched for and replaced in each spectrum independently of other spectra.

Value

A copy of the object passed as argument to x with values detected as spikes replaced by a local average of adjacent neighbors outside the spike.

Methods (by class)

  • despike(default): Default returning always NA.

  • despike(numeric): Default function usable on numeric vectors.

  • despike(data.frame): Method for "data.frame" objects.

  • despike(generic_spct): Method for "generic_spct" objects.

  • despike(source_spct): Method for "source_spct" objects.

  • despike(response_spct): Method for "response_spct" objects.

  • despike(filter_spct): Method for "filter_spct" objects.

  • despike(reflector_spct): Method for "reflector_spct" objects.

  • despike(solute_spct): Method for "solute_spct" objects.

  • despike(cps_spct): Method for "cps_spct" objects.

  • despike(raw_spct): Method for "raw_spct" objects.

  • despike(generic_mspct): Method for "generic_mspct" objects.

  • despike(source_mspct): Method for "source_mspct" objects.

  • despike(response_mspct): Method for "cps_mspct" objects.

  • despike(filter_mspct): Method for "filter_mspct" objects.

  • despike(reflector_mspct): Method for "reflector_mspct" objects.

  • despike(solute_mspct): Method for "solute_mspct" objects.

  • despike(cps_mspct): Method for "cps_mspct" objects.

  • despike(raw_mspct): Method for "raw_mspct" objects.

Note

Current algorithm misidentifies steep smooth slopes as spikes, so manual inspection is needed together with adjustment by trial and error of a suitable argument value for z.threshold.

See Also

See the documentation for find_spikes and replace_bad_pixs for details of the algorithm and implementation.

Examples

white_led.raw_spct[120:125, ]

# find and replace spike at 245.93 nm
despike(white_led.raw_spct,
        z.threshold = 10,
        window.width = 25)[120:125, ]

Diffraction

Description

Diffraction of optical radiation passing through a single slit can be computed with function diffraction_single_slit(), which implements Fraunhofer's equation. Diffraction plus interference for a pair of slits can be computed with diffraction_double_slit().

Usage

diffraction_single_slit(w.length, slit.width, angle)

diffraction_double_slit(w.length, slit.width, slit.distance, angle)

Arguments

w.length

numeric Wavelength (nm).

slit.width

numeric Width of the slit (m).

angle

numeric vector Angle (radians).

slit.distance

numeric Distance between the centres of the two slits (m).

Value

A numeric vector of the same length as angle, containing relative intensities.

Examples

diffraction_single_slit(w.length = 550,
                             slit.width = 1e-5,
                             angle = 0)

# use odd number for length.out so that 0 is in the sequence
angles <- pi * seq(from = -1/2, to = 1/2, length.out = 501)

plot(angles,
     diffraction_single_slit(w.length = 550, # 550 nm
                             slit.width = 6e-6, # 6 um
                             angle = angles),
     type = "l",
     ylab = "Relative irradiance (/1)",
     xlab = "Angle (radian)")

plot(angles,
     diffraction_double_slit(w.length = 550, # 550 nm
                             slit.width = 6e-6, # 6 um
                             slit.distance = 18e-6, # 18 um
                             angle = angles),
     type = "l",
     ylab = "Relative irradiance (/1)",
     xlab = "Angle (radian)")

Dimensions of an Object

Description

Retrieve or set the dimension of an object.

Usage

## S3 method for class 'generic_mspct'
dim(x)

## S3 replacement method for class 'generic_mspct'
dim(x) <- value

Arguments

x

A generic_mspct object or of a derived class.

value

Either NULL or a numeric vector, which is coerced to integer (by truncation).

Value

Either NULL or a numeric vector, which is coerced to integer (by truncation).


Divide two spectra, even if the wavelengths values differ

Description

The wavelength vectors of the two spectra are merged, and the missing spectral values are calculated by interpolation. After this, the two spectral values at each wavelength are operated upon.

Usage

div_spectra(
  w.length1,
  w.length2 = NULL,
  s.irrad1,
  s.irrad2,
  trim = "union",
  na.rm = FALSE
)

Arguments

w.length1

numeric vector of wavelength (nm) of denominator.

w.length2

numeric vector of wavelength (nm) of divisor.

s.irrad1

a numeric vector of spectral values of denominator.

s.irrad2

a numeric vector of spectral values of divisor.

trim

a character string with value "union" or "intersection".

na.rm

a logical value, if TRUE, not the default, NAs in the input are replaced with zeros.

Details

If trim=="union" spectral values are calculated for the whole range of wavelengths covered by at least one of the input spectra, and missing values are set in each input spectrum to zero before addition. If trim=="intersection" then the range of wavelengths covered by both input spectra is returned, and the non-overlapping regions discarded. If w.length2==NULL, it is assumed that both spectra are measured at the same wavelengths, and a simple addition is used, ensuring fast calculation.

Value

a dataframe with two numeric variables.

w.length

A numeric vector with the wavelengths (nm) obtained by "fusing" w.length1 and w.length2. w.length contains all the unique vales, sorted in ascending order.

s.irrad

A numeric vector with the ratio between the two spectral values at each wavelength.

See Also

Other low-level functions operating on numeric vectors.: as_energy(), as_quantum_mol(), calc_multipliers(), energy_irradiance(), energy_ratio(), insert_hinges(), integrate_xy(), interpolate_spectrum(), irradiance(), l_insert_hinges(), oper_spectra(), photon_irradiance(), photon_ratio(), photons_energy_ratio(), prod_spectra(), s_e_irrad2rgb(), split_energy_irradiance(), split_photon_irradiance(), subt_spectra(), sum_spectra(), trim_tails(), v_insert_hinges(), v_replace_hinges()

Examples

head(sun.data)
one.data <- with(sun.data, div_spectra(w.length, w.length, s.e.irrad, s.e.irrad))
head(one.data)
tail(one.data)

Arithmetic Operators

Description

Integer-division operator for generic spectra.

Usage

## S3 method for class 'generic_spct'
e1 %/% e2

Arguments

e1

an object of class "generic_spct"

e2

an object of class "generic_spct"

See Also

Other math operators and functions: MathFun, ^.generic_spct(), convolve_each(), log(), minus-.generic_spct, mod-.generic_spct, plus-.generic_spct, round(), sign(), slash-.generic_spct, times-.generic_spct


Drop user columns

Description

Remove from spectral object additional columns that are user defined.

Usage

drop_user_cols(x, keep.also, ...)

## Default S3 method:
drop_user_cols(x, keep.also = NULL, ...)

## S3 method for class 'generic_spct'
drop_user_cols(x, keep.also, ...)

## S3 method for class 'source_spct'
drop_user_cols(x, keep.also = NULL, ...)

## S3 method for class 'response_spct'
drop_user_cols(x, keep.also = NULL, ...)

## S3 method for class 'object_spct'
drop_user_cols(x, keep.also = NULL, ...)

## S3 method for class 'filter_spct'
drop_user_cols(x, keep.also = NULL, ...)

## S3 method for class 'reflector_spct'
drop_user_cols(x, keep.also = NULL, ...)

## S3 method for class 'solute_spct'
drop_user_cols(x, keep.also = NULL, ...)

## S3 method for class 'chroma_spct'
drop_user_cols(x, keep.also = NULL, ...)

## S3 method for class 'calibration_spct'
drop_user_cols(x, keep.also = NULL, ...)

## S3 method for class 'cps_spct'
drop_user_cols(x, keep.also = NULL, ...)

## S3 method for class 'raw_spct'
drop_user_cols(x, keep.also = NULL, ...)

## S3 method for class 'generic_mspct'
drop_user_cols(x, keep.also = NULL, ...)

Arguments

x

An R object

keep.also

character Additionlal columns to preserve.

...

needed to allow derivation.

Value

A copy of x possibly with some columns removed.

Methods (by class)

  • drop_user_cols(default):

  • drop_user_cols(generic_spct):

  • drop_user_cols(source_spct):

  • drop_user_cols(response_spct):

  • drop_user_cols(object_spct):

  • drop_user_cols(filter_spct):

  • drop_user_cols(reflector_spct):

  • drop_user_cols(solute_spct):

  • drop_user_cols(chroma_spct):

  • drop_user_cols(calibration_spct):

  • drop_user_cols(cps_spct):

  • drop_user_cols(raw_spct):

  • drop_user_cols(generic_mspct):

See Also

Other experimental utility functions: collect2mspct(), thin_wl(), uncollect2spct()


Energy fluence

Description

Energy fluence for one or more wavebands of a light source spectrum and a duration of the exposure.

Usage

e_fluence(
  spct,
  w.band,
  exposure.time,
  scale.factor,
  wb.trim,
  use.cached.mult,
  use.hinges,
  allow.scaled,
  ...
)

## Default S3 method:
e_fluence(
  spct,
  w.band,
  exposure.time,
  scale.factor,
  wb.trim,
  use.cached.mult,
  use.hinges,
  allow.scaled,
  ...
)

## S3 method for class 'source_spct'
e_fluence(
  spct,
  w.band = NULL,
  exposure.time,
  scale.factor = 1,
  wb.trim = getOption("photobiology.waveband.trim", default = TRUE),
  use.cached.mult = getOption("photobiology.use.cached.mult", default = FALSE),
  use.hinges = NULL,
  allow.scaled = FALSE,
  naming = "default",
  ...
)

## S3 method for class 'source_mspct'
e_fluence(
  spct,
  w.band = NULL,
  exposure.time,
  scale.factor = 1,
  wb.trim = getOption("photobiology.waveband.trim", default = TRUE),
  use.cached.mult = getOption("photobiology.use.cached.mult", default = FALSE),
  use.hinges = NULL,
  allow.scaled = FALSE,
  ...,
  attr2tb = NULL,
  idx = "spct.idx",
  .parallel = FALSE,
  .paropts = NULL
)

Arguments

spct

an R object

w.band

a list of waveband objects or a waveband object

exposure.time

lubridate::duration object.

scale.factor

numeric vector of length 1, or length equal to that of w.band. Numeric multiplier applied to returned values.

wb.trim

logical if TRUE wavebands crossing spectral data boundaries are trimmed, if FALSE, they are discarded

use.cached.mult

logical indicating whether multiplier values should be cached between calls

use.hinges

logical Flag indicating whether to insert "hinges" into the spectral data before integration so as to reduce interpolation errors at the boundaries of the wavebands.

allow.scaled

logical indicating whether scaled or normalized spectra as argument to spct are flagged as an error

...

other arguments (possibly ignored)

naming

character one of "long", "default", "short" or "none". Used to select the type of names to assign to returned value.

attr2tb

character vector, see add_attr2tb for the syntax for attr2tb passed as is to formal parameter col.names.

idx

character Name of the column with the names of the members of the collection of spectra.

.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

One numeric value for each waveband with no change in scale factor, with name attribute set to the name of each waveband unless a named list is supplied in which case the names of the list elements are used. The exposure.time is copied to the output as an attribute. Units are as follows: (J) joules per exposure.

Methods (by class)

  • e_fluence(default): Default for generic function

  • e_fluence(source_spct): Calculate energy fluence from a source_spct object and the duration of the exposure.

  • e_fluence(source_mspct): Calculates energy fluence from a source_mspct object.

Note

The last two parameters control speed optimizations. The defaults should be suitable in most cases. If you will use repeatedly the same SWFs on many spectra measured at exactly the same wavelengths you may obtain some speed up by setting use.cached.mult=TRUE. However, be aware that you are responsible for ensuring that the wavelengths are the same in each call, as the only test done is for the length of the w.length vector.

See Also

Other irradiance functions: e_irrad(), fluence(), irrad(), q_fluence(), q_irrad()

Examples

library(lubridate)
e_fluence(sun.spct, w.band = waveband(c(400,700)),
          exposure.time = lubridate::duration(3, "minutes") )

Energy:energy fraction

Description

This function returns the energy fraction for a given pair of wavebands of a light source spectrum.

Usage

e_fraction(
  spct,
  w.band.num,
  w.band.denom,
  scale.factor,
  wb.trim,
  use.cached.mult,
  use.hinges,
  ...
)

## Default S3 method:
e_fraction(
  spct,
  w.band.num,
  w.band.denom,
  scale.factor,
  wb.trim,
  use.cached.mult,
  use.hinges,
  ...
)

## S3 method for class 'source_spct'
e_fraction(
  spct,
  w.band.num = NULL,
  w.band.denom = NULL,
  scale.factor = 1,
  wb.trim = getOption("photobiology.waveband.trim", default = TRUE),
  use.cached.mult = FALSE,
  use.hinges = NULL,
  quantity = "total",
  naming = "short",
  name.tag = NULL,
  ...
)

## S3 method for class 'source_mspct'
e_fraction(
  spct,
  w.band.num = NULL,
  w.band.denom = NULL,
  scale.factor = 1,
  wb.trim = getOption("photobiology.waveband.trim", default = TRUE),
  use.cached.mult = FALSE,
  use.hinges = NULL,
  quantity = "total",
  naming = "short",
  name.tag = ifelse(naming != "none", "[e:e]", ""),
  ...,
  attr2tb = NULL,
  idx = "spct.idx",
  .parallel = FALSE,
  .paropts = NULL
)

Arguments

spct

source_spct

w.band.num

waveband object or a list of waveband objects used to compute the numerator(s) and denominator(s) of the fraction(s).

w.band.denom

waveband object or a list of waveband objects used to compute the denominator(s) of the fraction(s).

scale.factor

numeric vector of length 1, or length equal to that of w.band. Numeric multiplier applied to returned values.

wb.trim

logical if TRUE wavebands crossing spectral data boundaries are trimmed, if FALSE, they are discarded

use.cached.mult

logical Flag telling whether multiplier values should be cached between calls.

use.hinges

logical Flag indicating whether to insert "hinges" into the spectral data before integration so as to reduce interpolation errors at the boundaries of the wavebands.

...

other arguments (possibly used by derived methods).

quantity

character One of "total", "average" or "mean".

naming

character one of "long", "default", "short" or "none". Used to select the type of names to assign to returned value.

name.tag

character Used to tag the name of the returned values.

attr2tb

character vector, see add_attr2tb for the syntax for attr2tb passed as is to formal parameter col.names.

idx

character Name of the column with the names of the members of the collection of spectra.

.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.

Details

With the default quantity = "total" the fraction is based on two energy irradiances, one computed for each waveband.

E(s,wbnum)E(s,wbdenom)+E(s,wbnum)\frac{E(s, wb_\mathrm{num})}{E(s, wb_\mathrm{denom}) + E(s, wb_\mathrm{num})}

If the argument is set to quantity = "mean" or quantity = "average" the ratio is based on two mean spectral energy irradiances, one computed for each waveband.

Qλ(s,wbnum)Qλ(s,wbdenom)+Qλ(s,wbnum)\frac{\overline{Q_\lambda}(s, wb_\mathrm{num})}{\overline{Q_\lambda}(s, wb_\mathrm{denom}) + \overline{Q_\lambda}(s, wb_\mathrm{num})}

Only if the wavelength expanse of the two wavebands is the same, these two ratios are numerically identical.

Value

In the case of methods for individual spectra, a numeric vector with name attribute set. The name is based on the name of the wavebands unless a named list of wavebands is supplied in which case the names of the list elements are used. "[e:e]" is appended if quantity = "total" and "[e(wl):e(wl)]" if quantity = "mean" or quantity = "average".

A data.frame is returned in the case of collections of spectra, containing one column for each fraction definition, an index column with the names of the spectra, and optionally additional columns with metadata values retrieved from the attributes of the member spectra.

Fraction definitions are "assembled" from the arguments passed to w.band.num and w.band.denom. If both arguments are lists of waveband definitions, with an equal number of members, then the wavebands are paired to obtain as many fractions as the number of wavebands in each list. Recycling for wavebands takes place when the number of denominator and numerator wavebands differ.

Methods (by class)

  • e_fraction(default): Default for generic function

  • e_fraction(source_spct): Method for source_spct objects

  • e_fraction(source_mspct): Calculates energy:energy fraction from a source_mspct object.

Note

Recycling for wavebands takes place when the number of denominator and denominator wavebands differ. The last two parameters control speed optimizations. The defaults should be suitable in most cases. If you will use repeatedly the same SWFs on many spectra measured at exactly the same wavelengths you may obtain some speed up by setting use.cached.mult=TRUE. However, be aware that you are responsible for ensuring that the wavelengths are the same in each call, as the only test done is for the length of the w.length vector.

See Also

Other photon and energy ratio functions: e_ratio(), eq_ratio(), q_fraction(), q_ratio(), qe_ratio()

Examples

e_fraction(sun.spct, new_waveband(400,700), new_waveband(400,500))

Energy irradiance

Description

Energy irradiance for one or more wavebands of a light source spectrum.

Usage

e_irrad(
  spct,
  w.band,
  quantity,
  time.unit,
  scale.factor,
  wb.trim,
  use.cached.mult,
  use.hinges,
  allow.scaled,
  ...
)

## Default S3 method:
e_irrad(
  spct,
  w.band,
  quantity,
  time.unit,
  scale.factor,
  wb.trim,
  use.cached.mult,
  use.hinges,
  allow.scaled,
  ...
)

## S3 method for class 'source_spct'
e_irrad(
  spct,
  w.band = NULL,
  quantity = "total",
  time.unit = NULL,
  scale.factor = 1,
  wb.trim = getOption("photobiology.waveband.trim", default = TRUE),
  use.cached.mult = getOption("photobiology.use.cached.mult", default = FALSE),
  use.hinges = NULL,
  allow.scaled = !quantity %in% c("average", "mean", "total"),
  naming = "default",
  return.tb = FALSE,
  ...
)

## S3 method for class 'source_mspct'
e_irrad(
  spct,
  w.band = NULL,
  quantity = "total",
  time.unit = NULL,
  scale.factor = 1,
  wb.trim = getOption("photobiology.waveband.trim", default = TRUE),
  use.cached.mult = getOption("photobiology.use.cached.mult", default = FALSE),
  use.hinges = NULL,
  allow.scaled = !quantity %in% c("average", "mean", "total"),
  naming = "default",
  ...,
  attr2tb = NULL,
  idx = "spct.idx",
  .parallel = FALSE,
  .paropts = NULL
)

Arguments

spct

an R object.

w.band

a list of waveband objects or a waveband object.

quantity

character string One of "total", "average" or "mean", "contribution", "contribution.pc", "relative" or "relative.pc".

time.unit

character or lubridate::duration object.

scale.factor

numeric vector of length 1, or length equal to that of w.band. Numeric multiplier applied to returned values.

wb.trim

logical if TRUE wavebands crossing spectral data boundaries are trimmed, if FALSE, they are discarded.

use.cached.mult

logical indicating whether multiplier values should be cached between calls.

use.hinges

logical Flag indicating whether to insert "hinges" into the spectral data before integration so as to reduce interpolation errors at the boundaries of the wavebands.

allow.scaled

logical indicating whether scaled or normalized spectra as argument to spct are flagged as an error.

...

other arguments (possibly used by derived methods).

naming

character one of "long", "default", "short" or "none". Used to select the type of names to assign to returned value.

return.tb

logical Flag forcing a tibble to be always returned, even for a single spectrum as argumnet to spct. The default is FALSE for backwards compatibility.

attr2tb

character vector, see add_attr2tb for the syntax for attr2tb passed as is to formal parameter col.names.

idx

character Name of the column with the names of the members of the collection of spectra.

.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 named numeric vector in the case of a _spct object containing a single spectrum and return.tb = FALSE. The vector has one member one value for each waveband passed to parameter w.band. In all other cases a tibble, containing one column for each waveband object, an index column with the names of the spectra, and optionally additional columns with metadata values retrieved from the attributes of the member spectra.

By default values are only integrated, but depending on the argument passed to parameter quantity they can be re-expressed as relative fractions or percentages. In the case of vector output, names attribute is set to the name of the corresponding waveband unless a named list is supplied in which case the names of the list members are used. The time.unit attribute is copied from the spectrum object to the output. Units are as follows: If units are absolute and time.unit is second, [W m-2 nm-1] -> [W m-2] If time.unit is day, [J d-1 m-2 nm-1] -> [J m-2]; if units are relative, fraction of one or percent.

Methods (by class)

  • e_irrad(default): Default for generic function

  • e_irrad(source_spct): Calculates energy irradiance from a source_spct object.

  • e_irrad(source_mspct): Calculates energy irradiance from a source_mspct object.

Note

The last two parameters control speed optimizations. The defaults should be suitable in most cases. If you will use repeatedly the same SWFs on many spectra measured at exactly the same wavelengths you may obtain some speed up by setting use.cached.mult=TRUE. However, be aware that you are responsible for ensuring that the wavelengths are the same in each call, as the only test done is for the length of the w.length vector.

See Also

Other irradiance functions: e_fluence(), fluence(), irrad(), q_fluence(), q_irrad()

Examples

e_irrad(sun.spct, waveband(c(400,700)))
e_irrad(sun.spct, split_bands(c(400,700), length.out = 3))
e_irrad(sun.spct, split_bands(c(400,700), length.out = 3),
        quantity = "total")
e_irrad(sun.spct, split_bands(c(400,700), length.out = 3),
        quantity = "average")
e_irrad(sun.spct, split_bands(c(400,700), length.out = 3),
        quantity = "relative")
e_irrad(sun.spct, split_bands(c(400,700), length.out = 3),
        quantity = "relative.pc")
e_irrad(sun.spct, split_bands(c(400,700), length.out = 3),
        quantity = "contribution")
e_irrad(sun.spct, split_bands(c(400,700), length.out = 3),
        quantity = "contribution.pc")

Energy:energy ratio

Description

This function returns the photon ratio for a given pair of wavebands of a light source spectrum.

Usage

e_ratio(
  spct,
  w.band.num,
  w.band.denom,
  scale.factor,
  wb.trim,
  use.cached.mult,
  use.hinges,
  ...
)

## Default S3 method:
e_ratio(
  spct,
  w.band.num,
  w.band.denom,
  scale.factor,
  wb.trim,
  use.cached.mult,
  use.hinges,
  ...
)

## S3 method for class 'source_spct'
e_ratio(
  spct,
  w.band.num = NULL,
  w.band.denom = NULL,
  scale.factor = 1,
  wb.trim = getOption("photobiology.waveband.trim", default = TRUE),
  use.cached.mult = FALSE,
  use.hinges = NULL,
  quantity = "total",
  naming = "short",
  name.tag = NULL,
  ...
)

## S3 method for class 'source_mspct'
e_ratio(
  spct,
  w.band.num = NULL,
  w.band.denom = NULL,
  scale.factor = 1,
  wb.trim = getOption("photobiology.waveband.trim", default = TRUE),
  use.cached.mult = FALSE,
  use.hinges = NULL,
  quantity = "total",
  naming = "short",
  name.tag = ifelse(naming != "none", "[e:e]", ""),
  ...,
  attr2tb = NULL,
  idx = "spct.idx",
  .parallel = FALSE,
  .paropts = NULL
)

Arguments

spct

source_spct

w.band.num

waveband object or a list of waveband objects used to compute the numerator(s) of the ratio(s).

w.band.denom

waveband object or a list of waveband objects used to compute the denominator(s) of the ratio(s).

scale.factor

numeric vector of length 1, or length equal to that of w.band. Numeric multiplier applied to returned values.

wb.trim

logical if TRUE wavebands crossing spectral data boundaries are trimmed, if FALSE, they are discarded

use.cached.mult

logical Flag telling whether multiplier values should be cached between calls.

use.hinges

logical Flag indicating whether to insert "hinges" into the spectral data before integration so as to reduce interpolation errors at the boundaries of the wavebands.

...

other arguments (possibly used by derived methods).

quantity

character One of "total", "average" or "mean".

naming

character one of "long", "default", "short" or "none". Used to select the type of names to assign to returned value.

name.tag

character Used to tag the name of the returned values.

attr2tb

character vector, see add_attr2tb for the syntax for attr2tb passed as is to formal parameter col.names.

idx

character Name of the column with the names of the members of the collection of spectra.

.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.

Details

With the default quantity = "total" the ratio is based on two energy irradiances, one computed for each waveband.

I(s,wbnum)I(s,wbdenom)\frac{I(s, wb_\mathrm{num})}{I(s, wb_\mathrm{denom})}

If the argument is set to quantity = "mean" or quantity = "average" the ratio is based on two mean spectral photon irradiances, one computed for each waveband.

Iλ(s,wbnum)Iλ(s,wbdenom)\frac{\overline{I_\lambda}(s, wb_\mathrm{num})}{\overline{I_\lambda}(s, wb_\mathrm{denom})}

Only if the wavelength expanse of the two wavebands is the same, these two ratios are numerically identical.

Fraction definitions are "assembled" from the arguments passed to w.band.num and w.band.denom. If both arguments are lists of waveband definitions, with an equal number of members, then the wavebands are paired to obtain as many fractions as the number of wavebands in each list. Recycling for wavebands takes place when the number of denominator and numerator wavebands differ.

The last two parameters control speed optimizations. The defaults should be suitable in most cases. If you will use repeatedly the same SWFs on many spectra measured at exactly the same wavelengths you may obtain some speed up by setting use.cached.mult=TRUE. However, be aware that you are responsible for ensuring that the wavelengths are the same in each call, as the only test done is for the length of the w.length vector.

Value

In the case of methods for individual spectra, a numeric vector with name attribute set. The name is based on the name of the wavebands unless a named list of wavebands is supplied in which case the names of the list elements are used. "[e:e]" is appended if quantity = "total" and "[e(wl):e(wl)]" if quantity = "mean" or quantity = "average".

A data.frame is returned in the case of collections of spectra, containing one column for each fraction definition, an index column with the names of the spectra, and optionally additional columns with metadata values retrieved from the attributes of the member spectra.

Methods (by class)

  • e_ratio(default): Default for generic function

  • e_ratio(source_spct): Method for source_spct objects

  • e_ratio(source_mspct): Calculates energy:energy ratio from a source_mspct object.

Performance

As this method accepts spectra as its input, it computes irradiances before computing the ratios. If you need to compute both ratios and irradiances from several hundreds or thousands of spectra, computing the ratios from previously computed irradiances avoids their repeated computation. A less dramatic, but still important, increase in performance is available when computing in the same function call ratios that share the same denominator.

See Also

Other photon and energy ratio functions: e_fraction(), eq_ratio(), q_fraction(), q_ratio(), qe_ratio()

Examples

e_ratio(sun.spct,
        waveband(c(400,500), wb.name = "Blue"),
        waveband(c(400,700), wb.name = "White"))

Energy-based photo-response

Description

This function returns the mean, total, or contribution of response for each waveband and a response spectrum.

Usage

e_response(
  spct,
  w.band,
  quantity,
  time.unit,
  scale.factor,
  wb.trim,
  use.hinges,
  ...
)

## Default S3 method:
e_response(
  spct,
  w.band,
  quantity,
  time.unit,
  scale.factor,
  wb.trim,
  use.hinges,
  ...
)

## S3 method for class 'response_spct'
e_response(
  spct,
  w.band = NULL,
  quantity = "total",
  time.unit = NULL,
  scale.factor = 1,
  wb.trim = getOption("photobiology.waveband.trim", default = TRUE),
  use.hinges = getOption("photobiology.use.hinges", default = NULL),
  naming = "default",
  ...
)

## S3 method for class 'response_mspct'
e_response(
  spct,
  w.band = NULL,
  quantity = "total",
  time.unit = NULL,
  scale.factor = 1,
  wb.trim = getOption("photobiology.waveband.trim", default = TRUE),
  use.hinges = getOption("photobiology.use.hinges", default = NULL),
  naming = "default",
  ...,
  attr2tb = NULL,
  idx = "spct.idx",
  .parallel = FALSE,
  .paropts = NULL
)

Arguments

spct

an R object.

w.band

waveband or list of waveband objects or a numeric vector of length two. The waveband(s) determine the region(s) of the spectrum that are summarized. If a numeric range is supplied a waveband object is constructed on the fly from it.

quantity

character string One of "total", "average" or "mean", "contribution", "contribution.pc", "relative" or "relative.pc".

time.unit

character or lubridate::duration object.

scale.factor

numeric vector of length 1, or length equal to that of w.band. Numeric multiplier applied to returned values.

wb.trim

logical if TRUE wavebands crossing spectral data boundaries are trimmed, if FALSE, they are discarded.

use.hinges

logical Flag indicating whether to insert "hinges" into the spectral data before integration so as to reduce interpolation errors at the boundaries of the wavebands.

...

other arguments (possibly used by derived methods).

naming

character one of "long", "default", "short" or "none". Used to select the type of names to assign to returned value.

attr2tb

character vector, see add_attr2tb for the syntax for attr2tb passed as is to formal parameter col.names.

idx

character Name of the column with the names of the members of the collection of spectra.

.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 named numeric vector in the case of methods for individual spectra, with one value for each waveband passed to parameter w.band. A data.frame in the case of collections of spectra, containing one column for each waveband object, an index column with the names of the spectra, and optionally additional columns with metadata values retrieved from the attributes of the member spectra.

By default values are only integrated, but depending on the argument passed to parameter quantity they can be re-expressed as relative fractions or percentages. In the case of vector output, names attribute is set to the name of the corresponding waveband unless a named list is supplied in which case the names of the list members are used.

Methods (by class)

  • e_response(default): Default method for generic function

  • e_response(response_spct): Method for response spectra.

  • e_response(response_mspct): Calculates energy response from a response_mspct

Note

The parameter use.hinges controls speed optimization. The defaults should be suitable in most cases. Only the range of wavelengths in the wavebands is used and all BSWFs are ignored.

See Also

Other response functions: q_response(), response()

Examples

e_response(ccd.spct, new_waveband(200,300))
e_response(photodiode.spct)

Convert energy-based quantities into photon-based quantities.

Description

Conversion methods for spectral energy irradiance into spectral photon irradiance and for spectral energy response into spectral photon response.

Usage

e2q(x, action, byref, ...)

## Default S3 method:
e2q(x, action = "add", byref = FALSE, ...)

## S3 method for class 'source_spct'
e2q(x, action = NULL, byref = FALSE, ...)

## S3 method for class 'response_spct'
e2q(x, action = "add", byref = FALSE, ...)

## S3 method for class 'source_mspct'
e2q(x, action = "add", byref = FALSE, ..., .parallel = FALSE, .paropts = NULL)

## S3 method for class 'response_mspct'
e2q(x, action = "add", byref = FALSE, ..., .parallel = FALSE, .paropts = NULL)

Arguments

x

an R object.

action

a character string, one of "add", or "replace".

byref

logical indicating if a new object will be created by reference or a new object returned.

...

not used in current version.

.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.

Details

The converted spectral values are added to or replace the existing spectral values depending on the argument passed to parameter action. Addition is currently not supported for normalized spectra. If the spectrum has been normalized with a recent version of package 'photobiology' the spectrum will be renormalized after conversion using the same arguments as previously.

Methods (by class)

  • e2q(default): Default method

  • e2q(source_spct): Method for spectral irradiance

  • e2q(response_spct): Method for spectral responsiveness

  • e2q(source_mspct): Method for collections of (light) source spectra

  • e2q(response_mspct): Method for collections of response spectra

See Also

Other quantity conversion functions: A2T(), Afr2T(), T2A(), T2Afr(), any2T(), as_quantum(), e2qmol_multipliers(), e2quantum_multipliers(), q2e()


Calculate energy to quantum (mol) multipliers

Description

Multipliers as a function of wavelength, for converting from energy to photon (quantum) molar units.

Usage

e2qmol_multipliers(w.length)

Arguments

w.length

numeric Vector of wavelengths (nm)

Value

A numeric vector of multipliers

See Also

Other quantity conversion functions: A2T(), Afr2T(), T2A(), T2Afr(), any2T(), as_quantum(), e2q(), e2quantum_multipliers(), q2e()

Examples

with(sun.data, e2qmol_multipliers(w.length))

Calculate energy to quantum multipliers

Description

Gives multipliers as a function of wavelength, for converting from energy to photon (quantum) units (number of photons as default, or moles of photons).

Usage

e2quantum_multipliers(w.length, molar = FALSE)

Arguments

w.length

numeric Vector of wavelengths (nm)

molar

logical Flag indicating whether output should be in moles or numbers

Value

A numeric vector of multipliers

See Also

Other quantity conversion functions: A2T(), Afr2T(), T2A(), T2Afr(), any2T(), as_quantum(), e2q(), e2qmol_multipliers(), q2e()

Examples

with(sun.data, e2quantum_multipliers(w.length))
with(sun.data, e2quantum_multipliers(w.length, molar = TRUE))

Enable or disable checks

Description

Choose between protection against errors or faster performance by enabling (the default) or disabling data-consistency and sanity checks.

Usage

enable_check_spct()

disable_check_spct()

set_check_spct(x)

Arguments

x

logical Flag to enable (TRUE), disable (FALSE) or unset (NULL) option.

Details

Checks are applied by default after each operation that modifies the data. This can be excessive in production code. Some functions within this package disable checks for partial computations and apply them to the value they return. It is possible for users to apply this same approach, in which case it is best to schedule the restore of the previous setting using 'on.exit()'.

Value

The previous value of the option, which can be passed as argument to function set_check_spct() to restore the previous state of the option.

See Also

[check_spct()]

Other data validity check functions: check_spct(), check_spectrum(), check_w.length()


Set spectral-data options

Description

Set spectral-data related options easily.

Usage

energy_as_default()

photon_as_default()

quantum_as_default()

Tfr_as_default()

Afr_as_default()

A_as_default()

unset_radiation_unit_default()

unset_filter_qty_default()

unset_user_defaults()

Value

Previous value of the modified option.


Calculate (energy) irradiance from spectral irradiance

Description

Energy irradiance for a waveband from a radiation spectrum, optionally applying a "biological spectral weighting function" or BSWF.

Usage

energy_irradiance(
  w.length,
  s.irrad,
  w.band = NULL,
  unit.in = "energy",
  check.spectrum = TRUE,
  use.cached.mult = FALSE,
  use.hinges = getOption("photobiology.use.hinges", default = NULL)
)

Arguments

w.length

numeric vector of wavelength [nmnm].

s.irrad

numeric vector of spectral irradiances in [Wm2nm1W\,m^{-2}\,nm^{-1}] or [mols1sm2nm1mol\,s^{-1}\,sm^{-2}\,nm^{-1}] as indicated by the argument pased to unit.in.

w.band

waveband.

unit.in

character Allowed values "energy", and "photon", or its alias "quantum".

check.spectrum

logical Flag indicating whether to sanity check input data, default is TRUE.

use.cached.mult

logical Flag indicating whether multiplier values should be cached between calls.

use.hinges

logical Flag indicating whether to insert "hinges" into the spectral data before integration so as to reduce interpolation errors at the boundaries of the wavebands.

Value

A single numeric value with no change in scale factor: [Wm2W\,m^{-2}].

See Also

Other low-level functions operating on numeric vectors.: as_energy(), as_quantum_mol(), calc_multipliers(), div_spectra(), energy_ratio(), insert_hinges(), integrate_xy(), interpolate_spectrum(), irradiance(), l_insert_hinges(), oper_spectra(), photon_irradiance(), photon_ratio(), photons_energy_ratio(), prod_spectra(), s_e_irrad2rgb(), split_energy_irradiance(), split_photon_irradiance(), subt_spectra(), sum_spectra(), trim_tails(), v_insert_hinges(), v_replace_hinges()

Examples

with(sun.data, energy_irradiance(w.length, s.e.irrad))
with(sun.data, energy_irradiance(w.length, s.e.irrad, new_waveband(400,700)))

Energy:energy ratio

Description

Energy irradiance ratio between two wavebands for a radiation spectrum.

Usage

energy_ratio(
  w.length,
  s.irrad,
  w.band.num = NULL,
  w.band.denom = NULL,
  unit.in = "energy",
  check.spectrum = TRUE,
  use.cached.mult = FALSE,
  use.hinges = NULL
)

Arguments

w.length

numeric vector of wavelengths [nmnm].

s.irrad

numeric vector of spectral irradiances in [Wm2nm1W\,m^{-2}\,nm^{-1}] or [mols1sm2nm1mol\,s^{-1}\,sm^{-2}\,nm^{-1}] as indicated by the argument pased to unit.in.

w.band.num

waveband object used to compute the numerator of the ratio.

w.band.denom

waveband object used to compute the denominator of the ratio.

unit.in

character Allowed values "energy", and "photon", or its alias "quantum".

check.spectrum

logical Flag indicating whether to sanity check input data, default is TRUE.

use.cached.mult

logical Flag indicating whether multiplier values should be cached between calls.

use.hinges

logical Flag indicating whether to insert "hinges" into the spectral data before integration so as to reduce interpolation errors at the boundaries of the wavebands.

Value

a single numeric value giving the unitless energy ratio.

Note

The default for both w.band parameters is a waveband covering the whole range of w.length.

See Also

Other low-level functions operating on numeric vectors.: as_energy(), as_quantum_mol(), calc_multipliers(), div_spectra(), energy_irradiance(), insert_hinges(), integrate_xy(), interpolate_spectrum(), irradiance(), l_insert_hinges(), oper_spectra(), photon_irradiance(), photon_ratio(), photons_energy_ratio(), prod_spectra(), s_e_irrad2rgb(), split_energy_irradiance(), split_photon_irradiance(), subt_spectra(), sum_spectra(), trim_tails(), v_insert_hinges(), v_replace_hinges()

Examples

with(sun.data,
     energy_ratio(w.length, s.e.irrad, new_waveband(400,500), new_waveband(400,700)))

Energy:photon ratio

Description

This function returns the energy to mole of photons ratio for each waveband and a light source spectrum.

Usage

eq_ratio(spct, w.band, scale.factor, wb.trim, use.cached.mult, use.hinges, ...)

## Default S3 method:
eq_ratio(spct, w.band, scale.factor, wb.trim, use.cached.mult, use.hinges, ...)

## S3 method for class 'source_spct'
eq_ratio(
  spct,
  w.band = NULL,
  scale.factor = 1,
  wb.trim = getOption("photobiology.waveband.trim", default = TRUE),
  use.cached.mult = FALSE,
  use.hinges = NULL,
  naming = "short",
  name.tag = ifelse(naming != "none", "[e:q]", ""),
  ...
)

## S3 method for class 'source_mspct'
eq_ratio(
  spct,
  w.band = NULL,
  scale.factor = 1,
  wb.trim = getOption("photobiology.waveband.trim", default = TRUE),
  use.cached.mult = FALSE,
  use.hinges = NULL,
  naming = "short",
  name.tag = ifelse(naming != "none", "[e:q]", ""),
  ...,
  attr2tb = NULL,
  idx = "spct.idx",
  .parallel = FALSE,
  .paropts = NULL
)

Arguments

spct

source_spct.

w.band

waveband or list of waveband objects.

scale.factor

numeric vector of length 1, or length equal to that of w.band. Numeric multiplier applied to returned values.

wb.trim

logical if TRUE wavebands crossing spectral data boundaries are trimmed, if FALSE, they are discarded.

use.cached.mult

logical Flag telling whether multiplier values should be cached between calls.

use.hinges

logical Flag indicating whether to insert "hinges" into the spectral data before integration so as to reduce interpolation errors at the boundaries of the wavebands.

...

other arguments (possibly used by derived methods).

naming

character one of "long", "default", "short" or "none". Used to select the type of names to assign to returned value.

name.tag

character Used to tag the name of the returned values.

attr2tb

character vector, see add_attr2tb for the syntax for attr2tb passed as is to formal parameter col.names.

idx

character Name of the column with the names of the members of the collection of spectra.

.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.

Details

The ratio is based on one photon irradiance and one energy irradiance, both computed for the same waveband.

I(s,wb)Q(s,wb)\frac{I(s, wb)}{Q(s, wb)}

The last two parameters control speed optimizations. The defaults should be suitable in most cases. If you will use repeatedly the same SWFs on many spectra measured at exactly the same wavelengths you may obtain some speed up by setting use.cached.mult=TRUE. However, be aware that you are responsible for ensuring that the wavelengths are the same in each call, as the only test done is for the length of the w.length vector.#' @return Computed values are ratios between energy irradiance and photon irradiance for a given waveband. A named numeric vector in the case of methods for individual spectra, with one value for each waveband passed to parameter w.band. A data.frame in the case of collections of spectra, containing one column for each waveband object, an index column with the names of the spectra, and optionally additional columns with metadata values retrieved from the attributes of the member spectra.

By default values are only integrated, but depending on the argument passed to parameter quantity they can be re-expressed as relative fractions or percentages. In the case of vector output, names attribute is set to the name of the corresponding waveband unless a named list is supplied in which case the names of the list members are used, with "[e:q]" prepended. Units [J mol-1].

Value

Computed values are ratios between energy irradiance and photon irradiance for a given waveband. A named numeric vector in the case of methods for individual spectra, with one value for each waveband passed to parameter w.band. A data.frame in the case of multiple spectra, containing one column with ratios for each waveband object, an index column with the names of the spectra, and optionally additional columns with metadata values retrieved from the attributes of the member spectra.

By default values are only integrated, but depending on the argument passed to parameter quantity they are expressed as relative fractions or percentages. In the case of vector output, names attribute is set to the name of the corresponding waveband unless a named list is supplied in which case the names of the list members are used, with "[e:q]" prepended. Units [mol J-1].

Methods (by class)

  • eq_ratio(default): Default for generic function

  • eq_ratio(source_spct): Method for source_spct objects

  • eq_ratio(source_mspct): Calculates energy:photon from a source_mspct object.

Performance

As this method accepts spectra as its input, it computes irradiances before computing the ratios. If you need to compute both ratios and irradiances from several hundreds or thousands of spectra, computing the ratios from previously computed irradiances avoids their repeated computation. A less dramatic, but still important, increase in performance is available when computing in the same function call ratios that share the same denominator.

See Also

Other photon and energy ratio functions: e_fraction(), e_ratio(), q_fraction(), q_ratio(), qe_ratio()

Examples

eq_ratio(sun.spct,
         waveband(c(400,700), wb.name = "White")) # J mol-1
eq_ratio(sun.spct,
         waveband(c(400,700), wb.name = "White"),
         scale.factor = 1e-6) # J umol-1

Extract or replace parts of a spectrum

Description

Just like extraction and replacement with indexes in base R, but preserving the special attributes used in spectral classes and checking for validity of remaining spectral data.

Usage

## S3 method for class 'generic_spct'
x[i, j, drop = NULL]

## S3 method for class 'raw_spct'
x[i, j, drop = NULL]

## S3 method for class 'cps_spct'
x[i, j, drop = NULL]

## S3 method for class 'source_spct'
x[i, j, drop = NULL]

## S3 method for class 'response_spct'
x[i, j, drop = NULL]

## S3 method for class 'filter_spct'
x[i, j, drop = NULL]

## S3 method for class 'reflector_spct'
x[i, j, drop = NULL]

## S3 method for class 'solute_spct'
x[i, j, drop = NULL]

## S3 method for class 'object_spct'
x[i, j, drop = NULL]

## S3 method for class 'chroma_spct'
x[i, j, drop = NULL]

## S3 replacement method for class 'generic_spct'
x[i, j] <- value

## S3 replacement method for class 'generic_spct'
x$name <- value

Arguments

x

spectral object from which to extract element(s) or in which to replace element(s)

i

index for rows,

j

index for columns, specifying elements to extract or replace. Indices are numeric or character vectors or empty (missing) or NULL. Please, see Extract for more details.

drop

logical. If TRUE the result is coerced to the lowest possible dimension. The default is FALSE unless the result is a single column.

value

A suitable replacement value: it will be repeated a whole number of times if necessary and it may be coerced: see the Coercion section. If NULL, deletes the column if a single column is selected.

name

A literal character string or a name (possibly backtick quoted). For extraction, this is normally (see under 'Environments') partially matched to the names of the object.

Details

These methods are just wrappers on the method for data.frame objects which copy the additional attributes used by these classes, and validate the extracted object as a spectral object. When drop is TRUE and the returned object has only one column, then a vector is returned. If the extracted columns are more than one but do not include w.length, a data frame is returned instead of a spectral object.

Value

An object of the same class as x but containing only the subset of rows and columns that are selected. See details for special cases.

Note

If any argument is passed to j, even TRUE, some metadata attributes are removed from the returned object. This is how the extraction operator works with data.frames in R. For the time being we retain this behaviour for spectra, but it may change in the future.

See Also

subset and trim_spct

Examples

sun.spct[sun.spct[["w.length"]] > 400, ]
subset(sun.spct, w.length > 400)

tmp.spct <- sun.spct
tmp.spct[tmp.spct[["s.e.irrad"]] < 1e-5 , "s.e.irrad"] <- 0
e2q(tmp.spct[ , c("w.length", "s.e.irrad")]) # restore data consistency!

Extract or replace members of a collection of spectra

Description

Just like extraction and replacement with indexes for base R lists, but preserving the special attributes used in spectral classes.

Usage

## S3 method for class 'generic_mspct'
x[i, drop = NULL]

## S3 replacement method for class 'generic_mspct'
x[i] <- value

## S3 replacement method for class 'generic_mspct'
x$name <- value

## S3 replacement method for class 'generic_mspct'
x[[name]] <- value

Arguments

x

Collection of spectra object from which to extract member(s) or in which to replace member(s)

i

Index specifying elements to extract or replace. Indices are numeric or character vectors. Please, see Extract for more details.

drop

If TRUE the result is coerced to the lowest possible dimension (see the examples). This only works for extracting elements, not for the replacement.

value

A suitable replacement value: it will be repeated a whole number of times if necessary and it may be coerced: see the Coercion section. If NULL, deletes the column if a single column is selected.

name

A literal character string or a name (possibly backtick quoted). For extraction, this is normally (see under 'Environments') partially matched to the names of the object.

Details

This method is a wrapper on base R's extract method for lists that sets additional attributes used by these classes.

Value

An object of the same class as x but containing only the subset of members that are selected.


Incandescent "FEL" lamp emission spectrum

Description

Calculate values by means of a nth degree polynomial from user-supplied constants (for example from a lamp calibration certificate).

Usage

FEL_spectrum(w.length, k = photobiology::FEL.BN.9101.165, fill = NA_real_)

Arguments

w.length

numeric vector of wavelengths (nm) for output

k

a numeric vector with n constants for the function

fill

if NA, no extrapolation is done, and NA is returned for wavelengths outside the range 250 nm to 900 nm. If NULL then the tails are deleted. If 0 then the tails are set to zero, etc. NA is default.

Value

a dataframe with four numeric vectors with wavelength values (w.length), energy and photon irradiance (s.e.irrad, s.q.irrad) depending on the argument passed to unit.out (s.irrad).

Note

This is function is valid for wavelengths in the range 250 nm to 900 nm, for wavelengths outside this range NAs are returned.

Examples

FEL_spectrum(400)
FEL_spectrum(250:900)

Find peaks in a spectrum

Description

This function finds all peaks (local maxima) in a spectrum, using a user provided size threshold relative to the tallest peak (global maximum) bellow which found peaks are ignored—i.e., not included in the returned value. This is a wrapper built on top of function peaks() from package 'splus2R'.

Usage

find_peaks(x, ignore_threshold = 0, span = 3, strict = TRUE, na.rm = FALSE)

Arguments

x

numeric vector

ignore_threshold

numeric Value between 0.0 and 1.0 indicating the relative size compared to tallest peak threshold below which peaks will be ignored. Negative values set a threshold so that the tallest peaks are ignored, instead of the shortest.

span

integer A peak is defined as an element in a sequence which is greater than all other elements within a window of width span centered at that element. Use NULL for the global peak.

strict

logical If TRUE, an element must be strictly greater than all other values in its window to be considered a peak.

na.rm

logical indicating whether NA values should be stripped before searching for peaks.

Value

A logical vector of the same length as x. Values that are TRUE correspond to local peaks in the data.

Note

This function is a wrapper built on function peaks from splus2R and handles non-finite (including NA) values differently than splus2R::peaks, instead of giving an error they are replaced with the smallest finite value in x.

See Also

peaks

Other peaks and valleys functions: find_spikes(), get_peaks(), peaks(), replace_bad_pixs(), spikes(), valleys(), wls_at_target()

Examples

with(sun.data, w.length[find_peaks(s.e.irrad)])

Find spikes

Description

This function finds spikes in a numeric vector using the algorithm of Whitaker and Hayes (2018). Spikes are values in spectra that are unusually high or low compared to neighbors. They are usually individual values or very short runs of similar "unusual" values. Spikes caused by cosmic radiation are a frequent problem in Raman spectra. Another source of spikes are "hot pixels" in CCD and diode arrays. Other kinds of accidental "outlayers" will be also detected.

Usage

find_spikes(
  x,
  x.is.delta = FALSE,
  z.threshold = 9,
  max.spike.width = 8,
  na.rm = FALSE
)

Arguments

x

numeric vector containing spectral data.

x.is.delta

logical Flag indicating if x contains already differences.

z.threshold

numeric Modified Z values larger than z.threshold are considered to be spikes.

max.spike.width

integer Wider regions with high Z values are not detected as spikes.

na.rm

logical indicating whether NA values should be stripped before searching for spikes.

Details

Spikes are detected based on a modified Z score calculated from the differenced spectrum. The Z threshold used should be adjusted to the characteristics of the input and desired sensitivity. The lower the threshold the more stringent the test becomes, resulting in most cases in more spikes being detected. A modified version of the algorithm is used if a value different from NULL is passed as argument to max.spike.width. In such a case, an additional step filters out broader spikes (or falsely detected steep slopes) from the returned values.

Value

A logical vector of the same length as x. Values that are TRUE correspond to local spikes in the data.

References

Whitaker, D. A.; Hayes, K. (2018) A simple algorithm for despiking Raman spectra. Chemometrics and Intelligent Laboratory Systems, 179, 82-84.

See Also

Other peaks and valleys functions: find_peaks(), get_peaks(), peaks(), replace_bad_pixs(), spikes(), valleys(), wls_at_target()

Examples

with(white_led.raw_spct,
     which(find_spikes(counts_3, z.threshold = 30)))

Find wavelength values in a spectrum

Description

Find wavelength values corresponding to a target y value in any spectrum. The name of the column of the spectral data to be used to match the target needs to be passed as argument unless the spectrum contains a single numerical variable in addition to "w.length".

Usage

find_wls(
  x,
  target = NULL,
  col.name.x = NULL,
  col.name = NULL,
  .fun = `<=`,
  interpolate = FALSE,
  idfactor = length(target) > 1,
  na.rm = FALSE
)

Arguments

x

an R object

target

numeric or character. A numeric value indicates the spectral quantity value for which wavelengths are to be searched. A character representing a number is converted to a number. A character value representing a number followed by a function name, will be also accepted and decoded, such that "0.1max" is interpreted as targetting one tenthof the maximum value in a column. The character strings "half.maximum" and "HM" are synonyms for "0.5max" while "half.range" and "HR" are synonyms for "0.5range". These synonyms are converted to the cannonical form before saving them to the returned value.

col.name.x

character The name of the column in which to the independent variable is stored. Defaults to "w.length" for objects of class "generic_spct" or derived.

col.name

character The name of the column in which to search for the target value.

.fun

function A binary comparison function or operator.

interpolate

logical Indicating whether the nearest wavelength value in x should be returned or a value calculated by linear interpolation between wavelength values stradling the target.

idfactor

logical or character Generates an index column of factor type. If idfactor = TRUE then the column is auto named target.idx. Alternatively the column name can be directly passed as argument to idfactor as a character string.

na.rm

logical indicating whether NA values should be stripped before searching for the target.

Value

A spectrum object of the same class as x with fewer rows, possibly even no rows. If FALSE is passed to interpolate a subset of x is returned, otherwise a new object of the same class containing interpolated wavelenths for the target value is returned.

Note

This function is used internally by method wls_at_target(), and these methods should be preferred in user code and scripts.

Examples

find_wls(white_led.source_spct)
find_wls(white_led.source_spct, target = "0.5max")
find_wls(white_led.source_spct, target = 0.4)
find_wls(white_led.source_spct, target = 0.4, interpolate = TRUE)
find_wls(white_led.source_spct, target = c(0.3, 0.4))
find_wls(white_led.source_spct, target = c(0.3, 0.4), idfactor = "target")
find_wls(white_led.source_spct, target = c(0.3, 0.4), idfactor = TRUE)
find_wls(white_led.source_spct, target = "0.5max")
find_wls(white_led.source_spct, target = "0.05max")
find_wls(white_led.source_spct, target = "0.5range")

led.df <- as.data.frame(white_led.source_spct)
find_wls(led.df)
find_wls(led.df, col.name = "s.e.irrad", col.name.x = "w.length")
find_wls(led.df, col.name = "s.e.irrad", col.name.x = "w.length",
         target = 0.4)
find_wls(led.df, col.name = "s.e.irrad", col.name.x = "w.length",
         target = c(0.3, 0.4))
find_wls(led.df, col.name = "s.e.irrad", col.name.x = "w.length",
         target = 0.4, idfactor = "target")

Find repeated w.length values

Description

Find repeated w.length values

Usage

findMultipleWl(x, same.wls = TRUE)

Arguments

x

a generic_spct object

same.wls

logical If TRUE all spectra spected to share same w.length values.

Value

integer Number of spectra, guessed from the number of copies of each individual w.length value.


Refine position and value of extremes by fitting

Description

Functions implementing fitting of peaks in a class-agnostic way. The fitting refines the location of peaks and value of peaks based on the location of maxima and minima supplied. This function is to be used together with find_peaks() or find_valleys().

Usage

fit_peaks(
  x,
  peaks.idx,
  span,
  x.col.name = NULL,
  y.col.name,
  method,
  max.span = 5L,
  maximum = TRUE,
  keep.cols = NULL
)

fit_valleys(
  x,
  valleys.idx,
  span,
  x.col.name = NULL,
  y.col.name,
  method,
  max.span = 5L,
  maximum = FALSE,
  keep.cols = NULL
)

Arguments

x

generic_spct or data.frame object.

peaks.idx, valleys.idx

logical or integer Indexes into x selecting global or local extremes.

span

odd integer The span used when refining the location of maxima or minima of x.

x.col.name, y.col.name

character Name of the column of x on which to operate.

method

character The method to use for the fit.

max.span

odd integer The maximum number of data points used when when refining the location of maxima and minima.

maximum

logical A flag indicating whether to search for maxima or minima.

keep.cols

logical Keep unrecognized columns in data frames

Value

An R object of the same class as x containing the fitted values for the peaks, and optionally the values for at peaks.idx or valleys.idx for other retained columns.

Note

These functions are not meant for everyday use. Use option refine.wl = TRUE of methods peaks() and valleys() instead.

Examples

peaks <- find_peaks(sun.spct[["s.e.irrad"]], span = 31)
fit_peaks(sun.spct, peaks, span = 31,
          y.col.name = "s.e.irrad", method = "spline")

Fluence

Description

Energy or photon fluence for one or more wavebands of a light source spectrum and a duration of exposure.

Usage

fluence(
  spct,
  w.band,
  unit.out,
  exposure.time,
  scale.factor,
  wb.trim,
  use.cached.mult,
  use.hinges,
  allow.scaled,
  ...
)

## Default S3 method:
fluence(
  spct,
  w.band,
  unit.out,
  exposure.time,
  scale.factor,
  wb.trim,
  use.cached.mult,
  use.hinges,
  allow.scaled,
  ...
)

## S3 method for class 'source_spct'
fluence(
  spct,
  w.band = NULL,
  unit.out = getOption("photobiology.radiation.unit", default = "energy"),
  exposure.time,
  scale.factor = 1,
  wb.trim = getOption("photobiology.waveband.trim", default = TRUE),
  use.cached.mult = getOption("photobiology.use.cached.mult", default = FALSE),
  use.hinges = NULL,
  allow.scaled = FALSE,
  naming = "default",
  ...
)

## S3 method for class 'source_mspct'
fluence(
  spct,
  w.band = NULL,
  unit.out = getOption("photobiology.radiation.unit", default = "energy"),
  exposure.time,
  scale.factor = 1,
  wb.trim = getOption("photobiology.waveband.trim", default = TRUE),
  use.cached.mult = getOption("photobiology.use.cached.mult", default = FALSE),
  use.hinges = NULL,
  allow.scaled = FALSE,
  naming = "default",
  ...,
  attr2tb = NULL,
  idx = "spct.idx",
  .parallel = FALSE,
  .paropts = NULL
)

Arguments

spct

an R object.

w.band

a list of waveband objects or a waveband object.

unit.out

character string with allowed values "energy", and "photon", or its alias "quantum".

exposure.time

lubridate::duration object.

scale.factor

numeric vector of length 1, or length equal to that of w.band. Numeric multiplier applied to returned values.

wb.trim

logical if TRUE wavebands crossing spectral data boundaries are trimmed, if FALSE, they are discarded.

use.cached.mult

logical indicating whether multiplier values should be cached between calls.

use.hinges

logical Flag indicating whether to insert "hinges" into the spectral data before integration so as to reduce interpolation errors at the boundaries of the wavebands.

allow.scaled

logical indicating whether scaled or normalized spectra as argument to spct are flagged as an error.

...

other arguments (possibly used by derived methods).

naming

character one of "long", "default", "short" or "none". Used to select the type of names to assign to returned value.

attr2tb

character vector, see add_attr2tb for the syntax for attr2tb passed as is to formal parameter col.names.

idx

character Name of the column with the names of the members of the collection of spectra.

.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

One numeric value for each waveband with no change in scale factor, with name attribute set to the name of each waveband unless a named list is supplied in which case the names of the list elements are used. The time.unit attribute is copied from the spectrum object to the output. Units are as follows: If time.unit is second, [W m-2 nm-1] -> [mol s-1 m-2] If time.unit is day, [J d-1 m-2 nm-1] -> [mol d-1 m-2]

Methods (by class)

  • fluence(default): Default for generic function

  • fluence(source_spct): Calculate photon fluence from a source_spct object and the duration of the exposure

  • fluence(source_mspct): Calculates fluence from a source_mspct object.

Note

The last two parameters control speed optimizations. The defaults should be suitable in most cases. If you will use repeatedly the same SWFs on many spectra measured at exactly the same wavelengths you may obtain some speed up by setting use.cached.mult=TRUE. However, be aware that you are responsible for ensuring that the wavelengths are the same in each call, as the only test done is for the length of the w.length vector.

See Also

Other irradiance functions: e_fluence(), e_irrad(), irrad(), q_fluence(), q_irrad()

Examples

library(lubridate)
fluence(sun.spct,
        w.band = waveband(c(400,700)),
        exposure.time = lubridate::duration(3, "minutes") )

Compute range and format it

Description

Compute the range of an R object, and format it as string suitable for printing.

Usage

formatted_range(x, na.rm = TRUE, digits = 3, nsmall = 2, collapse = "..")

Arguments

x

an R object

na.rm

logical, indicating if NA's should be omitted.

digits, nsmall

numeric, passed to same name parameters of format().

collapse

character, passed to same name parameter of paste().

See Also

range, format and paste.

Examples

formatted_range(c(1, 3.5, -0.01))

Rescale a spectrum using a summary function

Description

These methods return a spectral object of the same class as the one supplied as argument but with the spectral data rescaled based on a summary function f applied over a specific range of wavelengths and a target value for the summary value. When the object contains multiple spectra, the rescaling is applied separately to each spectrum.

Usage

fscale(x, ...)

## Default S3 method:
fscale(x, ...)

## S3 method for class 'source_spct'
fscale(
  x,
  range = NULL,
  f = "mean",
  target = 1,
  unit.out = getOption("photobiology.radiation.unit", default = "energy"),
  set.scaled = target == 1,
  ...
)

## S3 method for class 'response_spct'
fscale(
  x,
  range = NULL,
  f = "mean",
  target = 1,
  unit.out = getOption("photobiology.radiation.unit", default = "energy"),
  set.scaled = target == 1,
  ...
)

## S3 method for class 'filter_spct'
fscale(
  x,
  range = NULL,
  f = "mean",
  target = 1,
  qty.out = getOption("photobiology.filter.qty", default = "transmittance"),
  set.scaled = target == 1,
  ...
)

## S3 method for class 'reflector_spct'
fscale(
  x,
  range = NULL,
  f = "mean",
  target = 1,
  qty.out = NULL,
  set.scaled = target == 1,
  ...
)

## S3 method for class 'solute_spct'
fscale(
  x,
  range = NULL,
  f = "mean",
  target = 1,
  qty.out = NULL,
  set.scaled = target == 1,
  ...
)

## S3 method for class 'raw_spct'
fscale(x, range = NULL, f = "mean", target = 1, set.scaled = target == 1, ...)

## S3 method for class 'cps_spct'
fscale(x, range = NULL, f = "mean", target = 1, set.scaled = target == 1, ...)

## S3 method for class 'generic_spct'
fscale(
  x,
  range = NULL,
  f = "mean",
  target = 1,
  set.scaled = target == 1,
  col.names,
  ...
)

## S3 method for class 'source_mspct'
fscale(
  x,
  range = NULL,
  f = "mean",
  target = 1,
  unit.out = getOption("photobiology.radiation.unit", default = "energy"),
  set.scaled = target == 1,
  ...,
  .parallel = FALSE,
  .paropts = NULL
)

## S3 method for class 'response_mspct'
fscale(
  x,
  range = NULL,
  f = "mean",
  target = 1,
  unit.out = getOption("photobiology.radiation.unit", default = "energy"),
  set.scaled = target == 1,
  ...,
  .parallel = FALSE,
  .paropts = NULL
)

## S3 method for class 'filter_mspct'
fscale(
  x,
  range = NULL,
  f = "mean",
  target = 1,
  qty.out = getOption("photobiology.filter.qty", default = "transmittance"),
  set.scaled = target == 1,
  ...,
  .parallel = FALSE,
  .paropts = NULL
)

## S3 method for class 'reflector_mspct'
fscale(
  x,
  range = NULL,
  f = "mean",
  target = 1,
  qty.out = NULL,
  set.scaled = target == 1,
  ...,
  .parallel = FALSE,
  .paropts = NULL
)

## S3 method for class 'solute_mspct'
fscale(
  x,
  range = NULL,
  f = "mean",
  target = 1,
  set.scaled = target == 1,
  ...,
  .parallel = FALSE,
  .paropts = NULL
)

## S3 method for class 'raw_mspct'
fscale(
  x,
  range = NULL,
  f = "mean",
  target = 1,
  set.scaled = target == 1,
  ...,
  .parallel = FALSE,
  .paropts = NULL
)

## S3 method for class 'cps_mspct'
fscale(
  x,
  range = NULL,
  f = "mean",
  target = 1,
  set.scaled = target == 1,
  ...,
  .parallel = FALSE,
  .paropts = NULL
)

## S3 method for class 'generic_mspct'
fscale(
  x,
  range = NULL,
  f = "mean",
  target = 1,
  set.scaled = target == 1,
  col.names,
  ...,
  .parallel = FALSE,
  .paropts = NULL
)

Arguments

x

An R object

...

additional named arguments passed down to f.

range

numeric. 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)

f

character string. "mean" or "total" for scaling so that this summary value becomes 1 for the returned object, or the name of a function taking x as first argument and returning a numeric value.

target

numeric A constant used as target value for scaling.

unit.out

character. Allowed values "energy", and "photon", or its alias "quantum".

set.scaled

logical or NULL Flag indicating if the data is to be marked as "scaled" or not.

qty.out

character. Allowed values "transmittance", and "absorbance".

col.names

character vector containing the names of columns or variables to which to apply the scaling.

.parallel

logical 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.

Details

After scaling, calling the function passed as argument to f with the scaled spectrum as argument, will return the value passed as argument to target. The default for set.scaled depends dynamically on the value passed to target. Sometimes we rescale a spectrum to a "theoretical" value for the summary, while in other cases we rescale the spectrum to a real-world target value of, e.g., a reference energy irradiance. In the first case we say that the data are expressed in relative units, while in the second case we retain actual physical units. To indicate this, the default argument for 'set.scaled' is TRUE when target == 1, assuming the first of these two situations, and false otherwise, assuming the second situation. These defaults can be overriden with an explicit logical argument passed to set.scaled. Scaling overrides any previous normalization with the spectrum tagged as not normalized.

Method fscale is implemented for solute_spct objects but as the spectral data stored in them are a description of an intensive property of a substance, scaling is unlikely to useful. To represent solutions of specific concentrations of solutes, filter_spct objects should be used instead.

Value

A copy of the object passed as argument to x with the original spectral data values replaced with rescaled values, and the "scaled" attribute set to a list describing the scaling applied.

a new object of the same class as x.

Methods (by class)

  • fscale(default): Default for generic function

  • fscale(source_spct):

  • fscale(response_spct):

  • fscale(filter_spct):

  • fscale(reflector_spct):

  • fscale(solute_spct):

  • fscale(raw_spct):

  • fscale(cps_spct):

  • fscale(generic_spct):

  • fscale(source_mspct):

  • fscale(response_mspct):

  • fscale(filter_mspct):

  • fscale(reflector_mspct):

  • fscale(solute_mspct):

  • fscale(raw_mspct):

  • fscale(cps_mspct):

  • fscale(generic_mspct):

Important changes

Metadata describing the rescaling operation are stored in an attribute only if set.scaled = TRUE is passed to the call. The exact format and data stored in the attribute "scaled" has changed during the development history of the package. Spectra re-scaled with earlier versions will lack some information. To obtain the metadata in a consistent format irrespective of this variation use accessor getScaling(), which fills missing fields with NA.

See Also

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

Examples

fscale(sun.spct)
fscale(sun.spct, f = "mean") # same as default
fscale(sun.spct, f = "mean", na.rm = TRUE)
fscale(sun.spct, range = c(400, 700)) # default is whole spectrum
fscale(sun.spct, f = "e_irrad", range = c(400, 700))
s400.spct <- fscale(sun.spct,
                    f = e_irrad,
                    range = c(400, 700),
                    target = 400) # a target in W m-2
s400.spct
e_irrad(s400.spct, c(400, 700))

Shift the scale of a spectrum using a summary function

Description

The fshift() methods return a spectral object of the same class as the one supplied as argument but with the spectral data on a zero-shifted scale. A range of wavelengths is taken as a zero reference and the summary calculated with f for this waveband is substracted. This results in a zero shift (= additive correction) to the values in the returned object. Metadata attributes are retained unchanged.

Usage

fshift(x, ...)

## Default S3 method:
fshift(x, ...)

## S3 method for class 'source_spct'
fshift(
  x,
  range = c(wl_min(x), wl_min(x) + 10),
  f = "mean",
  unit.out = getOption("photobiology.radiation.unit", default = "energy"),
  ...
)

## S3 method for class 'response_spct'
fshift(
  x,
  range = c(wl_min(x), wl_min(x) + 10),
  f = "mean",
  unit.out = getOption("photobiology.radiation.unit", default = "energy"),
  ...
)

## S3 method for class 'filter_spct'
fshift(
  x,
  range = c(wl_min(x), wl_min(x) + 10),
  f = "min",
  qty.out = getOption("photobiology.filter.qty", default = "transmittance"),
  ...
)

## S3 method for class 'reflector_spct'
fshift(x, range = c(wl_min(x), wl_min(x) + 10), f = "min", qty.out = NULL, ...)

## S3 method for class 'source_mspct'
fshift(
  x,
  range = c(wl_min(x), wl_min(x) + 10),
  f = "mean",
  unit.out = getOption("photobiology.radiation.unit", default = "energy"),
  ...
)

## S3 method for class 'raw_spct'
fshift(
  x,
  range = c(wl_min(x), wl_min(x) + 10),
  f = "mean",
  qty.out = NULL,
  ...
)

## S3 method for class 'cps_spct'
fshift(
  x,
  range = c(wl_min(x), wl_min(x) + 10),
  f = "mean",
  qty.out = NULL,
  ...
)

## S3 method for class 'generic_spct'
fshift(x, range = c(wl_min(x), wl_min(x) + 10), f = "mean", col.names, ...)

## S3 method for class 'response_mspct'
fshift(
  x,
  range = c(wl_min(x), wl_min(x) + 10),
  f = "mean",
  unit.out = getOption("photobiology.radiation.unit", default = "energy"),
  ...,
  .parallel = FALSE,
  .paropts = NULL
)

## S3 method for class 'filter_mspct'
fshift(
  x,
  range = c(wl_min(x), wl_min(x) + 10),
  f = "min",
  qty.out = getOption("photobiology.filter.qty", default = "transmittance"),
  ...,
  .parallel = FALSE,
  .paropts = NULL
)

## S3 method for class 'reflector_mspct'
fshift(
  x,
  range = c(wl_min(x), wl_min(x) + 10),
  f = "min",
  qty.out = NULL,
  ...,
  .parallel = FALSE,
  .paropts = NULL
)

## S3 method for class 'raw_mspct'
fshift(
  x,
  range = c(wl_min(x), wl_min(x) + 10),
  f = "min",
  ...,
  .parallel = FALSE,
  .paropts = NULL
)

## S3 method for class 'cps_mspct'
fshift(
  x,
  range = c(wl_min(x), wl_min(x) + 10),
  f = "min",
  ...,
  .parallel = FALSE,
  .paropts = NULL
)

## S3 method for class 'generic_mspct'
fshift(
  x,
  range = c(wl_min(x), wl_min(x) + 10),
  f = "min",
  col.names,
  ...,
  .parallel = FALSE,
  .paropts = NULL
)

Arguments

x

An R object

...

additional named arguments passed down to f.

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)

f

character string "mean", "min" or "max" for scaling so that this summary value becomes the origin of the spectral data scale in the returned object, or the name of a function taking x as first argument and returning a numeric value.

unit.out

character Allowed values "energy", and "photon", or its alias "quantum"

qty.out

character Allowed values "transmittance", and "absorbance"

col.names

character vector containing the names of columns or variables to which to apply the scale shift.

.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 the spectral data values replaced with values zero-shifted.

a new object of the same class as x.

Methods (by class)

  • fshift(default): Default for generic function

  • fshift(source_spct):

  • fshift(response_spct):

  • fshift(filter_spct):

  • fshift(reflector_spct):

  • fshift(source_mspct):

  • fshift(raw_spct):

  • fshift(cps_spct):

  • fshift(generic_spct):

  • fshift(response_mspct):

  • fshift(filter_mspct):

  • fshift(reflector_mspct):

  • fshift(raw_mspct):

  • fshift(cps_mspct):

  • fshift(generic_mspct):

Note

Method fshift is not implemented for solute_spct objects as the spectral data stored in them are a description of an intensive property of a substance. To represent solutions of specific concentrations of solutes, filter_spct objects can be used.

See Also

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


Collection-of-spectra constructor

Description

Converts a list of spectral objects into a "multi spectrum" object by setting the class attribute of the list of spectra to the corresponding multi-spct class, check that components of the list belong to the expected class.

Usage

generic_mspct(
  l = NULL,
  class = "generic_spct",
  ncol = 1,
  byrow = FALSE,
  dim = c(length(l)%/%ncol, ncol)
)

calibration_mspct(l = NULL, ncol = 1, byrow = FALSE, ...)

raw_mspct(l = NULL, ncol = 1, byrow = FALSE, ...)

cps_mspct(l = NULL, ncol = 1, byrow = FALSE, ...)

source_mspct(l = NULL, ncol = 1, byrow = FALSE, ...)

filter_mspct(l = NULL, ncol = 1, byrow = FALSE, ...)

reflector_mspct(l = NULL, ncol = 1, byrow = FALSE, ...)

object_mspct(l = NULL, ncol = 1, byrow = FALSE, ...)

solute_mspct(l = NULL, ncol = 1, byrow = FALSE, ...)

response_mspct(l = NULL, ncol = 1, byrow = FALSE, ...)

chroma_mspct(l = NULL, ncol = 1, byrow = FALSE, ...)

Arguments

l

list of generic_spct or derived classes

class

character The multi spectrum object class or the expected class for the elements of l

ncol

integer Number of 'virtual' columns in data

byrow

logical If ncol > 1 how to read in the data

dim

integer vector of dimensions

...

ignored

Functions

  • calibration_mspct(): Specialization for collections of calibration_spct objects.

  • raw_mspct(): Specialization for collections of raw_spct objects.

  • cps_mspct(): Specialization for collections of cps_spct objects.

  • source_mspct(): Specialization for collections of source_spct objects.

  • filter_mspct(): Specialization for collections of filter_spct objects.

  • reflector_mspct(): Specialization for collections of reflector_spct objects.

  • object_mspct(): Specialization for collections of object_spct objects.

  • solute_mspct(): Specialization for collections of solute_spct objects.

  • response_mspct(): Specialization for collections of response_spct objects.

  • chroma_mspct(): Specialization for collections of chroma_spct objects.

Note

Setting class = source_spct or class = source_mspct makes no difference

Examples

filter_mspct(list(polyester.spct, yellow_gel.spct))

Get the metadata attributes

Description

Method returning attributes of an object of class generic_spct or derived, or of class waveband. Only attributes defined and/or set by package 'photobiology' for objects of the corresponding class are returned. Parameter which can be used to subset the list of attributes.

Usage

get_attributes(x, which, ...)

## S3 method for class 'generic_spct'
get_attributes(x, which = NULL, allowed = all.attributes, ...)

## S3 method for class 'source_spct'
get_attributes(x, which = NULL, ...)

## S3 method for class 'filter_spct'
get_attributes(x, which = NULL, ...)

## S3 method for class 'reflector_spct'
get_attributes(x, which = NULL, ...)

## S3 method for class 'object_spct'
get_attributes(x, which = NULL, ...)

## S3 method for class 'solute_spct'
get_attributes(x, which = NULL, ...)

## S3 method for class 'waveband'
get_attributes(x, which = NULL, ...)

Arguments

x

a generic_spct object.

which

character vector Names of attributes to retrieve.

...

currently ignored

allowed

character vector Names of attributes accepted by which.

Details

Vectors of character strings passed as argument to which are parsed so that if the first member string is "-" the remaining members are removed from the allowed; and if it is "=" the remaining members are used if in allowed. If the first member is none of these three strings, the behaviour is the same as if the first string is "=". If which is NULL all the attributes in allowed are used. The string "" means no attributes, and has precedence over any other values in the character vector. The order of the names of annotations has no meaning: the vector is interpreted as a set except for the three possible "operators" at position 1.

Value

Named list of attribute values.

Methods (by class)

  • get_attributes(generic_spct): generic_spct

  • get_attributes(source_spct): source_spct

  • get_attributes(filter_spct): filter_spct

  • get_attributes(reflector_spct): reflector_spct

  • get_attributes(object_spct): object_spct

  • get_attributes(solute_spct): solute_spct

  • get_attributes(waveband): waveband

See Also

select_spct_attributes

Other measurement metadata functions: add_attr2tb(), getFilterProperties(), getHowMeasured(), getInstrDesc(), getInstrSettings(), getSoluteProperties(), getWhatMeasured(), getWhenMeasured(), getWhereMeasured(), isValidInstrDesc(), isValidInstrSettings(), select_spct_attributes(), setFilterProperties(), setHowMeasured(), setInstrDesc(), setInstrSettings(), setSoluteProperties(), setWhatMeasured(), setWhenMeasured(), setWhereMeasured(), spct_attr2tb(), spct_metadata(), subset_attributes(), trimInstrDesc(), trimInstrSettings()


Get peaks and valleys in a spectrum

Description

These functions find peaks (local maxima) or valleys (local minima) in a spectrum, using a user selectable size threshold relative to the tallest peak (global maximum). This a wrapper built on top of function peaks from package splus2R.

Usage

get_peaks(
  x,
  y,
  ignore_threshold = 0,
  span = 5,
  strict = TRUE,
  x_unit = "",
  x_digits = 3,
  na.rm = FALSE
)

get_valleys(
  x,
  y,
  ignore_threshold = 0,
  span = 5,
  strict = TRUE,
  x_unit = "",
  x_digits = 3,
  na.rm = FALSE
)

Arguments

x

numeric

y

numeric

ignore_threshold

numeric Value between 0.0 and 1.0 indicating the relative size compared to tallest peak threshold below which peaks will be ignored. Negative values set a threshold so that the tallest peaks are ignored, instead of the shortest.

span

integer A peak is defined as an element in a sequence which is greater than all other elements within a window of width span centered at that element. Use NULL for the global peak.

strict

logical If TRUE, an element must be strictly greater than all other values in its window to be considered a peak.

x_unit

character Vector of texts to be pasted at end of labels built from x value at peaks.

x_digits

numeric Number of significant digits in wavelength label.

na.rm

logical indicating whether NA values should be stripped before searching for peaks.

Value

A data frame with variables w.length and s.irrad with their values at the peaks or valleys plus a character variable of labels.

See Also

Other peaks and valleys functions: find_peaks(), find_spikes(), peaks(), replace_bad_pixs(), spikes(), valleys(), wls_at_target()

Examples

with(sun.spct, get_peaks(w.length, s.e.irrad))
with(sun.spct, get_valleys(w.length, s.e.irrad))

Get the "filter.properties" attribute

Description

Function to read the "filter.properties" attribute of an existing filter_spct or a filter_mspct.

Usage

getFilterProperties(x, return.null, ...)

filter_properties(x, return.null, ...)

## Default S3 method:
getFilterProperties(x, return.null = FALSE, ...)

## S3 method for class 'filter_spct'
getFilterProperties(x, return.null = FALSE, ...)

## S3 method for class 'summary_filter_spct'
getFilterProperties(x, return.null = FALSE, ...)

## S3 method for class 'generic_mspct'
getFilterProperties(x, return.null = FALSE, ..., idx = "spct.idx")

Arguments

x

a filter_spct object

return.null

logical If true, NULL is returned if the attribute is not set, otherwise the expected list is returned with all fields set to NA.

...

Allows use of additional arguments in methods for other classes.

idx

character Name of the column with the names of the members of the collection of spectra.

Value

a list with fields named "Rfr.constant" [/1/1], "thickness" [mm] and "attenuation.mode". If the attribute is not set, and return.null is FALSE, a list with fields set to NA is returned, otherwise, NULL.

Methods (by class)

  • getFilterProperties(default): default

  • getFilterProperties(filter_spct): generic_spct

  • getFilterProperties(summary_filter_spct): summary_generic_spct

  • getFilterProperties(generic_mspct): filter_mspct

Note

The method for collections of spectra returns the a tibble with a column of lists.

See Also

Other measurement metadata functions: add_attr2tb(), getHowMeasured(), getInstrDesc(), getInstrSettings(), getSoluteProperties(), getWhatMeasured(), getWhenMeasured(), getWhereMeasured(), get_attributes(), isValidInstrDesc(), isValidInstrSettings(), select_spct_attributes(), setFilterProperties(), setHowMeasured(), setInstrDesc(), setInstrSettings(), setSoluteProperties(), setWhatMeasured(), setWhenMeasured(), setWhereMeasured(), spct_attr2tb(), spct_metadata(), subset_attributes(), trimInstrDesc(), trimInstrSettings()

Examples

filter_properties(polyester.spct)

Get the "how.measured" attribute

Description

Function to read the "how.measured" attribute of an existing generic_spct, generic_mspct, summary_generic_spct, data.frame or a derived-class object.

Usage

getHowMeasured(x, ...)

how_measured(x, ...)

## Default S3 method:
getHowMeasured(x, ...)

## S3 method for class 'generic_spct'
getHowMeasured(x, ...)

## S3 method for class 'summary_generic_spct'
getHowMeasured(x, ...)

## S3 method for class 'data.frame'
getHowMeasured(x, ...)

## S3 method for class 'generic_mspct'
getHowMeasured(x, ..., idx = "spct.idx")

Arguments

x

a generic_spct object

...

Allows use of additional arguments in methods for other classes.

idx

character Name of the column with the names of the members of the collection of spectra.

Value

character vector An object containing a description of the data.

Methods (by class)

  • getHowMeasured(default): default

  • getHowMeasured(generic_spct): generic_spct

  • getHowMeasured(summary_generic_spct): summary_generic_spct

  • getHowMeasured(data.frame): data.frame

  • getHowMeasured(generic_mspct): generic_mspct

Note

The method for collections of spectra returns the a tibble with a column of character strings.

See Also

Other measurement metadata functions: add_attr2tb(), getFilterProperties(), getInstrDesc(), getInstrSettings(), getSoluteProperties(), getWhatMeasured(), getWhenMeasured(), getWhereMeasured(), get_attributes(), isValidInstrDesc(), isValidInstrSettings(), select_spct_attributes(), setFilterProperties(), setHowMeasured(), setInstrDesc(), setInstrSettings(), setSoluteProperties(), setWhatMeasured(), setWhenMeasured(), setWhereMeasured(), spct_attr2tb(), spct_metadata(), subset_attributes(), trimInstrDesc(), trimInstrSettings()

Examples

how_measured(sun.spct)

Get the "idfactor" attribute

Description

Function to read the idfactor attribute of an existing generic_spct.

Usage

getIdFactor(x)

id_factor(x)

Arguments

x

a generic_spct object

Value

character

Note

If x is not a generic_spct or an object of a derived class NA is returned.

See Also

Other idfactor attribute functions: setIdFactor()

Examples

id_factor(sun_evening.spct)

Get the "instr.desc" attribute

Description

Function to read the "instr.desc" attribute of an existing generic_spct object.

Usage

getInstrDesc(x)

instr_descriptor(x)

Arguments

x

a generic_spct object

Value

list (depends on instrument type)

See Also

Other measurement metadata functions: add_attr2tb(), getFilterProperties(), getHowMeasured(), getInstrSettings(), getSoluteProperties(), getWhatMeasured(), getWhenMeasured(), getWhereMeasured(), get_attributes(), isValidInstrDesc(), isValidInstrSettings(), select_spct_attributes(), setFilterProperties(), setHowMeasured(), setInstrDesc(), setInstrSettings(), setSoluteProperties(), setWhatMeasured(), setWhenMeasured(), setWhereMeasured(), spct_attr2tb(), spct_metadata(), subset_attributes(), trimInstrDesc(), trimInstrSettings()


Get the "instr.settings" attribute

Description

Function to read the "instr.settings" attribute of an existing generic_spct object.

Usage

getInstrSettings(x)

instr_settings(x)

Arguments

x

a generic_spct object

Value

list

See Also

Other measurement metadata functions: add_attr2tb(), getFilterProperties(), getHowMeasured(), getInstrDesc(), getSoluteProperties(), getWhatMeasured(), getWhenMeasured(), getWhereMeasured(), get_attributes(), isValidInstrDesc(), isValidInstrSettings(), select_spct_attributes(), setFilterProperties(), setHowMeasured(), setInstrDesc(), setInstrSettings(), setSoluteProperties(), setWhatMeasured(), setWhenMeasured(), setWhereMeasured(), spct_attr2tb(), spct_metadata(), subset_attributes(), trimInstrDesc(), trimInstrSettings()


Get the "K.type" attribute

Description

Function to read the "K.type" attribute of an existing solute_spct object.

Usage

getKType(x)

Arguments

x

a solute_spct object

Value

character string

Note

If x is not a solute_spct or a summary_solute_spct object, NA is returned.

See Also

Other K attribute functions: setKType()

Examples

print("missing example")

Get the "mspct.version" attribute

Description

Function to read the "mspct.version" attribute of an existing generic_mspct object.

Usage

getMspctVersion(x)

Arguments

x

a generic_mspct object

Value

numeric value

Note

if x is not a generic_mspct object, NA is returned, and if it the attribute is missing, zero is returned with a warning.


Get the "multiple.wl" attribute

Description

Function to query the value of the multiple.wl attribute of an existing generic_spct.

Usage

getMultipleWl(x)

multiple_wl(x)

Arguments

x

a generic_spct object

Value

integer value, the value of attribute multiple.wl, or NA if the attribute is not set, or if x is not a generic_spct object or an object of a derived class.

See Also

Other multiple.wl attribute functions: setMultipleWl()

Examples

multiple_wl(sun.spct)
multiple_wl(sun_evening.spct)

Query the "normalized" and "normalization" attributes

Description

Functions to read the "normalized" and "normalization" attributes of an existing generic_spct object.

Usage

getNormalized(x, .force.numeric = FALSE)

getNormalised(x, .force.numeric = FALSE)

getNormalization(x)

getNormalisation(x)

Arguments

x

a generic_spct object.

.force.numeric

logical If TRUE always silently return a numeric value, with FALSE encoded as zero, and character values as NA.

Details

Spectral data that has been normalized needs to be used diffferently in computations than data expresed in original units. These two functions make it possible to query if data stored in an object of class generic_spct or of a derived class contains data expressed in physical units or normalized. In the later case, it is possible to also query how the normalization was done.

Value

getNormalized() returns numeric or logical (possibly character for objects created with earlier versions); for collections of spectra, a named list, with one member for each spectrum. If x is not a generic_spct object, NA or a list with fields set to NAs is returned. Objects created with versions of package 'photobiology' earlier than 0.10.8 are lacking the detailed normalization metadata.

getNormalization() returns a list with five fields: norm.type, norm.wl, norm.factors, norm.cols, norm.range. For collections of spectra, a named list of lists, with one member list for each member of the collection of spectra. See setNormalized() for the values stored in the fields.

Note

getNormalised() is a synonym for this getNormalized() method.

See Also

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

Examples

getNormalized(sun.spct)
getNormalization(sun.spct)

sun_norm.spct <- normalize(sun.spct)

getNormalized(sun_norm.spct)
getNormalization(sun_norm.spct)

getNormalization(e2q(sun_norm.spct))

gel_norm.spct <- normalize(yellow_gel.spct)

getNormalized(gel_norm.spct)
getNormalization(gel_norm.spct)

# getNormalization(T2Afr(gel_norm.spct))
getNormalization(any2A(gel_norm.spct))

Get the "scaled" attribute

Description

Function to read the "scaled" attribute of an existing generic_spct object.

Usage

getScaled(x, .force.list = FALSE)

getScaling(x)

Arguments

x

a generic_spct object

.force.list

logical If TRUE always silently return a list, with FALSE encoded field multiplier = 1.

Value

logical

Note

if x is not a filter_spct object, NA is returned

See Also

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

Examples

scaled.spct <- fscale(sun.spct)
getScaled(scaled.spct)

Get the "solute.properties" attribute

Description

Function to read the "solute.properties" attribute of an existing solute_spct or a solute_mspct objects.

Usage

getSoluteProperties(x, return.null, ...)

solute_properties(x, return.null, ...)

## Default S3 method:
getSoluteProperties(x, return.null = FALSE, ...)

## S3 method for class 'solute_spct'
getSoluteProperties(x, return.null = FALSE, ...)

## S3 method for class 'summary_solute_spct'
getSoluteProperties(x, return.null = FALSE, ...)

## S3 method for class 'solute_mspct'
getSoluteProperties(x, return.null = FALSE, ..., idx = "spct.idx")

Arguments

x

solute_spct A spectrum of coefficients of attenuation.

return.null

logical If true, NULL is returned if the attribute is not set, otherwise the expected list is returned with all fields set to NA.

...

Allows use of additional arguments in methods for other classes.

idx

character Name of the column with the names of the members of the collection of spectra.

Value

a list with fields named "mass", "formula", "structure", "name" and "ID". If the attribute is not set, and return.null is FALSE, a list with fields set to NA is returned, otherwise, NULL.

Methods (by class)

  • getSoluteProperties(default): default

  • getSoluteProperties(solute_spct): solute_spct

  • getSoluteProperties(summary_solute_spct): summary_solute_spct

  • getSoluteProperties(solute_mspct): solute_mspct

Note

The method for collections of spectra returns the a tibble with a column of lists.

See Also

Other measurement metadata functions: add_attr2tb(), getFilterProperties(), getHowMeasured(), getInstrDesc(), getInstrSettings(), getWhatMeasured(), getWhenMeasured(), getWhereMeasured(), get_attributes(), isValidInstrDesc(), isValidInstrSettings(), select_spct_attributes(), setFilterProperties(), setHowMeasured(), setInstrDesc(), setInstrSettings(), setSoluteProperties(), setWhatMeasured(), setWhenMeasured(), setWhereMeasured(), spct_attr2tb(), spct_metadata(), subset_attributes(), trimInstrDesc(), trimInstrSettings()

Examples

solute_properties(water.spct)

Get the "spct.version" attribute

Description

Function to read the "spct.version" attribute of an existing generic_spct object.

Usage

getSpctVersion(x)

Arguments

x

a generic_spct object

Value

integer value

Note

if x is not a generic_spct object, NA is returned, and if it the attribute is missing, zero is returned with a warning.


Get the "time.unit" attribute of an existing source_spct object

Description

Function to read the "time.unit" attribute

Usage

getTimeUnit(x, force.duration = FALSE)

Arguments

x

a source_spct object

force.duration

logical If TRUE a lubridate::duration is returned even if the object attribute is a character string, if no conversion is possible NA is returned.

Value

character string or a lubridate::duration

Note

if x is not a source_spct or a response_spct object, NA is returned

See Also

Other time attribute functions: checkTimeUnit(), convertThickness(), convertTimeUnit(), setTimeUnit()

Examples

getTimeUnit(sun.spct)

Get the "what.measured" attribute

Description

Function to read the "what.measured" attribute of an existing generic_spct, generic_mspct, summary_generic_spct, data.frame or a derived-class object.

Usage

getWhatMeasured(x, ...)

what_measured(x, ...)

## Default S3 method:
getWhatMeasured(x, ...)

## S3 method for class 'generic_spct'
getWhatMeasured(x, ...)

## S3 method for class 'summary_generic_spct'
getWhatMeasured(x, ...)

## S3 method for class 'data.frame'
getWhatMeasured(x, ...)

## S3 method for class 'generic_mspct'
getWhatMeasured(x, ..., idx = "spct.idx")

Arguments

x

a generic_spct object

...

Allows use of additional arguments in methods for other classes.

idx

character Name of the column with the names of the members of the collection of spectra.

Value

character vector An object containing a description of the data.

Methods (by class)

  • getWhatMeasured(default): default

  • getWhatMeasured(generic_spct): generic_spct

  • getWhatMeasured(summary_generic_spct): summary_generic_spct

  • getWhatMeasured(data.frame): data.frame

  • getWhatMeasured(generic_mspct): generic_mspct

Note

The method for collections of spectra returns the a tibble with a column of character strings.

See Also

Other measurement metadata functions: add_attr2tb(), getFilterProperties(), getHowMeasured(), getInstrDesc(), getInstrSettings(), getSoluteProperties(), getWhenMeasured(), getWhereMeasured(), get_attributes(), isValidInstrDesc(), isValidInstrSettings(), select_spct_attributes(), setFilterProperties(), setHowMeasured(), setInstrDesc(), setInstrSettings(), setSoluteProperties(), setWhatMeasured(), setWhenMeasured(), setWhereMeasured(), spct_attr2tb(), spct_metadata(), subset_attributes(), trimInstrDesc(), trimInstrSettings()

Examples

what_measured(sun.spct)

Get the "when.measured" attribute

Description

Function to read the "when.measured" attribute of an existing generic_spct, generic_mspct, summary_generic_spct, data.frame or a derived-class object.

Usage

getWhenMeasured(x, ...)

when_measured(x, ...)

## Default S3 method:
getWhenMeasured(x, ...)

## S3 method for class 'generic_spct'
getWhenMeasured(x, as.df = FALSE, ...)

## S3 method for class 'summary_generic_spct'
getWhenMeasured(x, as.df = FALSE, ...)

## S3 method for class 'data.frame'
getWhenMeasured(x, as.df = FALSE, ...)

## S3 method for class 'generic_mspct'
getWhenMeasured(x, ..., idx = "spct.idx")

Arguments

x

a generic_spct object

...

Allows use of additional arguments in methods for other classes.

as.df

logical If TRUE return a data frame instead of a list, when the value stored in the attribute is a list.

idx

character Name of the column with the names of the members of the collection of spectra.

Value

POSIXct An object with date and time.

Methods (by class)

  • getWhenMeasured(default): default

  • getWhenMeasured(generic_spct): generic_spct

  • getWhenMeasured(summary_generic_spct): summary_generic_spct

  • getWhenMeasured(data.frame): data.frame

  • getWhenMeasured(generic_mspct): generic_mspct

Note

If x is not a generic_spct or an object of a derived class NA is returned.

The method for collections of spectra returns the a tibble with the correct times in TZ = "UTC".

See Also

Other measurement metadata functions: add_attr2tb(), getFilterProperties(), getHowMeasured(), getInstrDesc(), getInstrSettings(), getSoluteProperties(), getWhatMeasured(), getWhereMeasured(), get_attributes(), isValidInstrDesc(), isValidInstrSettings(), select_spct_attributes(), setFilterProperties(), setHowMeasured(), setInstrDesc(), setInstrSettings(), setSoluteProperties(), setWhatMeasured(), setWhenMeasured(), setWhereMeasured(), spct_attr2tb(), spct_metadata(), subset_attributes(), trimInstrDesc(), trimInstrSettings()

Examples

when_measured(sun.spct)

Get the "where.measured" attribute

Description

Function to read the "where.measured" attribute of generic_spct, generic_mspct, summary_generic_spct, data.frame or a derived-class object.

Usage

getWhereMeasured(x, ...)

where_measured(x, ...)

## Default S3 method:
getWhereMeasured(x, ...)

## S3 method for class 'generic_spct'
getWhereMeasured(x, ...)

## S3 method for class 'summary_generic_spct'
getWhereMeasured(x, ...)

## S3 method for class 'generic_mspct'
getWhereMeasured(x, ..., idx = "spct.idx", .bind.geocodes = TRUE)

## S3 method for class 'data.frame'
getWhereMeasured(x, ...)

Arguments

x

a generic_spct object

...

Allows use of additional arguments in methods for other classes.

idx

character Name of the column with the names of the members of the collection of spectra.

.bind.geocodes

logical In the case of collections of spectra if .bind.geocodes = TRUE, the default, the returned value is a single geocode with one row for each member spectrum. Otherwise the individual geocode data frames are returned in a list column within a tibble.

Value

a data.frame with a single row and at least columns "lon" and "lat", unless expand is set to FALSE.

Methods (by class)

  • getWhereMeasured(default): default

  • getWhereMeasured(generic_spct): generic_spct

  • getWhereMeasured(summary_generic_spct): summary_generic_spct

  • getWhereMeasured(generic_mspct): generic_mspct

  • getWhereMeasured(data.frame): data.frame

Note

If x is not a generic_spct or an object of a derived class NA is returned.

See Also

Other measurement metadata functions: add_attr2tb(), getFilterProperties(), getHowMeasured(), getInstrDesc(), getInstrSettings(), getSoluteProperties(), getWhatMeasured(), getWhenMeasured(), get_attributes(), isValidInstrDesc(), isValidInstrSettings(), select_spct_attributes(), setFilterProperties(), setHowMeasured(), setInstrDesc(), setInstrSettings(), setSoluteProperties(), setWhatMeasured(), setWhenMeasured(), setWhereMeasured(), spct_attr2tb(), spct_metadata(), subset_attributes(), trimInstrDesc(), trimInstrSettings()

Examples

where_measured(sun.spct)

Green birch leaf reflectance.

Description

A dataset of spectral reflectance expressed as a fraction of one.

Usage

green_leaf.spct

Format

A reflector_spct object with 226 rows and 2 variables

Details

  • w.length (nm)

  • Rfr (0..1)

References

Aphalo, P. J. & Lehto, T. Effects of light quality on growth and N accumulation in birch seedlings Tree Physiology, 1997, 17, 125-132

See Also

Other Spectral data examples: A.illuminant.spct, D50.illuminant.spct, D65.illuminant.spct, Ler_leaf.spct, black_body.spct, ccd.spct, clear.spct, filter_cps.mspct, phenylalanine.spct, photodiode.spct, sun.spct, sun_daily.spct, sun_evening.spct, two_filters.spct, two_sensors.mspct, water.spct, white_led.source_spct

Examples

green_leaf.spct

Return the First and Last Parts of an Object

Description

Returns the first and last "parts" (rows or members) of a spectrum, dataframe, vector, function, table or ftable. In other words, the combined output from methods head and tail.

Usage

head_tail(x, n, ...)

## Default S3 method:
head_tail(x, n = 3L, ...)

## S3 method for class 'data.frame'
head_tail(x, n = 3L, ...)

## S3 method for class 'matrix'
head_tail(x, n = 3L, ...)

## S3 method for class ''function''
head_tail(x, n = 6L, ...)

## S3 method for class 'table'
head_tail(x, n = 6L, ...)

## S3 method for class 'ftable'
head_tail(x, n = 6L, ...)

Arguments

x

an R object.

n

integer. If positive, n rows or members in the returned object are copied from each of "head" and "tail" of x. If negative, all except n elements of x from each of "head" and "tail" are returned.

...

arguments to be passed to or from other methods.

Details

The value returned by head_tail() is equivalent to row binding the the values returned by head() and tail(), although not implemented in this way. The same specializations as defined in package 'utils' for head() and tail() have been implemented.

Value

An object (usually) like x but smaller, except when n = 0. For ftable objects x, a transformed format(x).

Methods (by class)

  • head_tail(default):

  • head_tail(data.frame):

  • head_tail(matrix):

  • head_tail(`function`):

  • head_tail(table):

  • head_tail(ftable):

Note

For some types of input, like functions, the output may be confusing, however, we have opted for consistency with existing functions. The code is in part a revision of that of head() and tail() from package ‘utils’. This method is especially useful when checking spectral data, as both ends are of interest.

head_tail() methods for function, table and ftable classes, are wrappers for head() method.

See Also

head, and compare the examples and the values returned to the examples below.

Examples

head_tail(1:20)
head_tail(1:20, 12)
head_tail(1:20, -7)
head_tail(1:20, -10)
head_tail(letters)
head_tail(sun.spct)
head_tail(sun.spct, 6)
head_tail(sun.data)
head_tail(as.matrix(sun.data))
head_tail(sun_evening.spct)
head_tail(sun_evening.mspct, 1L)

Irradiance

Description

Computes illuminance (lux), or the luminous flux incident on a surface, from spectral irradiance stored in a source_spct object.

Usage

illuminance(spct, std, scale.factor, allow.scaled, ...)

## Default S3 method:
illuminance(spct, std, scale.factor, allow.scaled, ...)

## S3 method for class 'source_spct'
illuminance(
  spct,
  std = "CIE2deg",
  scale.factor = 1,
  allow.scaled = FALSE,
  naming = "default",
  ...
)

## S3 method for class 'source_mspct'
illuminance(
  spct,
  std = "CIE2deg",
  scale.factor = 1,
  allow.scaled = FALSE,
  naming = "default",
  ...,
  attr2tb = NULL,
  idx = "spct.idx",
  .parallel = FALSE,
  .paropts = NULL
)

Arguments

spct

an R object.

std

character The luminous efficiency function to use, "CIE2deg" or "CIE10deg".

scale.factor

numeric vector of length 1, or the character string exposure.

allow.scaled

logical indicating whether scaled or normalized spectra as argument to spct are flagged as an error.

...

other arguments (possibly ignored)

naming

character one of "long", "default", "short" or "none". Used to select the type of names to assign to returned value.

attr2tb

character vector, see add_attr2tb for the syntax for attr2tb passed as is to formal parameter col.names.

idx

character Name of the column with the names of the members of the collection of spectra.

.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 named numeric vector of length one in the case of methods for individual spectra. A data.frame in the case of collections of spectra, containing one column with illuminance, an index column with the names of the spectra, and optionally additional columns with metadata values retrieved from the attributes of the member spectra.

The time.unit attribute is always second. Units are as follows: if time.unit of the argument passed to spct is second, [W m-2 nm-1] -> [lx], otherwise average value [lx] for the period unless exposure = TRUE.

Methods (by class)

  • illuminance(default): Default for generic function

  • illuminance(source_spct): Calculates illuminance from a source_spct object.

  • illuminance(source_mspct): Calculates illuminance from a source_mspct object.

Note

Formal parameter allow.scaled is used internally for calculation of ratios, as rescaling and normalization do not invalidate the calculation of ratios within one spectrum.

References

Stockman, A. (2019) Cone fundamentals and CIE standards. Current Opinion in Behavioral Sciences, 30, 87-93. doi:10.1016/j.cobeha.2019.06.005

Examples

illuminance(sun.spct)
illuminance(sun.daily.spct)
illuminance(sun.daily.spct, scale.factor = "exposure")
illuminance(sun.daily.spct, scale.factor = 1e-3)

Insert wavelength values into spectral data.

Description

Inserting wavelengths values immediately before and after a discontinuity in the SWF, greatly reduces the errors caused by interpolating the weighted irradiance during integration of the effective spectral irradiance. This is specially true when data have a large wavelength step size.

Usage

insert_hinges(x, y, h)

Arguments

x

numeric vector (sorted in increasing order)

y

numeric vector

h

a numeric vector giving the wavelengths at which the y values should be inserted by interpolation, no interpolation is indicated by an empty vector (numeric(0))

Value

a data.frame with variables x and y. Unless the hinge values were already present in y, each inserted hinge, expands the vectors returned in the data frame by one value.

Note

Insertion is a costly operation but I have tried to optimize this function as much as possible by avoiding loops. Earlier this function was implemented in C++, but a bug was discovered and I have now rewritten it using R.

See Also

Other low-level functions operating on numeric vectors.: as_energy(), as_quantum_mol(), calc_multipliers(), div_spectra(), energy_irradiance(), energy_ratio(), integrate_xy(), interpolate_spectrum(), irradiance(), l_insert_hinges(), oper_spectra(), photon_irradiance(), photon_ratio(), photons_energy_ratio(), prod_spectra(), s_e_irrad2rgb(), split_energy_irradiance(), split_photon_irradiance(), subt_spectra(), sum_spectra(), trim_tails(), v_insert_hinges(), v_replace_hinges()

Examples

with(sun.data,
    insert_hinges(w.length, s.e.irrad,
       c(399.99, 400.00, 699.99, 700.00)))

Insert new wavelength values into a spectrum

Description

Insert new wavelength values into a spectrum interpolating the corresponding spectral data values.

Usage

insert_spct_hinges(spct, hinges = NULL, byref = FALSE)

Arguments

spct

an object of class "generic_spct"

hinges

numeric vector of wavelengths (nm) at which the s.irrad should be inserted by interpolation, no interpolation is indicated by an empty vector (numeric(0))

byref

logical indicating if new object will be created by reference or by copy of spct

Value

a generic_spct or a derived type with variables w.length and other numeric variables.

Note

Inserting wavelengths values "hinges" immediately before and after a discontinuity in the SWF, greatly reduces the errors caused by interpolating the weighted irradiance during integration of the effective spectral irradiance. This is specially true when data has a large wavelength step size.

Examples

insert_spct_hinges(sun.spct, c(399.99,400.00,699.99,700.00))
insert_spct_hinges(sun.spct,
                   c(199.99,200.00,399.50,399.99,400.00,699.99,
                         700.00,799.99,1000.00))

Integrate spectral data.

Description

This function gives the result of integrating spectral data over wavelengths.

Usage

integrate_spct(spct)

Arguments

spct

generic_spct

Value

One or more numeric values with no change in scale factor: e.g. [W m-2 nm-1] -> [W m-2]. Each value in the returned vector corresponds to a variable in the spectral object, except for wavelength. For non-numeric variables the returned value is NA.

Examples

integrate_spct(sun.spct)

Gives irradiance from spectral irradiance.

Description

This function gives the result of integrating spectral irradiance over wavelengths.

Usage

integrate_xy(x, y)

Arguments

x

numeric vector.

y

numeric vector.

Value

a single numeric value with no change in scale factor: e.g. [W m-2 nm-1] -> [W m-2]

See Also

Other low-level functions operating on numeric vectors.: as_energy(), as_quantum_mol(), calc_multipliers(), div_spectra(), energy_irradiance(), energy_ratio(), insert_hinges(), interpolate_spectrum(), irradiance(), l_insert_hinges(), oper_spectra(), photon_irradiance(), photon_ratio(), photons_energy_ratio(), prod_spectra(), s_e_irrad2rgb(), split_energy_irradiance(), split_photon_irradiance(), subt_spectra(), sum_spectra(), trim_tails(), v_insert_hinges(), v_replace_hinges()

Examples

with(sun.data, integrate_xy(w.length, s.e.irrad))

Map a spectrum to new wavelength values.

Description

This function gives the result of interpolating spectral data from the original set of wavelengths to a new one.

Usage

interpolate_spct(spct, w.length.out = NULL, fill = NA, length.out = NULL)

interpolate_mspct(
  mspct,
  w.length.out = NULL,
  fill = NA,
  length.out = NULL,
  .parallel = FALSE,
  .paropts = NULL
)

Arguments

spct

generic_spct

w.length.out

numeric vector of wavelengths (nm)

fill

a value to be assigned to out of range wavelengths

length.out

numeric value

mspct

an object of class "generic_mspct"

.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.

Details

If length.out it is a numeric value, then gives the number of rows in the output, if it is NULL, the values in the numeric vector w.length.out are used. If both are not NULL then the range of w.length.out and length.out are used to generate a vector of wavelength. A value of NULL for fill prevents extrapolation. If both w.length.out and length.out are NULL the input is returned as is. If w.length.out has length equal to zero, zero rows from the input are returned.

Value

A new spectral object of the same class as argument spct.

Note

The default fill = NA fills extrapolated values with NA. Giving NULL as argument for fill deletes wavelengths outside the input data range from the returned spectrum. A numerical value can be also be provided as fill. This function calls interpolate_spectrum for each non-wavelength column in the input spectra object.

Examples

interpolate_spct(sun.spct, 400:500, NA)
interpolate_spct(sun.spct, 400:500, NULL)
interpolate_spct(sun.spct, seq(200, 1000, by=0.1), 0)
interpolate_spct(sun.spct, c(400,500), length.out=201)

Calculate spectral values at a different set of wavelengths

Description

Interpolate/re-express spectral irradiance (or other spectral quantity) values at new wavelengths values. This is a low-level function operating on numeric vectors and called by higher level functions in the package, such as mathematical operators for classes for spectral data.

Usage

interpolate_spectrum(w.length.in, s.irrad, w.length.out, fill = NA, ...)

Arguments

w.length.in

numeric vector of wavelengths (nm).

s.irrad

a numeric vector of spectral values.

w.length.out

numeric vector of wavelengths (nm).

fill

a value to be assigned to out of range wavelengths.

...

additional arguments passed to spline().

Value

a numeric vector of interpolated spectral values.

Note

The current version of interpolate uses spline if fewer than 25 data points are available. Otherwise it uses approx. In the first case a cubic spline is used, in the second case linear interpolation, which should be faster.

See Also

splinefun.

Other low-level functions operating on numeric vectors.: as_energy(), as_quantum_mol(), calc_multipliers(), div_spectra(), energy_irradiance(), energy_ratio(), insert_hinges(), integrate_xy(), irradiance(), l_insert_hinges(), oper_spectra(), photon_irradiance(), photon_ratio(), photons_energy_ratio(), prod_spectra(), s_e_irrad2rgb(), split_energy_irradiance(), split_photon_irradiance(), subt_spectra(), sum_spectra(), trim_tails(), v_insert_hinges(), v_replace_hinges()

Examples

my.w.length <- 300:700
with(sun.data, interpolate_spectrum(w.length, s.e.irrad, my.w.length))

Map spectra to new wavelength values.

Description

This function returns the result of interpolating spectral data from the original set of wavelengths to a new one.

Usage

interpolate_wl(x, w.length.out, fill, length.out, ...)

## Default S3 method:
interpolate_wl(x, w.length.out, fill, length.out, ...)

## S3 method for class 'generic_spct'
interpolate_wl(x, w.length.out = NULL, fill = NA, length.out = NULL, ...)

## S3 method for class 'generic_mspct'
interpolate_wl(
  x,
  w.length.out = NULL,
  fill = NA,
  length.out = NULL,
  ...,
  .parallel = FALSE,
  .paropts = NULL
)

Arguments

x

an R object

w.length.out

numeric vector of wavelengths (nm)

fill

a value to be assigned to out of range wavelengths

length.out

numeric value

...

not used

.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.

Details

If length.out it is a numeric value, then gives the number of rows in the output, if it is NULL, the values in the numeric vector w.length.out are used. If both are not NULL then the range of w.length.out and length.out are used to generate a vector of wavelength. A value of NULL for fill prevents extrapolation.

Value

A new spectral object of the same class as argument spct.

Methods (by class)

  • interpolate_wl(default): Default for generic function

  • interpolate_wl(generic_spct): Interpolate wavelength in an object of class "generic_spct" or derived.

  • interpolate_wl(generic_mspct): Interpolate wavelength in an object of class "generic_mspct" or derived.

Note

The default fill = NA fills extrapolated values with NA. Giving NULL as argument for fill deletes wavelengths outside the input data range from the returned spectrum. A numerical value can be also be provided as fill. This function calls interpolate_spectrum for each non-wavelength column in the input spectra object.

Examples

interpolate_wl(sun.spct, 400:500, NA)
interpolate_wl(sun.spct, 400:500, NULL)
interpolate_wl(sun.spct, seq(200, 1000, by=0.1), 0)
interpolate_wl(sun.spct, c(400,500), length.out=201)

Irradiance

Description

This function returns the irradiance for a given waveband of a light source spectrum.

Usage

irrad(
  spct,
  w.band,
  unit.out,
  quantity,
  time.unit,
  scale.factor,
  wb.trim,
  use.cached.mult,
  use.hinges,
  allow.scaled,
  ...
)

## Default S3 method:
irrad(
  spct,
  w.band,
  unit.out,
  quantity,
  time.unit,
  scale.factor,
  wb.trim,
  use.cached.mult,
  use.hinges,
  allow.scaled,
  ...
)

## S3 method for class 'source_spct'
irrad(
  spct,
  w.band = NULL,
  unit.out = getOption("photobiology.radiation.unit", default = "energy"),
  quantity = "total",
  time.unit = NULL,
  scale.factor = 1,
  wb.trim = getOption("photobiology.waveband.trim", default = TRUE),
  use.cached.mult = getOption("photobiology.use.cached.mult", default = FALSE),
  use.hinges = NULL,
  allow.scaled = !quantity %in% c("average", "mean", "total"),
  naming = "default",
  return.tb = FALSE,
  ...
)

## S3 method for class 'source_mspct'
irrad(
  spct,
  w.band = NULL,
  unit.out = getOption("photobiology.radiation.unit", default = "energy"),
  quantity = "total",
  time.unit = NULL,
  scale.factor = 1,
  wb.trim = getOption("photobiology.waveband.trim", default = TRUE),
  use.cached.mult = getOption("photobiology.use.cached.mult", default = FALSE),
  use.hinges = NULL,
  allow.scaled = !quantity %in% c("average", "mean", "total"),
  naming = "default",
  ...,
  attr2tb = NULL,
  idx = "spct.idx",
  .parallel = FALSE,
  .paropts = NULL
)

Arguments

spct

an R object.

w.band

waveband or list of waveband objects The waveband(s) determine the region(s) of the spectrum that are summarized.

unit.out

character Allowed values "energy", and "photon", or its alias "quantum".

quantity

character string One of "total", "average" or "mean", "contribution", "contribution.pc", "relative" or "relative.pc".

time.unit

character or lubridate::duration object.

scale.factor

numeric vector of length 1, or length equal to that of w.band. Numeric multiplier applied to returned values.

wb.trim

logical if TRUE wavebands crossing spectral data boundaries are trimmed, if FALSE, they are discarded.

use.cached.mult

logical indicating whether multiplier values should be cached between calls.

use.hinges

logical Flag indicating whether to insert "hinges" into the spectral data before integration so as to reduce interpolation errors at the boundaries of the wavebands. If NULL, default is chosen based on data.

allow.scaled

logical indicating whether scaled or normalized spectra as argument to spct are flagged as an error.

...

other arguments (possibly ignored)

naming

character one of "long", "default", "short" or "none". Used to select the type of names to assign to returned value.

return.tb

logical Flag forcing a tibble to be always returned, even for a single spectrum as argumnet to spct. The default is FALSE for backwards compatibility.

attr2tb

character vector, see add_attr2tb for the syntax for attr2tb passed as is to formal parameter col.names.

idx

character Name of the column with the names of the members of the collection of spectra.

.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 named numeric vector in the case of a _spct object containing a single spectrum and return.tb = FALSE. The vector has one member one value for each waveband passed to parameter w.band. In all other cases a tibble, containing one column for each waveband object, an index column with the names of the spectra, and optionally additional columns with metadata values retrieved from the attributes of the member spectra.

If naming = "long" the names generated reflect both quantity and waveband, if naming = "short", names are based only on the wavebands, and if naming = "none" the returned vector has no names.

By default values are only integrated, but depending on the argument passed to parameter quantity they can be re-expressed as relative fractions or percentages. In the case of vector output, names attribute is set to the name of the corresponding waveband unless a named list is supplied in which case the names of the list members are used. The time.unit attribute is copied from the spectrum object to the output. Units are as follows: If time.unit is second, [W m-2 nm-1] -> [mol s-1 m-2] or [W m-2 nm-1] -> [W m-2] If time.unit is day, [J d-1 m-2 nm-1] -> [mol d-1 m-2] or [J d-1 m-2 nm-1] -> [J m-2]

Methods (by class)

  • irrad(default): Default for generic function

  • irrad(source_spct): Calculates irradiance from a source_spct object.

  • irrad(source_mspct): Calculates irradiance from a source_mspct object.

Note

Formal parameter allow.scaled is used internally for calculation of ratios, as rescaling and normalization do not invalidate the calculation of ratios.

The last two parameters control speed optimizations. The defaults should be suitable in most cases. If you will use repeatedly the same SWFs on many spectra measured at exactly the same wavelengths you may obtain some speed up by setting use.cached.mult=TRUE. However, be aware that you are responsible for ensuring that the wavelengths are the same in each call, as the only test done is for the length of the w.length vector.

See Also

Other irradiance functions: e_fluence(), e_irrad(), fluence(), q_fluence(), q_irrad()

Examples

irrad(sun.spct, waveband(c(400,700)))
irrad(sun.spct, waveband(c(400,700)), "energy")
irrad(sun.spct, waveband(c(400,700)), "photon")
irrad(sun.spct, split_bands(c(400,700), length.out = 3))
irrad(sun.spct, split_bands(c(400,700), length.out = 3), quantity = "total")
irrad(sun.spct, split_bands(c(400,700), length.out = 3), quantity = "average")
irrad(sun.spct, split_bands(c(400,700), length.out = 3), quantity = "relative")
irrad(sun.spct, split_bands(c(400,700), length.out = 3), quantity = "relative.pc")
irrad(sun.spct, split_bands(c(400,700), length.out = 3), quantity = "contribution")
irrad(sun.spct, split_bands(c(400,700), length.out = 3), quantity = "contribution.pc")

Photon or energy irradiance from spectral energy or photon irradiance.

Description

Energy or photon irradiance for one or more wavebands of a radiation spectrum.

Usage

irradiance(
  w.length,
  s.irrad,
  w.band = NULL,
  unit.out = NULL,
  unit.in = "energy",
  check.spectrum = TRUE,
  use.cached.mult = FALSE,
  use.hinges = getOption("photobiology.use.hinges", default = NULL)
)

Arguments

w.length

numeric Vector of wavelength [nmnm].

s.irrad

numeric vector of spectral (energy) irradiances [Wm2nm1W\,m^{-2}\,nm^{-1}].

w.band

waveband or list of waveband objects The waveband(s) determine the region(s) of the spectrum that are summarized.

unit.out, unit.in

character Allowed values "energy", and "photon", or its alias "quantum".

check.spectrum

logical Flag indicating whether to sanity check input data, default is TRUE.

use.cached.mult

logical Flag indicating whether multiplier values should be cached between calls.

use.hinges

logical Flag indicating whether to insert "hinges" into the spectral data before integration so as to reduce interpolation errors at the boundaries of the wavebands.

Value

A single numeric value or a vector of numeric values with no change in scale factor: [mols1sm2nm1mol\,s^{-1}\,sm^{-2}\,nm^{-1}] yields [mols1sm2mol\,s^{-1}\,sm^{-2}]

Note

The last three parameters control speed optimizations. The defaults should be suitable in most cases. If you set check.spectrum=FALSE then you should call check_spectrum() at least once for your spectrum before using any of the other functions. If you will use repeatedly the same SWFs on many spectra measured at exactly the same wavelengths you may obtain some speed up by setting use.cached.mult=TRUE. However, be aware that you are responsible for ensuring that the wavelengths are the same in each call, as the only test done is for the length of the w.length vector. The is no reason for setting use.cpp.code=FALSE other than for testing the improvement in speed, or in cases where there is no suitable C++ compiler for building the package.

See Also

Other low-level functions operating on numeric vectors.: as_energy(), as_quantum_mol(), calc_multipliers(), div_spectra(), energy_irradiance(), energy_ratio(), insert_hinges(), integrate_xy(), interpolate_spectrum(), l_insert_hinges(), oper_spectra(), photon_irradiance(), photon_ratio(), photons_energy_ratio(), prod_spectra(), s_e_irrad2rgb(), split_energy_irradiance(), split_photon_irradiance(), subt_spectra(), sum_spectra(), trim_tails(), v_insert_hinges(), v_replace_hinges()

Examples

with(sun.data, irradiance(w.length, s.e.irrad, new_waveband(400,700), "photon"))

Query if a spectrum contains absorbance or transmittance data

Description

Functions to query if an filter spectrum contains spectral absorbance data or spectral transmittance data.

Usage

is_absorbance_based(x)

is_absorptance_based(x)

is_transmittance_based(x)

Arguments

x

an R object

Value

is_absorbance_based returns a logical value, TRUE if its argument is a filter_spct object that contains spectral absorbance data and FALSE otherwise, but returns NA for any other R object, including those belonging other generic_spct-derived classes.

is_absorptance_based returns a logical value, if its argument is a filter_spct object, TRUE if it contains data as spectral absorptance and FALSE otherwise, but returns NA for any other R object, including those belonging other generic_spct-derived classes.

is_transmittance_based returns TRUE if its argument is a filter_spct object that contains spectral transmittance data and FALSE if it does not contain such data, but returns NA for any other R object, including those belonging other generic_spct-derived classes.

See Also

Other query units functions: is_mole_based(), is_photon_based()

Examples

is_absorbance_based(polyester.spct)
my.spct <- T2A(polyester.spct)
is.filter_spct(my.spct)
is_absorbance_based(my.spct)

is_absorptance_based(polyester.spct)

is_transmittance_based(polyester.spct)

Is an R object "effective"

Description

A generic function for querying if a biological spectral weighting function (BSWF) has been applied to an object or is included in its definition.

Usage

is_effective(x)

## Default S3 method:
is_effective(x)

## S3 method for class 'waveband'
is_effective(x)

## S3 method for class 'generic_spct'
is_effective(x)

## S3 method for class 'source_spct'
is_effective(x)

## S3 method for class 'summary_generic_spct'
is_effective(x)

## S3 method for class 'summary_source_spct'
is_effective(x)

Arguments

x

an R object

Value

A logical.

Methods (by class)

  • is_effective(default): Default method.

  • is_effective(waveband): Is a waveband object defining a method for calculating effective irradiance.

  • is_effective(generic_spct): Does a source_spct object contain effective spectral irradiance values.

  • is_effective(source_spct): Does a source_spct object contain effective spectral irradiance values.

  • is_effective(summary_generic_spct): Method for "summary_generic_spct".

  • is_effective(summary_source_spct): Method for "summary_source_spct".

See Also

Other waveband attributes: labels(), normalization()

Examples

is_effective(summary(sun.spct))

Query if a spectrum contains mole or mass based data

Description

Functions to check if an solute attenuation spectrum contains coefficients on expressed on mole of mass base.

Usage

is_mole_based(x)

is_mass_based(x)

Arguments

x

an R object

Value

is_mole_based returns TRUE if its argument is a solute_spct object that contains spectral K.mole data and FALSE if it contains K.mass data, but returns NA for any other R object, including those belonging other generic_spct-derived classes. is_mass_based returns the complement of is_mole_based.

See Also

Other query units functions: is_absorbance_based(), is_photon_based()

Examples

print("missing example")

Query whether a generic spectrum has been normalized.

Description

This function tests a generic_spct object for an attribute that signals whether the spectral data has been normalized or not after the object was created.

Usage

is_normalized(x)

is_normalised(x)

Arguments

x

An R object.

Value

A logical value indicating if x is normalized or not, for collections of spectra, a named list with logicals as members. If x is not a generic_spct or generic_mspct object the value returned is NA.

Note

is_normalised() is a synonym for this is_normalized() method.

See Also

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


Query if a spectrum contains photon- or energy-based data.

Description

Functions to query if source_spct and response_spct objects contain photon-based or energy-based data.

Usage

is_photon_based(x)

is_energy_based(x)

Arguments

x

any R object

Value

is_photon_based returns a logical value, TRUE if its argument is a source_spct or a response_spct object that contains photon base data and FALSE otherwise, but returns NA for any other R object, including those belonging other generic_spct-derived classes.

is_energy_based returns a logical value, TRUE if its argument is a source_spct or a response_spct object that contains energy base data and FALSE otherwise, but returns NA for any other R object, including those belonging other generic_spct-derived classes

See Also

Other query units functions: is_absorbance_based(), is_mole_based()

Examples

colnames(sun.spct)
is_photon_based(sun.spct)
my.spct <- sun.spct[ , c("w.length", "s.e.irrad")]
is.source_spct(my.spct)
is_photon_based(my.spct)

colnames(sun.spct)
is_energy_based(sun.spct)
my.spct <- sun.spct[ , c("w.length", "s.q.irrad")]
is.source_spct(my.spct)
is_energy_based(my.spct)

Query whether a generic spectrum has been scaled

Description

This function tests a generic_spct object for an attribute that signals whether the spectral data has been rescaled or not after the object was created.

Usage

is_scaled(x)

Arguments

x

An R object.

Value

A logical value. If x is not scaled or x is not a generic_spct object the value returned is FALSE.

See Also

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

Examples

scaled.spct <- fscale(sun.spct)
is_scaled(sun.spct)
is_scaled(scaled.spct)

Query if a spectrum is tagged

Description

Functions to check if an spct object contains tags.

Usage

is_tagged(x)

Arguments

x

any R object

Value

is_tagged returns a logical value, TRUE if its argument is a a spectrum that contains tags and FALSE if it is an untagged spectrum, but returns NA for any other R object.

See Also

Other tagging and related functions: tag(), untag(), wb2rect_spct(), wb2spct(), wb2tagged_spct()

Examples

is_tagged(sun.spct)

Query class of spectrum objects

Description

Functions to check if an object is of a given type of spectrum, or coerce it if possible.

Usage

is.generic_mspct(x)

is.calibration_mspct(x)

is.raw_mspct(x)

is.cps_mspct(x)

is.source_mspct(x)

is.response_mspct(x)

is.filter_mspct(x)

is.reflector_mspct(x)

is.object_mspct(x)

is.solute_mspct(x)

is.chroma_mspct(x)

is.any_mspct(x)

Arguments

x

an R object.

Value

These functions return TRUE if its argument is a of the queried type of spectrum and FALSE otherwise.

Note

Derived types also return TRUE for a query for a base type such as generic_mspct.

Examples

my.mspct <- filter_mspct(list(polyester.spct, yellow_gel.spct))
is.any_mspct(my.mspct)
is.filter_mspct(my.mspct)
is.source_mspct(my.mspct)

Query class of spectrum objects

Description

Functions to query whether an object is of a given type of spectrum.

Usage

is.generic_spct(x)

is.raw_spct(x)

is.calibration_spct(x)

is.cps_spct(x)

is.source_spct(x)

is.response_spct(x)

is.filter_spct(x)

is.reflector_spct(x)

is.object_spct(x)

is.solute_spct(x)

is.chroma_spct(x)

is.any_spct(x)

Arguments

x

an R object.

Value

A logical value, TRUE if the argument passed to x is an object of the queried type of spectrum and FALSE otherwise.

Note

Derived types also return TRUE for a query for a base type such as generic_spct, following R's practice.

Examples

is.source_spct(sun.spct)
is.filter_spct(sun.spct)
is.generic_spct(sun.spct)
is.generic_spct(sun.spct)

is.source_spct(sun.spct)
is.filter_spct(sun.spct)
is.generic_spct(sun.spct)
is.generic_spct(sun.spct)

Query if an object has old class names

Description

Query if an object has old class names Query if an object has old class names as used in photobiology (>= 0.6.0).

Usage

is.old_spct(object)

Arguments

object

an R object

Value

logical

See Also

Other upgrade from earlier versions: upgrade_spct(), upgrade_spectra()


Query class of spectrum summary objects

Description

Functions to check if an object is of a given type of spectrum, or coerce it if possible.

Usage

is.summary_generic_spct(x)

is.summary_raw_spct(x)

is.summary_cps_spct(x)

is.summary_source_spct(x)

is.summary_response_spct(x)

is.summary_filter_spct(x)

is.summary_reflector_spct(x)

is.summary_object_spct(x)

is.summary_solute_spct(x)

is.summary_chroma_spct(x)

is.any_summary_spct(x)

Arguments

x

an R object.

Value

These functions return TRUE if its argument is a of the queried type of spectrum and FALSE otherwise.

Note

Derived types also return TRUE for a query for a base type such as generic_spct.

Examples

sm <- summary(sun.spct)
is.summary_source_spct(sm)

Query if it is a waveband

Description

Functions to check if an object is waveband.

Usage

is.waveband(x)

Arguments

x

any R object

Value

is.waveband returns TRUE if its argument is a waveband and FALSE otherwise.


Check the "instr.desc" attribute

Description

Function to validate the "instr.settings" attribute of an existing generic_spct object.

Usage

isValidInstrDesc(x)

Arguments

x

a generic_spct object

Value

logical TRUE if at least instrument name and serial number is found.

See Also

Other measurement metadata functions: add_attr2tb(), getFilterProperties(), getHowMeasured(), getInstrDesc(), getInstrSettings(), getSoluteProperties(), getWhatMeasured(), getWhenMeasured(), getWhereMeasured(), get_attributes(), isValidInstrSettings(), select_spct_attributes(), setFilterProperties(), setHowMeasured(), setInstrDesc(), setInstrSettings(), setSoluteProperties(), setWhatMeasured(), setWhenMeasured(), setWhereMeasured(), spct_attr2tb(), spct_metadata(), subset_attributes(), trimInstrDesc(), trimInstrSettings()


Check the "instr.settings" attribute

Description

Function to validate the "instr.settings" attribute of an existing generic_spct object.

Usage

isValidInstrSettings(x)

Arguments

x

a generic_spct object

Value

logical TRUE if at least integration time data is found.

See Also

Other measurement metadata functions: add_attr2tb(), getFilterProperties(), getHowMeasured(), getInstrDesc(), getInstrSettings(), getSoluteProperties(), getWhatMeasured(), getWhenMeasured(), getWhereMeasured(), get_attributes(), isValidInstrDesc(), select_spct_attributes(), setFilterProperties(), setHowMeasured(), setInstrDesc(), setInstrSettings(), setSoluteProperties(), setWhatMeasured(), setWhenMeasured(), setWhereMeasured(), spct_attr2tb(), spct_metadata(), subset_attributes(), trimInstrDesc(), trimInstrSettings()


Join all spectra in a collection

Description

Join all the spectra contained in a homogeneous collection, returning a data frame with spectral-data columns named according to the names of the spectra in the collection. By default a full join is done within the overlapping range of wavelengths, after interpolating the spectra to a shared set of wavelength values, and discarding data for wavelength not shared. Alternatively, filling the spectral data for wavelengths outside the overlapping range with with NA when data is not available.

Usage

join_mspct(x, type, ...)

## Default S3 method:
join_mspct(x, type = "full", ...)

## S3 method for class 'generic_mspct'
join_mspct(x, type = "full", col.name, validate.names = TRUE, ...)

## S3 method for class 'source_mspct'
join_mspct(x, type = "full", unit.out = "energy", validate.names = TRUE, ...)

## S3 method for class 'response_mspct'
join_mspct(x, type = "full", unit.out = "energy", validate.names = TRUE, ...)

## S3 method for class 'filter_mspct'
join_mspct(
  x,
  type = "full",
  qty.out = "transmittance",
  validate.names = TRUE,
  ...
)

## S3 method for class 'reflector_mspct'
join_mspct(x, type = "full", validate.names = TRUE, ...)

## S3 method for class 'object_mspct'
join_mspct(x, type = "full", qty.out, validate.names = TRUE, ...)

## S3 method for class 'solute_mspct'
join_mspct(x, type = "full", validate.names = TRUE, ...)

Arguments

x

generic_mspct object, or an object of a class derived from generic_mspct.

type

character Type of join: "inner" (default) or "full". See details for more information.

...

ignored (possibly used by derived methods).

col.name

character, name of the column in the spectra to be preserved, in addition to "w.length".

validate.names

logical A flag to enable (default) or disable validation of column names with make.names.

unit.out

character Allowed values "energy", and "photon", or its alias "quantum".

qty.out

character Allowed values "transmittance", "absorptance", and "absorbance" and in the method for object_spct, also "reflectance" (.

Value

A data.frame with the spectra joined by, possibly interpolated, wavelength, with rows sorted by wavelength (variable w.length) and data columns named according to the names of members in x, by default made unique and valid.

Methods (by class)

  • join_mspct(default):

  • join_mspct(generic_mspct):

  • join_mspct(source_mspct):

  • join_mspct(response_mspct):

  • join_mspct(filter_mspct):

  • join_mspct(reflector_mspct):

  • join_mspct(object_mspct):

  • join_mspct(solute_mspct):

Note

Currently only generic_spct, source_mspct, response_mspct, filter_mspct, reflector_mspct, object_mspct and solute_mspct classes have this method implemented.

Examples

my.mspct <- solute_mspct(list(water = water.spct, pha = phenylalanine.spct))
join_mspct(my.mspct, type = "inner")
join_mspct(my.mspct, type = "full")

Find labels from "waveband" object

Description

A method specialization that extracts the name and label of objects of class waveband.

Usage

## S3 method for class 'waveband'
labels(object, ...)

## S3 method for class 'generic_spct'
labels(object, ...)

Arguments

object

an object of class "waveband"

...

not used in current version

Methods (by class)

  • labels(generic_spct):

See Also

Other waveband attributes: is_effective(), normalization()

Examples

labels(sun.spct)

Green Arabidopsis leaf reflectance and transmittance.

Description

A dataset of total spectral reflectance and total spectral transmittance expressed as fractions of one from the upper surface of a leaf of an Arabidopsis thaliana 'Ler' rosette.

Usage

Ler_leaf.spct

Ler_leaf_rflt.spct

Ler_leaf_trns.spct

Ler_leaf_trns_i.spct

Format

Datasets stored as object_spct, reflector_spct and filter_spct objects, containing transmittance and reflectance data.

An object of class reflector_spct (inherits from generic_spct, tbl_df, tbl, data.frame) with 1750 rows and 2 columns.

An object of class filter_spct (inherits from generic_spct, tbl_df, tbl, data.frame) with 1753 rows and 2 columns.

An object of class filter_spct (inherits from generic_spct, tbl_df, tbl, data.frame) with 2401 rows and 3 columns.

Details

  • w.length (nm)

  • Rfr (0..1)

  • Tfr (0..1)

Note

Measured with a Jaz spectrometer from Ocean Optics (USA) configured with a PX Xenon lamp module and Spectroclip double integrating spheres.

Author(s)

Aphalo, P. J. & Wang, F (unpublished data)

See Also

Other Spectral data examples: A.illuminant.spct, D50.illuminant.spct, D65.illuminant.spct, black_body.spct, ccd.spct, clear.spct, filter_cps.mspct, green_leaf.spct, phenylalanine.spct, photodiode.spct, sun.spct, sun_daily.spct, sun_evening.spct, two_filters.spct, two_sensors.mspct, water.spct, white_led.source_spct

Examples

Ler_leaf.spct
Ler_leaf_rflt.spct

Logarithms and Exponentials

Description

Logarithms and Exponentials for Spectra. The functions are applied to the spectral data, not the wavelengths. The quantity in the spectrum to which the function is applied depends on the class of x and the current value of output options

Usage

## S3 method for class 'generic_spct'
log(x, base = exp(1))

## S3 method for class 'generic_spct'
log2(x)

## S3 method for class 'generic_spct'
log10(x)

## S3 method for class 'generic_spct'
exp(x)

Arguments

x

an object of class "generic_spct"

base

a positive number: the base with respect to which logarithms are computed. Defaults to e=exp(1).

Value

An object of the same class as x.

Note

In most cases a logarithm of an spectral quantity will yield off-range values. For this reason unless x is an object of base class generic_spct, checks will not be passed, resulting in warnings or errors.

See Also

Other math operators and functions: MathFun, ^.generic_spct(), convolve_each(), div-.generic_spct, minus-.generic_spct, mod-.generic_spct, plus-.generic_spct, round(), sign(), slash-.generic_spct, times-.generic_spct


Column or variable labels

Description

Create a named list of character strings describing the variables contained in a spectrum object.

Usage

make_var_labels(x, ...)

## Default S3 method:
make_var_labels(x, ...)

## S3 method for class 'source_spct'
make_var_labels(x, ...)

## S3 method for class 'response_spct'
make_var_labels(x, ...)

## S3 method for class 'filter_spct'
make_var_labels(x, ...)

## S3 method for class 'reflector_spct'
make_var_labels(x, ...)

## S3 method for class 'object_spct'
make_var_labels(x, ...)

## S3 method for class 'solute_spct'
make_var_labels(x, ...)

## S3 method for class 'chroma_spct'
make_var_labels(x, ...)

## S3 method for class 'calibration_spct'
make_var_labels(x, ...)

## S3 method for class 'raw_spct'
make_var_labels(x, ...)

## S3 method for class 'cps_spct'
make_var_labels(x, ...)

Arguments

x

An object of a class derived from generic_spct.

...

Currently ignored.

Details

Objects of classes derived from generic_spct are used to store different types of spectral data. The data stored in some of the classes needs to be interpreted differently depending on how they were measured or are expressed and this information is stored in attributes of the objects. In other cases, even if consistent across different objects, the units of expression may not be obvious to users. The names of the variables are concise, thus using variable labels makes it possible to make these features visible when exploring the data. The methods provided do not add the labels, only supply the character strings. Variable labels are implemented in packages 'labelled' by setting the label attribute in each variable (= column) of a data frame or tibble. This is compatible with the approach used by package 'haven'.

Value

A named list of character strings with one member for each recognized column in x. This list can be used to set variable labels with methods from package 'labelled'. However, package 'photobiology' does not natively support variable labels stored in attribute label.

Methods (by class)

  • make_var_labels(default):

  • make_var_labels(source_spct):

  • make_var_labels(response_spct):

  • make_var_labels(filter_spct):

  • make_var_labels(reflector_spct):

  • make_var_labels(object_spct):

  • make_var_labels(solute_spct):

  • make_var_labels(chroma_spct):

  • make_var_labels(calibration_spct):

  • make_var_labels(raw_spct):

  • make_var_labels(cps_spct):

Note

These methods are still under development and the text of the labels may change. Not all classes derived from generic_spct are yet supported.

Examples

make_var_labels(sun.spct)
# str() prints more compactly than print()
str(make_var_labels(sun.spct))
str(make_var_labels(normalize(sun.spct)))
str(make_var_labels(fscale(sun.spct)))

str(make_var_labels(sun_daily.spct))

str(make_var_labels(polyester.spct))
str(make_var_labels(normalize(polyester.spct)))
str(make_var_labels(fscale(polyester.spct)))

str(make_var_labels(white_led.cps_spct))
str(make_var_labels(white_led.raw_spct))

Miscellaneous Mathematical Functions

Description

abs(x) computes the absolute value of x, sqrt(x) computes the (principal) square root of x. The functions are applied to the spectral data, not the wavelengths. The quantity in the spectrum to which the function is applied depends on the class of x and the current value of output options.

Usage

## S3 method for class 'generic_spct'
sqrt(x)

## S3 method for class 'generic_spct'
abs(x)

Arguments

x

an object of class "generic_spct"

See Also

Other math operators and functions: ^.generic_spct(), convolve_each(), div-.generic_spct, log(), minus-.generic_spct, mod-.generic_spct, plus-.generic_spct, round(), sign(), slash-.generic_spct, times-.generic_spct


Merge and copy attributes

Description

Merge attributes from x and y and copy them to z. Methods defined for spectral objects of classes from package 'photobiology'.

Usage

merge_attributes(x, y, z, which, which.not, ...)

## Default S3 method:
merge_attributes(x, y, z, which = NULL, which.not = NULL, ...)

## S3 method for class 'generic_spct'
merge_attributes(
  x,
  y,
  z,
  which = NULL,
  which.not = NULL,
  copy.class = FALSE,
  ...
)

Arguments

x, y, z

R objects. Objects x and y must be of the same class, z must be an object with a structure valid for this same class.

which

character Names of attributes to copy, if NULL all those relevant according to the class of x are used as default,

which.not

character Names of attributes not to be copied. The names passed here are removed from the list for which, which is most useful when we want to modify the default.

...

not used

copy.class

logical If TRUE class attributes are also copied.

Value

A copy of z with additional attributes set.

Methods (by class)

  • merge_attributes(default): Default for generic function

  • merge_attributes(generic_spct):


Merge into object_spct

Description

Merge a filter_spct with a reflector_spct returning an object_spct object, even if wavelength values are mismatched.

Usage

merge2object_spct(
  x,
  y,
  by = "w.length",
  ...,
  w.length.out = x[["w.length"]],
  Tfr.type.out = "total"
)

Arguments

x, y

a filter_spct object and a reflector_spct object.

by

a vector of shared column names in x and y to merge on; by defaults to w.length.

...

other arguments passed to dplyr::inner_join().

w.length.out

numeric vector of wavelengths to be used for the returned object (nmnm).

Tfr.type.out

character string indicating whether transmittance values in the returned object should be expressed as "total" or "internal". This applies only to the case when an object_spct is returned.

Value

An object_spct is returned as the result of merging a filter_spct and a reflector_spct object.

Note

If a numeric vector is supplied as argument for w.length.out, the two spectra are interpolated to the new wavelength values before merging. The default argument for w.length.out is x[["w.length"]].

See Also

join


Arithmetic Operators

Description

Subtraction operator for generic spectra.

Usage

## S3 method for class 'generic_spct'
e1 - e2 = NULL

Arguments

e1

an object of class "generic_spct"

e2

an object of class "generic_spct"

See Also

Other math operators and functions: MathFun, ^.generic_spct(), convolve_each(), div-.generic_spct, log(), mod-.generic_spct, plus-.generic_spct, round(), sign(), slash-.generic_spct, times-.generic_spct


Arithmetic Operators

Description

Reminder operator for generic spectra.

Usage

## S3 method for class 'generic_spct'
e1 %% e2

Arguments

e1

an object of class "generic_spct"

e2

an object of class "generic_spct"

See Also

Other math operators and functions: MathFun, ^.generic_spct(), convolve_each(), div-.generic_spct, log(), minus-.generic_spct, plus-.generic_spct, round(), sign(), slash-.generic_spct, times-.generic_spct


Multi-spct transform methods

Description

Apply a function or operator to a collection of spectra.

Usage

msmsply(mspct, .fun, ..., .parallel = FALSE, .paropts = NULL)

msdply(
  mspct,
  .fun,
  ...,
  idx = NULL,
  col.names = NULL,
  .parallel = FALSE,
  .paropts = NULL
)

mslply(mspct, .fun, ..., .parallel = FALSE, .paropts = NULL)

msaply(mspct, .fun, ..., .drop = TRUE, .parallel = FALSE, .paropts = NULL)

Arguments

mspct

an object of class generic_mspct or a derived class

.fun

a function

...

other arguments passed to .fun

.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.

idx

character Name of the column with the names of the members of the collection of spectra.

col.names

character Names to be used for data columns.

.drop

should extra dimensions of length 1 in the output be dropped, simplifying the output. Defaults to TRUE

Value

a collection of spectra in the case of msmsply, belonging to a different class than mspct if .fun modifies the class of the member spectra.

a data frame in the case of msdply

a list in the case of mslply

an vector in the case of msaply


Names of multi-spectra classes

Description

Function that returns a vector containing the names of multi-spectra classes using for collections of spectra.

Usage

mspct_classes()

Value

A character vector of class names.

Examples

mspct_classes()

Handle Missing Values in Objects

Description

These methods are useful for dealing with NAs in e.g., source_spct, response_spct, filter_spct and reflector_spct.

Usage

## S3 method for class 'generic_spct'
na.omit(object, na.action = "omit", fill = NULL, target.colnames, ...)

## S3 method for class 'source_spct'
na.omit(object, na.action = "omit", fill = NULL, ...)

## S3 method for class 'response_spct'
na.omit(object, na.action = "omit", fill = NULL, ...)

## S3 method for class 'filter_spct'
na.omit(object, na.action = "omit", fill = NULL, ...)

## S3 method for class 'reflector_spct'
na.omit(object, na.action = "omit", fill = NULL, ...)

## S3 method for class 'object_spct'
na.omit(object, na.action = "omit", fill = NULL, ...)

## S3 method for class 'solute_spct'
na.omit(object, na.action = "omit", fill = NULL, ...)

## S3 method for class 'cps_spct'
na.omit(object, na.action = "omit", fill = NULL, ...)

## S3 method for class 'raw_spct'
na.omit(object, na.action = "omit", fill = NULL, ...)

## S3 method for class 'chroma_spct'
na.omit(object, na.action = "omit", fill = NULL, ...)

## S3 method for class 'generic_mspct'
na.omit(object, na.action = "omit", fill = NULL, ...)

## S3 method for class 'generic_spct'
na.exclude(object, na.action = "exclude", fill = NULL, target.colnames, ...)

## S3 method for class 'source_spct'
na.exclude(object, na.action = "exclude", fill = NULL, ...)

## S3 method for class 'response_spct'
na.exclude(object, na.action = "exclude", fill = NULL, ...)

## S3 method for class 'filter_spct'
na.exclude(object, na.action = "exclude", fill = NULL, ...)

## S3 method for class 'reflector_spct'
na.exclude(object, na.action = "exclude", fill = NULL, ...)

## S3 method for class 'object_spct'
na.exclude(object, na.action = "exclude", fill = NULL, ...)

## S3 method for class 'solute_spct'
na.exclude(object, na.action = "exclude", fill = NULL, ...)

## S3 method for class 'cps_spct'
na.exclude(object, na.action = "exclude", fill = NULL, ...)

## S3 method for class 'raw_spct'
na.exclude(object, na.action = "exclude", fill = NULL, ...)

## S3 method for class 'chroma_spct'
na.exclude(object, na.action = "exclude", fill = NULL, ...)

## S3 method for class 'generic_mspct'
na.exclude(object, na.action = "exclude", fill = NULL, ...)

Arguments

object

an R object

na.action

character One of "omit", "exclude" or "replace".

fill

numeric Value used to replace NAs unless NULL, in which case interpolation is attempted.

target.colnames

character Vector of names for the target columns to operate upon, if present in object.

...

further arguments other special methods could require

Details

If na.omit removes cases, the row numbers of the cases form the "na.action" attribute of the result, of class "omit".

na.exclude differs from na.omit only in the class of the "na.action" attribute of the result, which is "exclude".

Note

na.fail and na.pass do not require a specialisation for spectral objects. R's definitions work as expected with no need to override them. We do not define a method na.replace, just pass "replace" as argument. The current implementation replaces by interpolation only individual NAs which are flanked on both sides by valid data. Runs of multiple NAs con only replaced by a constant value passed through parameter fill.

See Also

na.fail and na.action

Examples

my_sun.spct <- sun.spct
my_sun.spct[3, "s.e.irrad"] <- NA
my_sun.spct[5, "s.q.irrad"] <- NA

head(my_sun.spct)

# rows omitted
zo <- na.omit(my_sun.spct)
head(zo)
na.action(zo)

# rows excluded
ze <- na.exclude(my_sun.spct)
head(ze)
na.action(ze)

# data in both rows replaced
zr <- na.omit(my_sun.spct, na.action = "replace")
head(zr)
na.action(zr)

Normalization of an R object

Description

Normalization wavelength [nmnm] and other normalization metadata of an R object, retrieved from the object's attributes.

Usage

normalization(x)

## Default S3 method:
normalization(x)

## S3 method for class 'waveband'
normalization(x)

## S3 method for class 'generic_spct'
normalization(x)

## S3 method for class 'summary_generic_spct'
normalization(x)

## S3 method for class 'generic_mspct'
normalization(x)

Arguments

x

an R object

Details

In the case of wavebands for spectral weighting functions (waveband objects), the normalization wavelength is returned. For spectral objects (generic_spct and derived ), the normalization descriptor, a list object, is returned. This list contains in addition to the normalization wavelength, the multiplier used and type of normalization applied. These metadata makes it possible to "undo" the normalization and to "update" the normalization after a transformation, such as conversion to a related physical quantity, of the spectral data.

Value

A single numeric value of wavelength [nmnm] or a list with with members.

Methods (by class)

  • normalization(default): Default methods.

  • normalization(waveband): Normalization of a waveband object.

  • normalization(generic_spct): Normalization of a generic_spct object.

  • normalization(summary_generic_spct): Normalization of a summary.generic_spct object.

  • normalization(generic_mspct): Normalization of a generic_mspct object.

Note

Older versions of the package stored only a subset of the metadata or only a flag to indicate that normalization had been applied. For such objects some or even all fields in the returned list are set to NA.

See Also

Other waveband attributes: is_effective(), labels()

Examples

is_normalized(sun.spct)
normalization(sun.spct)
sun_norm.spct <- normalize(sun.spct)
is_normalized(sun_norm.spct)
normalization(sun_norm.spct)

my_wband <- waveband(c(400,700))
is_normalized(my_wband)
normalization(my_wband)

Normalize spectral data

Description

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. When the object contains multiple spectra, the normalisation is applied to each spectrum individually.

Usage

normalize(x, ...)

normalise(x, ...)

## Default S3 method:
normalize(x, ...)

## S3 method for class 'source_spct'
normalize(
  x,
  ...,
  range = NULL,
  norm = "max",
  unit.out = NA,
  keep.scaling = FALSE,
  na.rm = FALSE
)

## S3 method for class 'response_spct'
normalize(
  x,
  ...,
  range = NULL,
  norm = "max",
  unit.out = NA,
  keep.scaling = FALSE,
  na.rm = FALSE
)

## S3 method for class 'filter_spct'
normalize(
  x,
  ...,
  range = NULL,
  norm = "max",
  qty.out = NA,
  keep.scaling = FALSE,
  na.rm = FALSE
)

## S3 method for class 'reflector_spct'
normalize(
  x,
  ...,
  range = NULL,
  norm = "max",
  qty.out = NA,
  keep.scaling = FALSE,
  na.rm = FALSE
)

## S3 method for class 'solute_spct'
normalize(
  x,
  ...,
  range = NULL,
  norm = "max",
  qty.out = NA,
  keep.scaling = FALSE,
  na.rm = FALSE
)

## S3 method for class 'raw_spct'
normalize(
  x,
  ...,
  range = NULL,
  norm = "max",
  keep.scaling = FALSE,
  na.rm = FALSE
)

## S3 method for class 'cps_spct'
normalize(
  x,
  ...,
  range = NULL,
  norm = "max",
  keep.scaling = FALSE,
  na.rm = FALSE
)

## S3 method for class 'generic_spct'
normalize(
  x,
  ...,
  range = NULL,
  norm = "max",
  col.names,
  keep.scaling = FALSE,
  na.rm = FALSE
)

## S3 method for class 'source_mspct'
normalize(
  x,
  ...,
  range = NULL,
  norm = "max",
  unit.out = NA,
  keep.scaling = FALSE,
  na.rm = FALSE,
  .parallel = FALSE,
  .paropts = NULL
)

## S3 method for class 'response_mspct'
normalize(
  x,
  ...,
  range = NULL,
  norm = "max",
  unit.out = NA,
  keep.scaling = FALSE,
  na.rm = FALSE,
  .parallel = FALSE,
  .paropts = NULL
)

## S3 method for class 'filter_mspct'
normalize(
  x,
  ...,
  range = NULL,
  norm = "max",
  qty.out = NA,
  keep.scaling = FALSE,
  na.rm = FALSE,
  .parallel = FALSE,
  .paropts = NULL
)

## S3 method for class 'reflector_mspct'
normalize(
  x,
  ...,
  range = x,
  norm = "max",
  qty.out = NA,
  keep.scaling = FALSE,
  na.rm = FALSE,
  .parallel = FALSE,
  .paropts = NULL
)

## S3 method for class 'raw_mspct'
normalize(
  x,
  ...,
  range = x,
  norm = "max",
  keep.scaling = FALSE,
  na.rm = FALSE,
  .parallel = FALSE,
  .paropts = NULL
)

## S3 method for class 'cps_mspct'
normalize(
  x,
  ...,
  range = x,
  norm = "max",
  keep.scaling = FALSE,
  na.rm = FALSE,
  .parallel = FALSE,
  .paropts = NULL
)

## S3 method for class 'solute_mspct'
normalize(
  x,
  ...,
  range = x,
  norm = "max",
  qty.out = NA,
  keep.scaling = FALSE,
  na.rm = FALSE,
  .parallel = FALSE,
  .paropts = NULL
)

## S3 method for class 'generic_mspct'
normalize(
  x,
  ...,
  range = NULL,
  norm = "max",
  col.names,
  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, "undo" to revert an existing normalization or "skip" to force return of x unchanged.

unit.out

No longer supported and is ignored with a warning.

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

No longer supported and is ignored with a warning..

col.names

character vector containing the names of columns or variables. Columns in x matching the names in col.names are normalized, other columns are returned unchanged.

.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.

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. An existing normalization can be updated for a different unit 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, e.g., for the maximum, can be limited to a range of wavelengths of interest instead of the whole 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, except for possible accumulated loss of precision due to floating-point arithmetic, independently of the previous application of a different normalization.

Value

A copy of the object passed as argument to 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.

Methods (by class)

  • normalize(default): Default for generic function

  • normalize(source_spct): Normalize a source_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.

  • normalize(solute_mspct): Normalize the members of a solute_mspct object.

  • normalize(generic_mspct): Normalize the members of a solute_mspct object.

Note

When the spectrum passed as argument to x had 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.

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.

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.

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, normalization is unlikely to useful. To represent solutions of specific concentrations of solutes, filter_spct objects should be used instead.

normalise() is a synonym for this normalize() method.

See Also

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

Examples

normalize(sun.spct)
normalise(sun.spct) # equivalent

normalize(sun.spct, norm = "max")
normalize(sun.spct, norm = 400)

Normalize a range argument into a true numeric range

Description

Several functions in this package and the suite accept a range argument with a flexible syntax. To ensure that all functions and methods behave in the same way this code has been factored out into a separate function.

Usage

normalize_range_arg(arg.range, wl.range, trim = TRUE)

Arguments

arg.range

a numeric vector of length two, or any other object for which function range() will return a range of wavelengths (nm).

wl.range

a numeric vector of length two, or any other object for which function range() will return a range of wavelengths (nm), missing values are not allowed.

trim

logical If TRUE the range returned is bound within wl.range while if FALSE it can be broader.

Details

The arg.range argument can contain NAs which are replaced by the value at the same position in wl.range. In addition a NULL argument for range is converted into wl.range. The wl.range is also the limit to which the returned value is trimmed if trim == TRUE. The idea is that the value supplied as wl.range is the wavelength range of the data.

Value

a numeric vector of length two, guaranteed not to have missing values.

Examples

normalize_range_arg(c(NA, 500), range(sun.spct))
normalize_range_arg(c(300, NA), range(sun.spct))
normalize_range_arg(c(100, 5000), range(sun.spct), FALSE)
normalize_range_arg(c(NA, NA), range(sun.spct))
normalize_range_arg(c(NA, NA), sun.spct)

Calculate a normalized difference.

Description

This method returns a normalized difference index value for an arbitrary pair of wavebands. There are many such indexes in use, such as NDVI (normalized difference vegetation index), NDWI (normalized difference water index), NDMI (normalized difference moisture index), etc., the only difference among then is in the wavebands used.

Usage

normalized_diff_ind(spct, w.band.plus, w.band.minus, f, ...)

normalised_diff_ind(spct, w.band.plus, w.band.minus, f, ...)

NDxI(spct, w.band.plus, w.band.minus, f, ...)

## Default S3 method:
normalized_diff_ind(spct, w.band.plus, w.band.minus, f, ...)

## S3 method for class 'generic_spct'
normalized_diff_ind(spct, w.band.plus, w.band.minus, f, ...)

## S3 method for class 'generic_mspct'
normalized_diff_ind(spct, w.band.plus, w.band.minus, f, ...)

Arguments

spct

an R object

w.band.plus, w.band.minus

waveband objects The wavebands determine the regions of the spectrum used in the calculations.

f

function used for integration taking spct as first argument and a list of wavebands as second argument.

...

additional arguments passed to f

Details

f is most frequently reflectance, but also transmittance, or even absorbance, response, irradiance or a user-defined function can be used if there is a good reason for it. In every case spct should be of the class expected by f. When using two wavebands of different widths do consider passing to f a suitable quantity argument, for example to compare averages rather than integrals. Wavebands can describe weighting functions if desired.

NDxI=f(s,wbplus)f(s,wbminus)f(s,wbplus)+f(s,wbminus)\mathrm{NDxI} = \frac{f(s, wb_\mathrm{plus}) - f(s, wb_\mathrm{minus})}{f(s, wb_\mathrm{plus}) + f(s, wb_\mathrm{minus})}