Benchmarking function sun_angles()

As far as I know there are in CRAN four R packages implementing the computations for the position of the sun and times of sunrise and sunset: ‘photobiology’, ‘fishmethods’, ‘solartime’ and ‘suncalc’.

The functions sun_angles() and day_night() from package ‘photobiology’ use Meeus equations as used by NOAA Solar Calculator https://www.esrl.noaa.gov/gmd/grad/solcalc/ which could be more precise than those in NOAA’s Excel worksheet which implement a simplified version of the Meeus equations especially for far into the past or far into the future calculations. The approximations based on Meuus equations are very good for years between 1800 and 2100 and results should still be sufficiently accurate for the range from -1000 to 3000 as long as the computation of Julian dates is correct. The Excel implementation is only valid for dates between 1901 and 2099 because of how Julian dates are computed in Excell.

Function astrocalc4r() from package ‘fishmethods’ also implements Meeus equations (the authors work at NOAA). Function computeSunPosition() from package ‘solartime’ uses unspecified equations and function getSunlightPosition() is an R interface to the ‘suncalc.js’ library, part of the ‘SunCalc.net’ project <http://suncalc.net>.

Function computeSunPosition() from package ‘solartime’ uses unspecified equations and function getSunlightPosition() is an R interface to the ‘suncalc.js’ library, part of the ‘SunCalc.net’ project <http://suncalc.net>.

Continue reading

ggpmisc 0.3.1

After the previous major update to ‘ggpmisc’ (0.3.0), a follow up (0.3.1) with multiple new features and smoothed rough edges for some of the features added in version 3.0.0. Package documentation is available at https://docs.r4photobiology.info/ggpmisc/ as a web site.

The enhancements in this and the previous update to ‘ggpmisc’ are made possible by changes to ‘ggplot2’ (>= 3.0.0) made while adding support for sf (simple features).

The functions in ‘ggpmisc’ (>= 0.3.1) are related to different kinds of annotations and insets in ggplots. Annotations of plots with fitted-model equations, fit diagnosis, ANOVA and summary tables, highlighting and labelling of peaks and valleys in curves, and local density-based highlighting or labelling in scatter plots. Additionally specializations of the ggplot() constructor allow on-the-fly conversion of time-series. Two new geoms join geom_table() added in version 0.3.0, geom_plot() and geom_grob(). These three geoms make it possible to add tables, ggplots and arbitrary graphical objects (grobs) as insets to plots respecting the the Grammar of Graphics paradigm.

Inset plot showing means per group.
Inset grobs

A set of new geometries produce marginal annotations: geom_x_margin_point(), geom_y_margin_point(), geom_x_margin_arrow(), geom_y_margin_arrow(), geom_x_margin_grob() and geom_y_margin_grob().

Marginal “points” showing means per group.

Another novel feature is based on the addition of two new aesthetics npcx and npcy, the corresponding scales scale_npcx_continuous() and scale_npcy_continuous(), and several new geometries that make use of then: geom_text_npc(), geom_label_npc(), geom_table_npc(), geom_plot_npc() and geom_grob_npc(). These allow to position insets and annotations relative to the dimensions of the plotting area instead of using native data units. Using "npc" units is more natural for labels or insets that are not directly related to data but that look better if positioned consistently across multiple panels or multiple separately produced plots. One improvement to the stats from earlier versions of ‘ggpmisc’ is the use of these new geoms to achieve more consistent location for insets and labels.

Quadrant counts with panels.
Fitted equations in panels with free y limits.
Inset tables at different positions in different panels.

As in the announcement of the previous version, I have included some example plots taken from the documentation of the package. In all cases annotations are generated automatically, but formatting is flexible.

NOTE: The new version of ‘ggpmisc’ will be soon submitted to CRAN .

gginnards 0.0.2

This is a minor update, with the following enhancements compared to ‘gginnards’ 0.0.1.

  • Implement str() method for class "ggplot" as a wrapper with tweaked default arguments.
  • Add functions mapped_vars() and data_vars() to list variables in the default data member of objects of class "gg".
  • Add function data_attributes() to list the attributes of the default data member of objects of class "gg".

Documentation web site at http://docs.r4photobiology.info/gginnards/ includes all help pages, with output from all examples, and vignettes in HTML format.
NOTE: The package is on its way to CRAN CRAN.

Please raise issues concerning bugs or enhancements to this package through Bitbucket https://bitbucket.org/aphalo/gginnards/issues

Yoctopuce modules: Introduction

Yoctopuce USB interface modules provide a very elegant solution to many different sensing and control problems, including measuring radiation. I have been interested in using them to acquire data directly from within R so as to be able to use the ‘r4photobiology’ suite of packages for real-time or near real time analysis and plotting of the acquired data.

The elegantly coded libraries supplied by Yoctopuce are available with interfaces in multiple computer programming and scripting languages. I have been trying different approaches to calling functions from these libraries in R scripts, but given the large number of functions needed to support the great variety of modules, writing an ad hoc interface for R was out of question. I first tried calling the command line version of the library functions from within R, but at least in Windows 10, the delay was too much and not consistent. Next I tried using the web server in the YoctoHub to send commands as http requests. This worked but it is a rather awkward approach, and not portable to accessing the modules directly through USB.

Two days ago, after reading about the ‘reticulate’ package I decided to test an approach similar to that I have used in package ‘rOmniDriver’ to access, with help from the ‘rJava’ package, Ocean Optics spectrometers through OmniDriver, a library written in Java. In the present case using ‘reticulate’ to access the Python version of the YoctoPuce library. It works extremely well, and the RStudio IDE provides in the editor even auto-completion and bubble help for functions and other objects defined in the Python library!

I have decided to describe here a few use cases for data acquisition or light source control using YoctoPuce models and R scripts. Most examples will be simple but useful, as they are real use cases rather than toy examples.

The YoctoPuce modules, hubs and the corresponding free libraries and the documentation are available at https://www.yoctopuce.com/. The ‘reticulate’ package is available through CRAN, and nicely formatted documentation can be found at https://rstudio.github.io/reticulate/. The first CRAN release of ‘reticulate’ appeared less than a year ago.

.