Benchmarking function sun_angles() [updated]

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

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 ‘’ project <>.

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

UPDATED on 2019-04-24

I have noticed significant differences in the values returned by equivalent functions from different packages. Up to now the tests on the functions of my own package ‘photobiology’ have revealed only very small mismatches to the NOAA Solar Calculator. These small errors, noticeable for dates far from the present, were due to the use of base R’s julian() function, which is not designed to be precise enough for astronomical calculations. The code now in the repository at Bitbucket has been revised to use Meuus’ algorithm for the calculation of Julian days removing this source of  small discrepancies.

In contrast, while testing ‘photobiology’ against other packages, I seem to have found a bug in function astrocalc4r() from R package ‘fishmethods’.

A minimal example follows:

By only changing the hour passed as argument different times for sunrise, sunset and daylength are returned even though the day is the same. The differences are larger at high than at low latitudes. The maximum difference for the example above is 1/4 h for daylength. Comparison against the NOAA Solar Calculator shows even larger differences.

(The bug has been reported to the maintainer of package ‘fishmethods’.)

Continue reading

Yoctopuce modules: Spectrometer

In the introduction to this series of post, I described the Yoctopuce library and told that R package ‘reticulate’ can be used to access the Python version of the yoctopuce library. Here I describe a simple and cheap “micro” spectrometer with a digital interface and its use together with R packages from the 'r4photobiology' suite.

I will use a miniature and low cost spectrometer, type AS7265X from ams. It does not used a grating as monochromator, but instead each of the 18 channels has a different interference filter deposited directly on the silicon chip. The FWHM is 20 nm, and the wavelength range from 410 nm to 940 nm. The spectrometer consists in three separate sensor units working together. The interface is digital, and temperature compensation and analogue to digital conversion takes place in the sensor modules. In spite of the number of channels communication between the spectrometer and a micro-processor requires only two wires. The spectrometer supports two different communication protocols, the specialized I2C and a generic serial communication (UART).

Continue reading

Encryption and https:

The site has been updated to use encryption. For the web site, old addresses using http: are silently redirected to https:. If you have earlier received warnings from browsers because of the lack of encryption, this upgrade to the server settings should remove them.

The repository at the subdomain also supports encrypted connections. In addition, because of tightening of security in other ways, if you have been earlier using the address to access the repository, you will need to use instead from now on. In other words if you are setting this repository address in an .Rprofile file you should edit it to use the new address.

The documentation should be accessed through as settings for this subdomain have been changing in the same way.

All these changes should ensure enhanced security for the site and downloads.


R 3.5.0 has been released

R 3.5.0 was released on 23 April. It includes several performance improvements. All packages in the ‘r4photobiology’ suite pass checks on the new version. In CRAN binaries for R 3.5.0 of all packages have been built. In the case of development versions and packages not in CRAN, the repository at will soon be updated to include binaries suitable for R 3.5.0. Meanwhile packages will be installed from sources if the require tools are available (e.g. RTools 3.5.0 or 3.4.0 installed in Windows computers).

The update from R 3.4.x to R 3.5.x requires that all packages are reinstalled. For the time being avoid using package ‘installr’ to do the update, at least on Windows, as copying installed packages from an earlier installation is not useful. Please see the page Upgrading R for instructions.