This package, is a data only package, part of a suite, which has package ‘photobiology’ at its core. Please visit (https://www.r4photobiology.info/) for more details. For information on plotting spectra, please consult the documentation for package ‘ggspectra’, and for information on the calculation of summaries and maths operations between spectra, please, consult the documentation for package ‘photobiology’.
library(photobiology)
library(photobiologyWavebands)
library(photobiologySun)
library(lubridate)
library(ggplot2)
library(ggspectra)
theme_set(theme_bw())
One collection of spectra, sun_reference.mspct
, contains published reference solar spectra used in model simulations and for calculations. Another collection, gap.mspct
contains a rapid sequence of spectra measured in a forest gap. Another two time series of simulated hourly spectra sun_hourly_june.spct
and sun_hourly_august.spct
, are each in the format of a single spectral object. Other measured spectra is inlcuded, as well as energy- and photon-irradiance time series from broadband sensors.
The source_spct
member objects in sun_reference.mspct
and gap.mspct
can be accessed through their names or through a numeric index. As the numeric indexes are likely to change with updates to the package, their use is discouraged. Names as character strings should be used instead. They can also be retrieved with method names()
.
## [1] "ASTM.E490.AM0" "ASTM.G173.direct" "ASTM.G173.global"
## [4] "Gueymard.AM0" "WMO.Wehrli.AM0"
We can use a character string as index to extract an individual source_spct
object.
## Object: source_spct [2,002 x 2]
## Wavelength range 280 to 4000 nm, step 0.5 to 5 nm
## Time unit 1s
##
## # A tibble: 2,002 x 2
## w.length s.e.irrad
## <dbl> <dbl>
## 1 280 0.082
## 2 280. 0.099
## 3 281 0.15
## 4 282. 0.212
## 5 282 0.267
## 6 282. 0.303
## 7 283 0.325
## 8 284. 0.323
## 9 284 0.299
## 10 284. 0.250
## # ... with 1,992 more rows
## Object: source_spct [2,002 x 2]
## Wavelength range 280 to 4000 nm, step 0.5 to 5 nm
## Time unit 1s
##
## # A tibble: 2,002 x 2
## w.length s.e.irrad
## <dbl> <dbl>
## 1 280 0.082
## 2 280. 0.099
## 3 281 0.15
## 4 282. 0.212
## 5 282 0.267
## 6 282. 0.303
## 7 283 0.325
## 8 284. 0.323
## 9 284 0.299
## 10 284. 0.250
## # ... with 1,992 more rows
Be aware that according to R’s rules, using single square brackets will return a source_mspct
object possibly of length one. This statement is not equivalent to the one in the chunk immediately above.
## Object: source_mspct [1 x 1]
## --- Member: Gueymard.AM0 ---
## Object: source_spct [2,002 x 2]
## Wavelength range 280 to 4000 nm, step 0.5 to 5 nm
## Time unit 1s
##
## # A tibble: 2,002 x 2
## w.length s.e.irrad
## <dbl> <dbl>
## 1 280 0.082
## 2 280. 0.099
## 3 281 0.15
## 4 282. 0.212
## 5 282 0.267
## 6 282. 0.303
## 7 283 0.325
## 8 284. 0.323
## 9 284 0.299
## 10 284. 0.250
## # ... with 1,992 more rows
##
## --- END ---
We can subset sensors.mspct
object by indexing with vectors of character strings. More generally one can search for matching names within the collection of spectra.
## Object: source_mspct [3 x 1]
## --- Member: ASTM.E490.AM0 ---
## Object: source_spct [1,697 x 2]
## Wavelength range 119.5 to 1e+06 nm, step 1 to 6e+05 nm
## Time unit 1s
##
## # A tibble: 1,697 x 2
## w.length s.e.irrad
## <dbl> <dbl>
## 1 120. 61.9
## 2 120. 561.
## 3 122. 4901
## 4 122. 1184
## 5 124. 47.7
## 6 124. 34.3
## 7 126. 28.8
## 8 126. 35.2
## 9 128. 21.3
## 10 128. 17.3
## # ... with 1,687 more rows
## --- Member: Gueymard.AM0 ---
## Object: source_spct [2,002 x 2]
## Wavelength range 280 to 4000 nm, step 0.5 to 5 nm
## Time unit 1s
##
## # A tibble: 2,002 x 2
## w.length s.e.irrad
## <dbl> <dbl>
## 1 280 0.082
## 2 280. 0.099
## 3 281 0.15
## 4 282. 0.212
## 5 282 0.267
## 6 282. 0.303
## 7 283 0.325
## 8 284. 0.323
## 9 284 0.299
## 10 284. 0.250
## # ... with 1,992 more rows
## --- Member: WMO.Wehrli.AM0 ---
## Object: source_spct [920 x 2]
## Wavelength range 199.5 to 10075 nm, step 0.1 to 2290 nm
## Time unit 1s
##
## # A tibble: 920 x 2
## w.length s.e.irrad
## <dbl> <dbl>
## 1 200. 0.005
## 2 200. 0.007
## 3 202. 0.007
## 4 202. 0.008
## 5 204. 0.009
## 6 204. 0.009
## 7 206. 0.01
## 8 206. 0.01
## 9 208. 0.011
## 10 208. 0.015
## # ... with 910 more rows
##
## --- END ---
Using autoplot()
methods for spectra defined in package ‘ggspectra’ annotated plotting is automatic. The defaults can be easily changed, please see the documentation in package ‘ggspectra’.
Using the ggplot()
method for spectra from package ‘ggspectra’ plus geometries and statistics from package ‘ggplot2’ we gain additional control on the design.
In the case of spectral objects containing a time series of spectra, the index variable UTC
containing time and date in universal time coordinates (“UTC”) can be used to select and/or highlight individual spectra.
As source_spct
is a class derived from list
, and source_spct
is derived from tibble::tible
which is a compatible reimplementation of data.frame
the data can be used very easily with any R function.
## w.length s.e.irrad
## 1 250.22 0
## 2 250.69 0
## 3 251.17 0
## 4 251.64 0
## 5 252.12 0
## 6 252.59 0
Of course attach
and with
also work as expected.
## Warning in q_response.default(spct.1, Red()): 'q_response' is not defined
## for objects of class source_spct
## [1] NA
## [1] 899.86
## Warning in q_response.default(spct.1, Red()): 'q_response' is not defined
## for objects of class source_spct
## [1] NA