Learn R Programming

photobiology

Package ‘photobiology’ defines a system of classes for storing spectral data and accompanying metadata. For each of these classes specialised summary methods, maths operators and functions are provided. In addition, classes for storing collections of objects of the classes for individual spectra are defined as well as ‘apply’ functions. Extraction and replacement operators are implemented.

Functions for calculation of the position of the sun, times of sunrise and sunset, day length and night length are also available. Starting from ‘photobiology’ 0.12.0 they are imported from package ‘SunCalcMeeus’, which is a spin-off of ’photobiology. If you only use these functions, you can attach or load ‘SunCalcMeeus’ instead of ‘photobiology’, otherwise, the only visible change is that the on-line help is at a separate site.

Functions for the estimation of evapotranspiration and the energy balance of vegetation have been migrated to package ‘photobiologyPlants’ as they are related to vegetation. To use them with this version of package ‘photobiology’, please, add library(photobiologyPlants) to your code.

The package supports storage and manipulation of data for radiation quantities and for optical properties of objects and solutes, as well as response and action spectra for photobiological, photochemical and photoelectrical responses.

This package is the core of a suite of R packages for photobiological calculations described at the r4photobiology web site and in the vignette The R for Photobiology Suite.

Examples

The first example shows you how to estimate solar irradiance in W/m2 under a filter. We use a measured solar spectrum and a measured filter transmission spectrum.

library(photobiology)
e_irrad(sun.spct * yellow_gel.spct)
#>  E_Total 
#> 146.5053 
#> attr(,"time.unit")
#> [1] "second"
#> attr(,"radiation.unit")
#> [1] "total energy irradiance"

The second example shows some simple astronomical calculations for the sun.

geocode <- data.frame(lon = 0, lat = 55)
date <- lubridate::now(tzone = "UTC")
sunrise_time(date, tz = "UTC", geocode = geocode)
#> [1] "2025-01-12 08:18:17 UTC"
day_length(date, tz = "UTC", geocode = geocode)
#> [1] 7.670362

Installation

Installation of the most recent stable version from CRAN:

install.packages("photobiology")

Installation of the current unstable version from R-Universe CRAN-like repository:

install.packages('photobiology', 
                 repos = c('https://aphalo.r-universe.dev', 
                           'https://cloud.r-project.org'))

Once package ‘photobiology’ is installed, installation of the remaining or missing packages in the suite from CRAN (or by adding the repository information as above, from R-Universe):

intalled_pkgs <- installed.packages()[ , 1]
missing_pkgs <- setdiff(photobiology::r4p_pkgs, intalled_pkgs)
if (length(missing_pkgs) > 0) {
 install.packages(missing_pkgs)
}

Installation of the current unstable version from GitHub:

# install.packages("devtools")
devtools::install_github("aphalo/photobiology")

Documentation

HTML documentation is available at (https://docs.r4photobiology.info/photobiology/), including three User Guides.

News on updates to the different packages of the ‘r4photobiology’ suite are regularly posted at (https://www.r4photobiology.info/).

Two articles introduce the basic ideas behind the design of the suite and describe its use: Aphalo P. J. (2015) (https://doi.org/10.19232/uv4pb.2015.1.14) and Aphalo P. J. (2016) (https://doi.org/10.19232/uv4pb.2016.1.15).

A book is under preparation, and the draft is currently available at (https://leanpub.com/r4photobiology/).

A handbook written before the suite was developed contains useful information on the quantification and manipulation of ultraviolet and visible radiation: 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. xxx + 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). PDF file available from (https://hdl.handle.net/10138/37558).

Contributing

Pull requests, bug reports, and feature requests are welcome at (https://github.com/aphalo/photobiology).

Citation

If you use this package to produce scientific or commercial publications, please cite according to:

citation("photobiology")
#> To cite package ‘photobiology’ in publications use:
#> 
#>   Aphalo, Pedro J. (2015) The r4photobiology suite. UV4Plants Bulletin,
#>   2015:1, 21-29. DOI:10.19232/uv4pb.2015.1.14
#> 
#> A BibTeX entry for LaTeX users is
#> 
#>   @Article{,
#>     author = {Pedro J. Aphalo},
#>     title = {The r4photobiology suite},
#>     journal = {UV4Plants Bulletin},
#>     volume = {2015},
#>     number = {1},
#>     pages = {21-29},
#>     year = {2015},
#>     doi = {10.19232/uv4pb.2015.1.14},
#>   }

License

© 2012-2025 Pedro J. Aphalo (pedro.aphalo@helsinki.fi). Released under the GPL, version 2 or greater. This software carries no warranty of any kind.

Copy Link

Version

Install

install.packages('photobiology')

Monthly Downloads

1,630

Version

0.12.0

License

GPL (>= 2)

Issues

Pull Requests

Stars

Forks

Maintainer

Pedro Aphalo

Last Published

February 2nd, 2025

Functions in photobiology (0.12.0)

FEL_spectrum

Incandescent "FEL" lamp emission spectrum
Tfr_ratio

transmittance:transmittance ratio
D2_spectrum

Calculate deuterium lamp output spectrum from fitted constants
D50.illuminant.spct

CIE D50 illuminant data
Tfr_fraction

transmittance:transmittance fraction
Tfr_normdiff

transmittance:transmittance normalised difference
absorbance

Absorbance
Trig

Trigonometric Functions
absorbance_spct

Calculate absorbance from spectral absorbance.
Rfr_ratio

reflectance:reflectance ratio
Rfr_normdiff

reflectance:reflectance normalised difference
as.chroma_spct

Coerce to a spectrum
any2T

Convert filter quantities.
as.cps_mspct

Coerce to a collection-of-spectra
Rfr_fraction

reflectance:reflectance fraction
adaptive_smoothing

Custom smoothing
as.calibration_mspct

Coerce to a collection-of-spectra
as.filter_mspct

Coerce to a collection-of-spectra
as.cps_spct

Coerce to a spectrum
absorptance

Absorptance
as.generic_spct

Coerce to a spectrum
add_attr2tb

Copy attributes from members of a generic_mspct
as.matrix-mspct

Coerce a collection of spectra into a matrix
as.response_mspct

Coerce to a collection-of-spectra
Rfr_from_n

Reflectance at a planar boundary
as.response_spct

Coerce to a spectrum
check_spectrum

Sanity check a spectrum
check_w.length

Sanity check of wavelengths (internal function).
average_spct

Average spectral data.
beesxyzCMF.spct

Honeybee xyz chromaticity colour matching function data
ciexyzCC2.spct

CIE xyz chromaticity coordinates 2 deg data
T2A

Convert transmittance into absorbance.
T2Afr

Convert transmittance into absorptance.
ciexyzCC10.spct

CIE xyz chromaticity coordinates (CC) 10 deg data
as.source_mspct

Coerce to a collection-of-spectra
as.source_spct

Coerce to a spectrum
as_quantum_mol

Convert spectral energy irradiance into spectral photon irradiance
auto_hinges

Guess whether insertion of hinges is needed or not
collect2mspct

Form a new collection
absorptance_spct

Calculate absorptance from spectral absorptance.
e_irrad

Energy irradiance
e_fraction

Energy:energy fraction
dim.generic_mspct

Dimensions of an Object
color_of

Color of an object
div-.generic_spct

Arithmetic Operators
as.generic_mspct

Coerce to a collection-of-spectra
as.filter_spct

Coerce or convert into a filter spectrum
ccd.spct

Spectral response of a back-thinned CCD image sensor.
eq_ratio

Energy:photon ratio
clip_wl

Clip head and/or tail of a spectrum
clear_photobio.cache

Clear the spectral weights cache
spread

Expanse
as.reflector_mspct

Coerce to a collection-of-spectra
compare_spct

Coarse-grained comparison of two spectra
as.raw_mspct

Coerce to a collection-of-spectra
as.raw_spct

Coerce to a spectrum
calc_multipliers

Spectral weights
as.calibration_spct

Coerce to a spectrum
as.chroma_mspct

Coerce to a collection-of-spectra
checkMspctVersion

Check that the "mspct.version" attribute is set
calc_source_output

Scaled and/or interpolated light-source spectral output
ciev10.spct

Linear energy CIE 2008 luminous efficiency function 10 deg data
ciev2.spct

Linear energy CIE 2008 luminous efficiency function 2 deg data
as.reflector_spct

Coerce to a spectrum
cone_fundamentals10.spct

Ten-degree cone fundamentals
black_body.spct

Theoretical optical bodies
as.object_spct

Coerce to a spectrum
as.solute_mspct

Coerce to a collection-of-spectra
as.object_mspct

Coerce to a collection-of-spectra
as.solute_spct

Coerce to a solute spectrum
as_energy

Convert spectral photon irradiance into spectral energy irradiance
as_quantum

Convert spectral energy irradiance into spectral photon irradiance
class_spct

Query which is the class of a spectrum
check_and_rename_vars

check and rename variables
check_spct

Check validity of spectral objects
c

Combine collections of spectra
div_spectra

Divide two spectra, even if the wavelengths values differ
checkTimeUnit

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

Drop user columns
despike

Remove spikes from spectrum
clean_spct

Clean a spectrum
checkSpctVersion

Check that the "spct.version" attribute is set
ciexyzCMF2.spct

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

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

Copy attributes
clean

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

Energy-based photo-response
e_ratio

Energy:energy ratio
cps2irrad

Conversion from counts per second to physical quantities
diffraction_single_slit

Diffraction
get_peaks

Get peaks and valleys in a spectrum
get_attributes

Get the metadata attributes
convertTimeUnit

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

Theoretical spectrum of clear and apaque materials
convertTfrType

Convert the "Tfr.type" attribute
convertThickness

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

Extract or replace parts of a spectrum
energy_irradiance

Calculate (energy) irradiance from spectral irradiance
Extract_mspct

Extract or replace members of a collection of spectra
e2qmol_multipliers

Calculate energy to quantum (mol) multipliers
energy_ratio

Energy:energy ratio
e2q

Convert energy-based quantities into photon-based quantities.
defunct

Defunct functions and methods
convolve_each

Convolve function for collections of spectra
denormalize_spct

Remove a previously applied normalization
formatted_range

Compute range and format it
fscale

Rescale a spectrum using a summary function
getSoluteProperties

Get the "solute.properties" attribute
fluence

Fluence
fit_peaks

Refine position and value of extremes by fitting
e2quantum_multipliers

Calculate energy to quantum multipliers
e_fluence

Energy fluence
f_dispatcher_spct

Math function dispatcher for spectra
energy_as_default

Set spectral-data options
enable_check_spct

Enable or disable checks
find_spikes

Find spikes
integrate_xy

Gives irradiance from spectral irradiance.
getInstrSettings

Get the "instr.settings" attribute
find_wls

Find wavelength values in a spectrum
getKType

Get the "K.type" attribute
getFilterProperties

Get the "filter.properties" attribute
filter_cps.mspct

Counts per second from a measurement of a plastic film
getHowMeasured

Get the "how.measured" attribute
findMultipleWl

Find repeated w.length values
find_peaks

Find peaks in a spectrum
getTimeUnit

Get the "time.unit" attribute of an existing source_spct object
getWhatMeasured

Get the "what.measured" attribute
interpolate_spct

Map a spectrum to new wavelength values.
fscale_spct

fscale a spectrum
fshift

Shift the scale of a spectrum using a summary function
is_normalized

Query whether a generic spectrum has been normalized.
is_photon_based

Query if a spectrum contains photon- or energy-based data.
getSpctVersion

Get the "spct.version" attribute
getNormalized

Query the "normalized" and "normalization" attributes
getScaled

Get the "scaled" attribute
is.generic_mspct

Query class of spectrum objects
is.generic_spct

Query class of spectrum objects
is_absorbance_based

Query if a spectrum contains absorbance or transmittance data
isValidInstrSettings

Check the "instr.settings" attribute
illuminance

Irradiance
insert_hinges

Insert wavelength values into spectral data.
interpolate_spectrum

Calculate spectral values at a different set of wavelengths
interpolate_wl

Map spectra to new wavelength values.
fshift_spct

fshift a spectrum
generic_mspct

Collection-of-spectra constructor
l_insert_hinges

Insert wavelength values into spectral data.
is.old_spct

Query if an object has old class names
getWhenMeasured

Get the "when.measured" attribute
make_wl_consistent

Make wavelengths consistent
getWhereMeasured

Get the "where.measured" attribute
wl_max

Wavelength maximum
getMspctVersion

Get the "mspct.version" attribute
getIdFactor

Get the "idfactor" attribute
getInstrDesc

Get the "instr.desc" attribute
getMultipleWl

Get the "multiple.wl" attribute
is.summary_generic_spct

Query class of spectrum summary objects
msmsply

Multi-spct transform methods
labels

Find labels from "waveband" object
green_leaf.spct

Green birch leaf reflectance.
head_tail

Return the First and Last Parts of an Object
log

Logarithms and Exponentials
make_var_labels

Column or variable labels
mspct_classes

Names of multi-spectra classes
normalize

Normalize spectral data
normalize_range_arg

Normalize a range argument into a true numeric range
pull_sample

Random sample of spectra
irrad

Irradiance
irradiance

Photon or energy irradiance from spectral energy or photon irradiance.
is_effective

Is an R object "effective"
wl_midpoint

Midpoint
minus-.generic_spct

Arithmetic Operators
q2e

Convert photon-based quantities into energy-based quantities
wl_min

Wavelength minimum
photons_energy_ratio

Photon:energy ratio
plus-.generic_spct

Arithmetic Operators
mod-.generic_spct

Arithmetic Operators
response

Integrated response
se

Standard error of the mean
rgb_spct

RGB color values
photobiology-package

photobiology: Photobiological Calculations
photodiode.spct

Spectral response of a GaAsP photodiode
peaks

Peaks or local maxima
phenylalanine.spct

Molar spectral attenuation coefficient of phenylalanine
q_response

Photon-based photo-response
print.generic_spct

Print spectral objects
^.generic_spct

Arithmetic Operators
r4p_pkgs

Packages in R for Photobiology suite
wl_range

Wavelength range
is_mole_based

Query if a spectrum contains mole or mass based data
is_scaled

Query whether a generic spectrum has been scaled
is_tagged

Query if a spectrum is tagged
na.omit

Handle Missing Values in Objects
normalization

Normalization of an R object
insert_spct_hinges

Insert new wavelength values into a spectrum
round

Rounding of Numbers
is.waveband

Query if it is a waveband
integrate_spct

Integrate spectral data.
print.metadata

Print methods for metadata records
print.summary_generic_spct

Print spectral summary
isValidInstrDesc

Check the "instr.desc" attribute
photon_irradiance

Photon irradiance
photon_ratio

Photo:photon ratio
q_irrad

Photon irradiance
join_mspct

Join all spectra in a collection
q_ratio

Photon:photon ratio
split_irradiance

Energy or photon irradiance for split spectrum regions
s_median

Median of a collection of spectra
qe_ratio

Photon:energy ratio
rowwise

rowwise functions for collections of spectra
range_check_Tfr

Internal utility range-check functions
trimInstrDesc

Trim the "instr.desc" attribute
calendar_change

Solar astronomy using Meeus' algorithm
s_prod

Product from collection of spectra
rmDerivedMspct

Remove "generic_mspct" and derived class attributes.
rmDerivedSpct

Remove "generic_spct" and derived class attributes.
replace_bad_pixs

Replace bad pixels in a spectrum
rbindspct

Row-bind spectra
resp_spct

Calculate response from spectral response
merge2object_spct

Merge into object_spct
s_e_irrad2rgb

Spectral irradiance to rgb color conversion
s_mean

Mean from collection of spectra
merge_attributes

Merge and copy attributes
s_range

Range of a collection of spectra
select_spct_attributes

Merge user supplied attribute names with default ones
s_sd

Standard Deviation of a collection of spectra
setKType

Set the "K.type" attribute
setBSWFUsed

The "bswf.used" attribute
s_var

Variance of a collection of spectra
normalized_diff_ind

Calculate a normalized difference.
s_se

Standard Error of a collection of spectra
transmittance_spct

Calculate transmittance from spectral transmittance.
se.m

Standard error of the mean
oper_spectra

Binary operation on two spectra, even if the wavelengths values differ
se.p

Standard error of the mean
split2mspct

Convert a 'wide' or untidy data frame into a collection of spectra
s_sum

Sum from collection of spectra
setSoluteProperties

Set the "solute.properties" attribute
setTfrType

The "Tfr.type" attribute
smooth_spct

Smooth a spectrum
water.spct

Molar spectral attenuation coefficient of water
setInstrSettings

Set the "instr.settings" attribute
setInstrDesc

Set the "instr.desc" attribute
print.waveband

Print a "waveband" object
slash-.generic_spct

Arithmetic Operators
sinc

sinc
summary_spct_classes

Function that returns a vector containing the names of spectral summary classes.
valleys

Valleys or local minima
setMultipleWl

Set the "multiple.wl" attribute
spikes

Spikes
prod_spectra

Multiply two spectra, even if the wavelengths values differ
spct_attr2tb

Copy attributes into a tibble
untag

Remove tags
w_length2rgb

Wavelength to rgb color conversion
setWhenMeasured

Set the "when.measured" attribute
q_fraction

Photon:photon fraction
source_spct

Spectral-object constructors
s_mean_se

Mean and standard error from collection of spectra
split_photon_irradiance

Photon irradiance for split spectrum regions
setRfrType

The "Rfr.type" attribute
setWhereMeasured

Set the "where.measured" attribute
spct_classes

Function returning a vector containing the names of spectra classes.
waveband_ratio

Photon or energy ratio
subt_spectra

Subtract two spectra
setHowMeasured

Set the "how.measured" attribute
wb2tagged_spct

Create tagged spectrum from wavebands
setIdFactor

Set the "idfactor" attribute
setWhatMeasured

Set the "what.measured" attribute
setTimeUnit

Set the "time.unit" attribute of an existing source_spct object
spct_metadata

Access metadata
q_fluence

Photon fluence
thin_wl

Thin the density of wavelength values
summary.generic_spct

Summary of one or more spectra
spct_wide2long

Convert spectrum from wide to long form
two_sensors.mspct

Spectral response of two light sensors.
subset2mspct

Convert 'long' or tidy spectral data into a collection of spectra
times-.generic_spct

Arithmetic Operators
subset_attributes

Subset the metadata attributes
sign

Sign
reflectance

Reflectance
upgrade_spct

Upgrade one spectral object
trimInstrSettings

Trim the "instr.settings" attribute
sum_spectra

Add two spectra
using_Tfr

Use photobiology options
upgrade_spectra

Upgrade one or more spectral objects
trim_spct

Trim (or expand) head and/or tail of a spectrum
trim_tails

Trim (or expand) head and/or tail
verbose_as_default

Set error reporting options
transmittance

Transmittance
setScaled

Set the "scaled" attribute
sun.spct

Solar spectral irradiance (simulated)
w_length_range2rgb

Wavelength range to rgb color conversion
two_transmittances

Compute two transmittances for ratio, fraction or normalised difference
wb_trim_as_default

Set computation options
split_bands

List-of-wavebands constructor
wb2spct

Create spectrum from wavebands
reflectance_spct

Calculate reflectance from spectral reflectance
split_energy_irradiance

Energy irradiance for split spectrum regions
waveband

Waveband constructor method
wb2rect_spct

Create tagged spectrum from wavebands
two_reflectances

Compute two reflectances for ratio, fraction or normalised difference
uncollect2spct

Extract all members from a collection
s_mean_se_band

Mean plus and minus standard error from collection of spectra
white_led.source_spct

White led bulb spectrum
sun_daily.spct

Daily solar spectral irradiance (simulated)
two_filters.spct

Transmittance spectrum of plastic films
two_irrads

Compute two irrads for ratio, fraction or normalised difference
wl_stepsize

Stepsize
setFilterProperties

Set the "filter.properties" attribute
tag

Tag a spectrum
setResponseType

Set the "response.type" attribute
setNormalized

Set the "normalized" and "normalization" attributes
shared_member_class

Classes common to all collection members.
setGenericSpct

Convert an R object into a spectrum object.
sun_evening.spct

Time series of solar spectral irradiance (measured)
Subset

Subsetting spectra
v_replace_hinges

Overwrite spectral data values at existing wavelength values.
trim_waveband

Trim (or expand) head and/or tail
trim_wl

Trim head and/or tail of a spectrum
wls_at_target

Find wavelengths values corresponding to a target spectral value
wl2wavenumber

Wavelength conversions
v_insert_hinges

Insert spectral data values at new wavelength values.
MathFun

Miscellaneous Mathematical Functions
Ler_leaf.spct

Green Arabidopsis leaf reflectance and transmittance.
A2T

Convert absorbance into transmittance
A.illuminant.spct

CIE A illuminant data
D2.UV653

Data for typical calibration lamps
Afr2T

Convert transmittance into absorptance.
D65.illuminant.spct

CIE D65 illuminant data