Git Product home page Git Product logo

photobiology's Introduction

photobiology

CRAN version cran checks R build status

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] "2023-08-08 04:21:26 UTC"
day_length(date, tz = "UTC", geocode = geocode)
#> [1] 15.47508

Installation

Installation of the most recent stable version from CRAN:

install.packages("photobiology")

Once package ‘photobiology’ is installed, installation of the remaining or missing packages in the suite from CRAN:

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-2023 Pedro J. Aphalo ([email protected]). Released under the GPL, version 2 or greater. This software carries no warranty of any kind.

photobiology's People

Contributors

aphalo avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

romainfrancois

photobiology's Issues

`TfrType` assumptions and conversions

T2A() seems to not work correctly when Tfr == 0 and Rfr != 0. The problem could be caused by a wrongly set TfrType attribute in the data I was using, or could be an error in the computations. In the first case a validity test would be missing and in the second case, a plain bug.

The missing Afr2A() would have been useful for testing and diagnosing the problem, and adding it should be the first step.

Use 'poorman' and plain R instead of 'dplyr' and 'tidyr'.

Once again package 'photobiology' was affected by code-breakiing changes in 'dplyr' and 'tidyr'. In this case indirectly as the change was made in 'tidyeval' and possibly not caught by tests of reverse dependencies.

I think the time has come for removing these dependencies from 'photobiology' and minimizing other dependencies on the 'tidyverse', as most of the unplanned and urgent maintenance work has been caused in recent years by their inestability, while they do not provide much of an advantage compared to base R.

Unit tests for `pull_sample()` and `subset()` and `[ ]`

Adding these tests makes it neccessary to add example data for multiple spectra in long form and collections of spectra for all classes derived from "generic.spct" and from "generic.mspct". Current code was tested manually during development of these new functions.

Interpolate wls to make members of a collection consistent

There is a need to interpolate wavelengths of spectra within a collection to allow some parallel or rowwise operations. We need a function to achieve this efficiently now that we are using thinning of spectra to reduce their stored size. See also #11 as this two issues need to be resolved so that the new function can work together. I should have thought of this before starting to use wl-thinned spectra in the data-only packages!

Bug in extract with negative indexes

Extracting from a collection of spectra using negative indexing sets the dimension to the length of the index vector, rather than to the number of remaining members.

Unnesting of spectra within mspct objects

Collections of spectra containing spct objects with multiple spectra in long form trigger errors in summary functions like q_irrad(), q_ratio(), etc. The error message from plyr::ldply() is obscure, and unhelpful. At the very least an informative message is needed. Best solution would be to write a function to unnest these spectra, by replacing the spct object by multiple spct objects within the collection. This could be an exported function. By default, applied with a warnig or message. See also #12 as they both affect similar use cases and the solution should solve also mixed cases.

Spectral irradiance ratios

e_ratio() and q_ratio() compute the ratio based on irradiances, i.e., based on the integral of irradiance for two different wavebands. This is in most cases what we are interested in. Occasionally, we may want to compute ratios based on mean spectral irradiance of the two wavebands. Only when the wavelength range covered by both wavebands is the same, the two approaches yield the same value.

Adding a parameter to switch between the two approaches could be sometimes useful, and simple to implement.

Support for FR fraction and similar indices

As we have a NDxI() function and q_ratio(), e_ratio() and ratio() functions we should add support for computing fractions based on pairs of wavelengths: we can just add an option to q_ratio(), e_ratio() and ratio(). Maybe named qty.out with values "ratio", "spct.ratio", and "fraction" and "spct.fraction", thus addressing also #13.

wave_number(), wave_frequency() and photon_energy()

The first two conversion functions are in package 'ggspectra' but should be moved to 'photobiology'. Wavelength is used frequently in chemistry and physics, "wavelength" expressed in eV (the energy of a photon) and this needs to be also implemented in 'ggspectra'.

A more elegant way of handling molar cross sections vs absorption spectra is needed

Using filter_spct objects to store spectral molar cross sections is clumsy unless we add a way to store this information in an attribute. This is likely to be enough. Creating a class derived from filter_spct could also work as it would inherit most of the functionality. In either case this seems a rather major undertaking as it may break old code. NEEDS TO BE DONE BEFORE FIRST COMPLETE DRAFT OF THE BOOK.

sunrise_time does not update time value for requested time zone

It seems sunrise_time is not correct for non-UTC times with recent versions of lubridate or R, as shown in the User Guide.

library(lubridate)
library(photobiology)

my.geocode <- data.frame(lat = 60.16, lon = 24.93, address = "Helsinki")
my.datetime <- as_datetime("2022-07-10 12:00:00", tz="EET")

sunrise_time(my.datetime, geocode = my.geocode, tz = "UTC")
[1] "2022-07-10 01:13:46 UTC"

sunrise_time(my.datetime, geocode = my.geocode, tz = "EET")
[1] "2022-07-10 01:13:46 EEST"

> sessionInfo()
R version 4.2.0 (2022-04-22)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.04.4 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3
LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/liblapack.so.3

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8    LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] photobiology_0.10.2 tibble_3.1.7        lubridate_1.8.0    

loaded via a namespace (and not attached):
 [1] compiler_4.2.0    pillar_1.7.0      prettyunits_1.1.1 remotes_2.4.2     tools_4.2.0       testthat_3.1.4    pkgbuild_1.3.1   
 [8] pkgload_1.2.4     memoise_2.0.1     lifecycle_1.0.1   pkgconfig_2.0.3   rlang_1.0.2       DBI_1.1.3         cli_3.3.0        
[15] fastmap_1.1.0     withr_2.5.0       dplyr_1.0.9       generics_0.1.2    desc_1.4.1        fs_1.5.2          vctrs_0.4.1      
[22] devtools_2.4.3    rprojroot_2.0.3   tidyselect_1.1.2  glue_1.6.2        R6_2.5.1          processx_3.6.1    fansi_1.0.3      
[29] sessioninfo_1.2.2 callr_3.7.0       purrr_0.3.4       magrittr_2.0.3    ps_1.7.1          ellipsis_0.3.2    usethis_2.1.6    
[36] assertthat_0.2.1  utf8_1.2.2        cachem_1.0.6      crayon_1.5.1      brio_1.1.3   

However, regressing to earlier versions of lubridate and R but using the same photobiology version results in the correct time.

library(lubridate)
library(photobiology)

my.geocode <- data.frame(lat = 60.16, lon = 24.93, address = "Helsinki")
my.datetime <- as_datetime("2022-07-10 12:00:00", tz="EET")

sunrise_time(my.datetime, geocode = my.geocode, tz = "UTC")
[1] "2022-07-10 01:13:46 UTC"

sunrise_time(my.datetime, geocode = my.geocode, tz = "EET")
[1] "2022-07-10 04:13:46 EEST"

sessionInfo()
R version 3.6.3 (2020-02-29)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Debian GNU/Linux 10 (buster)

Matrix products: default
BLAS/LAPACK: /usr/lib/x86_64-linux-gnu/libopenblasp-r0.3.5.so

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8       
 [4] LC_COLLATE=en_US.UTF-8     LC_MONETARY=en_US.UTF-8    LC_MESSAGES=C             
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                  LC_ADDRESS=C              
[10] LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] photobiology_0.10.2 tibble_3.0.1        lubridate_1.7.8    

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.4.6      compiler_3.6.3    pillar_1.4.3      prettyunits_1.1.1 remotes_2.1.1    
 [6] tools_3.6.3       testthat_2.3.2    digest_0.6.25     pkgbuild_1.0.6    pkgload_1.0.2    
[11] memoise_1.1.0     lifecycle_0.2.0   pkgconfig_2.0.3   rlang_0.4.5       cli_2.0.2        
[16] rstudioapi_0.11   withr_2.2.0       dplyr_0.8.5       generics_0.0.2    desc_1.2.0       
[21] fs_1.4.1          vctrs_0.2.4       devtools_2.3.0    rprojroot_1.3-2   tidyselect_1.0.0 
[26] glue_1.4.0        R6_2.4.1          processx_3.4.2    fansi_0.4.1       sessioninfo_1.1.1
[31] purrr_0.3.4       callr_3.4.3       magrittr_1.5      backports_1.1.6   ps_1.3.2         
[36] ellipsis_0.3.0    usethis_1.6.0     assertthat_0.2.1  crayon_1.3.4  

Implement GOFF-GRATCH FORMULATIONS for water vapour

Tetens and Magnus formulations are simpler but Goff-Gratch may be preferred under some conditions.

Implemented in version 0.9.25 for saturation water VP, inverse not yet implemented. Need to find the inverse equation formulation or derive it.

Added forward and inverse implementations of Wexler. See http://www.decatur.de/javascript/dew/resources/its90formulas.pdf. ITS90 of forward equation needs the replacement of constants. Currently forward follows ITS68 as the original formulation, while the only inverse available follows ITS90.

See https://www.eol.ucar.edu/system/files/VaporPressure.pdf for the equation of Murphy and Koop.

dplyr 1.0.8

We're about to release dplyr 1.0.8 and it seems that the released version of photobiology has issues:

# photobiology

<details>

* Version: 0.10.8
* GitHub: https://github.com/aphalo/photobiology
* Source code: https://github.com/cran/photobiology
* Date/Publication: 2021-12-08 11:50:02 UTC
* Number of recursive dependencies: 60

Run `cloud_details(, "photobiology")` for more info

</details>

## Newly broken

*   checking examples ... ERROR
    ```
    Running examples in ‘photobiology-Ex.R’ failed
    The error most likely occurred in:
    
    > ### Name: A.illuminant.spct
    > ### Title: CIE A illuminant data
    > ### Aliases: A.illuminant.spct
    > ### Keywords: datasets
    > 
    > ### ** Examples
    > 
    > A.illuminant.spct
    Object: source_spct [97 x 2]
    Wavelength range 300 to 780 nm, step 5 nm 
    Label: CIE A standard illuminant, normalized to one at 560 nm 
    Time unit 1s
    Spectral data normalized to 1 at 560 nm 
    
    Error: 'trunc_mat' is not an exported object from 'namespace:dplyr'
    Execution halted
    ```

*   checking dependencies in R code ... WARNING
    ```
    Missing or unexported object: ‘dplyr::trunc_mat’
    ```

*   checking re-building of vignette outputs ... WARNING
    ```
    Error(s) in re-building vignettes:
    --- re-building ‘userguide-1-radiation.Rmd’ using rmarkdown
    News at https://www.r4photobiology.info/
    
    Attaching package: 'lubridate'
    
    The following objects are masked from 'package:base':
    
        date, intersect, setdiff, union
    
    ...
    
        date, intersect, setdiff, union
    
    --- finished re-building ‘userguide-2-astronomy.Rmd’
    
    SUMMARY: processing the following file failed:
      ‘userguide-1-radiation.Rmd’
    
    Error: Vignette re-building failed.
    Execution halted
    ```

it seems however fixed in the dev version.

Add mathematical equations to documentation

[Moved from Bitbucket: original date 2018-06-27]
It would be good to add equations describing the various summaries to help pages and/or vignettes. This requires to make sure that portability is not affected.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.