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

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] "2024-08-23 04:50:47 UTC"
day_length(date, tz = "UTC", geocode = geocode)
#> [1] 14.39096

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

987

Version

0.11.4

License

GPL (>= 2)

Issues

Pull Requests

Stars

Forks

Maintainer

Last Published

November 30th, 2024

Functions in photobiology (0.11.4)

T2Afr

Convert transmittance into absorptance.
MathFun

Miscellaneous Mathematical Functions
Rfr_ratio

reflectance:reflectance ratio
Tfr_ratio

transmittance:transmittance ratio
Rfr_from_n

Reflectance at a planar boundary
Tfr_fraction

transmittance:transmittance fraction
Rfr_normdiff

reflectance:reflectance normalised difference
Tfr_normdiff

transmittance:transmittance normalised difference
Rfr_fraction

reflectance:reflectance fraction
Trig

Trigonometric Functions
as.calibration_mspct

Coerce to a collection-of-spectra
adaptive_smoothing

Custom smoothing
T2A

Convert transmittance into absorbance.
absorptance

Absorptance
add_attr2tb

Copy attributes from members of a generic_mspct
absorbance

Absorbance
absorbance_spct

Calculate absorbance from spectral absorbance.
absorptance_spct

Calculate absorptance from spectral absorptance.
as.calibration_spct

Coerce to a spectrum
as.filter_spct

Coerce or convert into a filter spectrum
as.generic_mspct

Coerce to a collection-of-spectra
as.chroma_mspct

Coerce to a collection-of-spectra
as.filter_mspct

Coerce to a collection-of-spectra
as.object_mspct

Coerce to a collection-of-spectra
any2T

Convert filter quantities.
as.chroma_spct

Coerce to a spectrum
as.matrix-mspct

Coerce a collection of spectra into a matrix
as.cps_spct

Coerce to a spectrum
as.cps_mspct

Coerce to a collection-of-spectra
as.reflector_spct

Coerce to a spectrum
as.solute_mspct

Coerce to a collection-of-spectra
as.object_spct

Coerce to a spectrum
average_spct

Average spectral data.
as.raw_mspct

Coerce to a collection-of-spectra
auto_hinges

Guess whether insertion of hinges is needed or not
as.solute_spct

Coerce to a solute spectrum
as.source_mspct

Coerce to a collection-of-spectra
as.solar_date

Convert a solar_time object into solar_date object
as.response_spct

Coerce to a spectrum
checkTimeUnit

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

Honeybee xyz chromaticity colour matching function data
check_and_rename_vars

check and rename variables
black_body.spct

Theoretical optical bodies
as_energy

Convert spectral photon irradiance into spectral energy irradiance
as_quantum

Convert spectral energy irradiance into spectral photon irradiance
checkMspctVersion

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

Check that the "spct.version" attribute is set
as.source_spct

Coerce to a spectrum
calc_multipliers

Spectral weights
as.response_mspct

Coerce to a collection-of-spectra
c

Combine collections of spectra
ciexyzCMF2.spct

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

Query which is the class of a spectrum
ciexyzCC10.spct

CIE xyz chromaticity coordinates (CC) 10 deg data
ciexyzCC2.spct

CIE xyz chromaticity coordinates 2 deg data
ciev2.spct

Linear energy CIE 2008 luminous efficiency function 2 deg data
ciexyzCMF10.spct

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

Convert datetime to time-of-day
as.raw_spct

Coerce to a spectrum
as.generic_spct

Coerce to a spectrum
as.reflector_mspct

Coerce to a collection-of-spectra
as_quantum_mol

Convert spectral energy irradiance into spectral photon irradiance
color_of

Color of an object
compare_spct

Coarse-grained comparison of two spectra
check_spectrum

Sanity check a spectrum
clear.spct

Theoretical spectrum of clear and apaque materials
convertThickness

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

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

Check validity of spectral objects
convertTimeUnit

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

Conversion from counts per second to physical quantities
clean_spct

Clean a spectrum
clear_photobio.cache

Clear the spectral weights cache
day_night

Times for sun positions
despike

Remove spikes from spectrum
convolve_each

Convolve function for collections of spectra
collect2mspct

Form a new collection
defunct

Defunct functions and methods
clip_wl

Clip head and/or tail of a spectrum
copy_attributes

Copy attributes
e_response

Energy-based photo-response
e2q

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

Drop user columns
enable_check_spct

Enable or disable checks
e_fluence

Energy fluence
ccd.spct

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

Scaled and/or interpolated light-source spectral output
e_fraction

Energy:energy fraction
check_w.length

Sanity check of wavelengths (internal function).
ciev10.spct

Linear energy CIE 2008 luminous efficiency function 10 deg data
div-.generic_spct

Arithmetic Operators
div_spectra

Divide two spectra, even if the wavelengths values differ
Extract

Extract or replace parts of a spectrum
e_ratio

Energy:energy ratio
spread

Expanse
e_irrad

Energy irradiance
filter_cps.mspct

Counts per second from a measurement of a plastic film
findMultipleWl

Find repeated w.length values
formatted_range

Compute range and format it
format.tod_time

Encode in a Common Format
convertTfrType

Convert the "Tfr.type" attribute
cone_fundamentals10.spct

Ten-degree cone fundamentals
diffraction_single_slit

Diffraction
dim.generic_mspct

Dimensions of an Object
energy_as_default

Set spectral-data options
fscale

Rescale a spectrum using a summary function
eq_ratio

Energy:photon ratio
energy_irradiance

Calculate (energy) irradiance from spectral irradiance
fscale_spct

fscale a spectrum
find_wls

Find wavelength values in a spectrum
energy_ratio

Energy:energy ratio
find_peaks

Find peaks in a spectrum
generic_mspct

Collection-of-spectra constructor
getKType

Get the "K.type" attribute
find_spikes

Find spikes
getMspctVersion

Get the "mspct.version" attribute
get_attributes

Get the metadata attributes
getIdFactor

Get the "idfactor" attribute
e2quantum_multipliers

Calculate energy to quantum multipliers
e2qmol_multipliers

Calculate energy to quantum (mol) multipliers
getWhereMeasured

Get the "where.measured" attribute
getHowMeasured

Get the "how.measured" attribute
getSpctVersion

Get the "spct.version" attribute
f_dispatcher_spct

Math function dispatcher for spectra
getFilterProperties

Get the "filter.properties" attribute
getTimeUnit

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

Extract or replace members of a collection of spectra
fshift

Shift the scale of a spectrum using a summary function
fit_peaks

Refine position and value of extremes by fitting
getWhenMeasured

Get the "when.measured" attribute
format.solar_time

Encode in a Common Format
fluence

Fluence
insert_hinges

Insert wavelength values into spectral data.
getWhatMeasured

Get the "what.measured" attribute
interpolate_spectrum

Calculate spectral values at a different set of wavelengths
is.solar_time

Query class
is.old_spct

Query if an object has old class names
interpolate_spct

Map a spectrum to new wavelength values.
isValidInstrDesc

Check the "instr.desc" attribute
green_leaf.spct

Green birch leaf reflectance.
is.waveband

Query if it is a waveband
getMultipleWl

Get the "multiple.wl" attribute
is.summary_generic_spct

Query class of spectrum summary objects
insert_spct_hinges

Insert new wavelength values into a spectrum
fshift_spct

fshift a spectrum
get_peaks

Get peaks and valleys in a spectrum
illuminance

Irradiance
head_tail

Return the First and Last Parts of an Object
getNormalized

Query the "normalized" and "normalization" attributes
irradiance

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

Extraterrestrial irradiance
is_scaled

Query whether a generic spectrum has been scaled
getInstrDesc

Get the "instr.desc" attribute
is_photon_based

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

Check the "instr.settings" attribute
is_tagged

Query if a spectrum is tagged
getInstrSettings

Get the "instr.settings" attribute
getSoluteProperties

Get the "solute.properties" attribute
getScaled

Get the "scaled" attribute
integrate_spct

Integrate spectral data.
join_mspct

Join all spectra in a collection
labels

Find labels from "waveband" object
make_var_labels

Column or variable labels
make_wl_consistent

Make wavelengths consistent
merge_attributes

Merge and copy attributes
mod-.generic_spct

Arithmetic Operators
msmsply

Multi-spct transform methods
log

Logarithms and Exponentials
normalize

Normalize spectral data
normalized_diff_ind

Calculate a normalized difference.
mspct_classes

Names of multi-spectra classes
na.omit

Handle Missing Values in Objects
oper_spectra

Binary operation on two spectra, even if the wavelengths values differ
photobiology-package

photobiology: Photobiological Calculations
interpolate_wl

Map spectra to new wavelength values.
is_normalized

Query whether a generic spectrum has been normalized.
wl_max

Wavelength maximum
irrad

Irradiance
photodiode.spct

Spectral response of a GaAsP photodiode
is_mole_based

Query if a spectrum contains mole or mass based data
wl_midpoint

Midpoint
merge2object_spct

Merge into object_spct
normalize_range_arg

Normalize a range argument into a true numeric range
photon_ratio

Photo:photon ratio
print.tod_time

Print time-of-day objects
print.summary_generic_spct

Print spectral summary
photon_irradiance

Photon irradiance
net_irradiance

Net radiation flux
normalization

Normalization of an R object
print.metadata

Print methods for metadata records
peaks

Peaks or local maxima
phenylalanine.spct

Molar spectral attenuation coefficient of phenylalanine
pull_sample

Random sample of spectra
q2e

Convert photon-based quantities into energy-based quantities
print.solar_time

Print solar time and solar date objects
q_response

Photon-based photo-response
rmDerivedMspct

Remove "generic_mspct" and derived class attributes.
rmDerivedSpct

Remove "generic_spct" and derived class attributes.
qe_ratio

Photon:energy ratio
integrate_xy

Gives irradiance from spectral irradiance.
is.generic_spct

Query class of spectrum objects
is.generic_mspct

Query class of spectrum objects
q_irrad

Photon irradiance
q_ratio

Photon:photon ratio
calendar_change

Solar astronomy using Meeus' algorithm
is_absorbance_based

Query if a spectrum contains absorbance or transmittance data
is_effective

Is an R object "effective"
wl_min

Wavelength minimum
l_insert_hinges

Insert wavelength values into spectral data.
round

Rounding of Numbers
q_fraction

Photon:photon fraction
q_fluence

Photon fluence
print.waveband

Print a "waveband" object
prod_spectra

Multiply two spectra, even if the wavelengths values differ
reflectance_spct

Calculate reflectance from spectral reflectance
rowwise

rowwise functions for collections of spectra
s_mean_se

Mean and standard error from collection of spectra
relative_AM

Relative Air Mass (AM)
s_median

Median of a collection of spectra
s_prod

Product from collection of spectra
s_se

Standard Error of a collection of spectra
s_sum

Sum from collection of spectra
setBSWFUsed

The "bswf.used" attribute
select_spct_attributes

Merge user supplied attribute names with default ones
minus-.generic_spct

Arithmetic Operators
photons_energy_ratio

Photon:energy ratio
setFilterProperties

Set the "filter.properties" attribute
s_mean_se_band

Mean plus and minus standard error from collection of spectra
setNormalized

Set the "normalized" and "normalization" attributes
setResponseType

Set the "response.type" attribute
slash-.generic_spct

Arithmetic Operators
setHowMeasured

Set the "how.measured" attribute
sinc

sinc
spct_classes

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

Set the "idfactor" attribute
plus-.generic_spct

Arithmetic Operators
wl_range

Wavelength range
r4p_pkgs

Packages in R for Photobiology suite
setGenericSpct

Convert an R object into a spectrum object.
split_photon_irradiance

Photon irradiance for split spectrum regions
spct_metadata

Access metadata
setKType

Set the "K.type" attribute
setMultipleWl

Set the "multiple.wl" attribute
setTimeUnit

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

Set the "what.measured" attribute
wl_stepsize

Stepsize
setInstrDesc

Set the "instr.desc" attribute
setWhenMeasured

Set the "when.measured" attribute
setInstrSettings

Set the "instr.settings" attribute
replace_bad_pixs

Replace bad pixels in a spectrum
^.generic_spct

Arithmetic Operators
print.generic_spct

Print spectral objects
resp_spct

Calculate response from spectral response
split2mspct

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

Convert spectrum from wide to long form
setWhereMeasured

Set the "where.measured" attribute
spikes

Spikes
summary.generic_spct

Summary of one or more spectra
sum_spectra

Add two spectra
trimInstrDesc

Trim the "instr.desc" attribute
sun_evening.spct

Time series of solar spectral irradiance (measured)
trimInstrSettings

Trim the "instr.settings" attribute
sun.spct

Solar spectral irradiance (simulated)
tag

Tag a spectrum
split_bands

List-of-wavebands constructor
summary_spct_classes

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

Valleys or local minima
times-.generic_spct

Arithmetic Operators
rbindspct

Row-bind spectra
thin_wl

Thin the density of wavelength values
twilight2angle

twilight argument check and conversion
two_filters.spct

Transmittance spectrum of plastic films
verbose_as_default

Set error reporting options
reflectance

Reflectance
Subset

Subsetting spectra
subset2mspct

Convert 'long' or tidy spectral data into a collection of spectra
trim_waveband

Trim (or expand) head and/or tail
response

Integrated response
rgb_spct

RGB color values
w_length2rgb

Wavelength to rgb color conversion
s_sd

Standard Deviation of a collection of spectra
se.p

Standard error of the mean
trim_spct

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

Wavelength range to rgb color conversion
s_range

Range of a collection of spectra
se.m

Standard error of the mean
v_replace_hinges

Overwrite spectral data values at existing wavelength values.
using_Tfr

Use photobiology options
v_insert_hinges

Insert spectral data values at new wavelength values.
trim_tails

Trim (or expand) head and/or tail
s_mean

Mean from collection of spectra
trim_wl

Trim head and/or tail of a spectrum
untag

Remove tags
s_e_irrad2rgb

Spectral irradiance to rgb color conversion
uncollect2spct

Extract all members from a collection
validate_geocode

Validate a geocode
setSoluteProperties

Set the "solute.properties" attribute
wb2rect_spct

Create tagged spectrum from wavebands
wb2spct

Create spectrum from wavebands
se

Standard error of the mean
s_var

Variance of a collection of spectra
wb2tagged_spct

Create tagged spectrum from wavebands
setTfrType

The "Tfr.type" attribute
wb_trim_as_default

Set computation options
setScaled

Set the "scaled" attribute
setRfrType

The "Rfr.type" attribute
smooth_spct

Smooth a spectrum
solar_time

Local solar time
wls_at_target

Find wavelengths values corresponding to a target spectral value
split_energy_irradiance

Energy irradiance for split spectrum regions
split_irradiance

Energy or photon irradiance for split spectrum regions
shared_member_class

Classes common to all collection members.
spct_attr2tb

Copy attributes into a tibble
source_spct

Spectral-object constructors
sign

Sign
sun_daily.spct

Daily solar spectral irradiance (simulated)
sun_angles

Solar angles
two_irrads

Compute two irrads for ratio, fraction or normalised difference
two_reflectances

Compute two reflectances for ratio, fraction or normalised difference
subt_spectra

Subtract two spectra
subset_attributes

Subset the metadata attributes
transmittance_spct

Calculate transmittance from spectral transmittance.
transmittance

Transmittance
two_transmittances

Compute two transmittances for ratio, fraction or normalised difference
upgrade_spct

Upgrade one spectral object
upgrade_spectra

Upgrade one or more spectral objects
tz_time_diff

Time difference between two time zones
water.spct

Molar spectral attenuation coefficient of water
water_vp_sat

Water vapour pressure
waveband

Waveband constructor method
waveband_ratio

Photon or energy ratio
white_led.source_spct

White led bulb spectrum
wl2wavenumber

Wavelength conversions
Ler_leaf.spct

Green Arabidopsis leaf reflectance and transmittance.
D2_spectrum

Calculate deuterium lamp output spectrum from fitted constants
ET_ref

Evapotranspiration
D65.illuminant.spct

CIE D65 illuminant data
D50.illuminant.spct

CIE D50 illuminant data
FEL_spectrum

Incandescent "FEL" lamp emission spectrum
A.illuminant.spct

CIE A illuminant data
D2.UV653

Data for typical calibration lamps
Afr2T

Convert transmittance into absorptance.
A2T

Convert absorbance into transmittance