Reference Document Home | Publications Home
Table of Contents
References Cited

Northeast Fisheries Science Center Reference Document 11-14

AstroCalc4R: Software to Calculate Solar Zenith Angle; Time at Sunrise, Local Noon, and Sunset; and Photosynthetically Available Radiation Based on Date, Time, and Location

by Larry Jacobson, Alan Seaver, and Jiashen Tang
NOAA National Marine Fisheries Service, Northeast Fisheries Science Center, 166 Water Street, Woods Hole, MA 02543

Web version posted October 14, 2011

Citation: Jacobson L, Seaver A, Tang J. 2011. AstroCalc4R: software to calculate solar zenith angle; time at sunrise, local noon and sunset; and photosynthetically available radiation based on date, time and location. US Dept Commer, Northeast Fish Sci Cent Ref Doc. 11-14; 10 p. Available from: National Marine Fisheries Service, 166 Water Street, Woods Hole, MA 02543-1026, or online at

Information Quality Act Compliance: In accordance with section 515 of Public Law 106-554, the Northeast Fisheries Science Center completed both technical and policy reviews for this report. These predissemination reviews are on file at the NEFSC Editorial Office.

AcrobatDownload complete PDF/print version


AstroCalc4R for Windows and Linux can be used to study diel and seasonal patterns in biological organisms and ecosystems due to illumination. The algorithms require more time to understand and program than would be available to most biological researchers. In contrast to the algorithms, the results are understandable and links to marine and terrestrial ecosystems are obvious to biologists. Diel variation in solar energy affects the energy budgets of ecosystems (Link et al. 2006) and behavior of a wide range of organisms including zooplankton, fish, marine birds, reptiles and mammals; and aquatic and terrestrial organisms (e.g. Hjellvik et al. 2001). The solar zenith angle; time at sunrise, local noon and sunset; and photosynthetically available radiation (PAR) are the most important variables for biology that are calculated by AstroCalc4R. PAR is the amount of photosynthetically available radiation (usually wavelengths of 400-700 nm) at the surface of the earth or ocean based on the solar zenith angle under average atmospheric conditions (Frouin et al. 1989; Figure 1)[1],[2].

The algorithms in AstroCalc4R for all variables except PAR are based on Meeus (2009) and Seidelmann (2006). They give the same results and are almost the same as algorithms used by the National Oceanographic and Atmospheric Administration (NOAA) Earth System Research Laboratory, Global Monitoring Division. All variables, with the exception of PAR, can be calculated using spreadsheets distributed by NOAA (NOAA_Solar_Calculations_day.xls and NOAA_Solar_Calculations_year.xls). These spreadsheets are useful, available free at but are difficult to use with large data sets and from other programming languages.

AstroCalc4R consists of programs and functions written in the C and R programming languages[3]. Most of the calculations are done in C and the C code contains complete documentation of algorithms. The R code consists of a single function that validates and organizes input data, calls the C code as a dynamic link library (Windows) or shared object (Linux), and then returns results to the user in the form of an R dataframe.

The C program AstroCalc4R.c is a modified version of AstroCalc.c which was written by A. Seaver and used at the Northeast Fisheries Science Center (NEFSC) to analyze bottom trawl survey data for marine fish and invertebrates (Azarovitz 1981). The modifications allow AstroCalc4R.c to accept more than one input record at a time, make it easier to call from R, and handles cases near the poles when days or nights are 24 hours long. With the exception of these modifications, documentation for AstroCalc4R.C can also be used for AstroCalc.c.


Astronomical definitions are based on definitions in Meeus (2009) and Seidelmann (2006). The geocentric solar zenith angle is the angle between a line drawn "straight up" from the center of the Earth through the observer and a line drawn from the center of the solar disk through the observer. The solar zenith angle and all of the solar variables calculated by AstroCalc4R depend on latitude, longitude, date and time of day. For example, the solar zenith angle at a single time of day varies in NEFSC bottom trawl survey tows due to changes in position, date and time (Figure 2).

Local solar noon is the time of day when the sun reaches its maximum elevation and minimum solar zenith angle. Sunrise and sunset occur when the solar zenith angle is 90.83o (90o 50'). This angle occurs when the leading edge of the sun first appears above, or the trailing edge disappears below the horizon (0.83o accounts for the radius of the sun when seen from the earth and for refraction by the atmosphere). Day length is the time in hours between sunrise and sunset.[4]

The solar declination and azimuth angles describe the exact position of the sun in the sky, relative to an observer and based on an equatorial coordinate system. The equatorial coordinate system is formed by projecting the earth's surface onto a very large theoretical sphere that rotates around an axis that is shared by the earth (the axis of the equatorial sphere passes through the earth's poles). The equators of the earth and celestial sphere lie in the same plane. Solar declination is the angular displacement of the sun above the equatorial plane. Solar azimuth is the position of the sun measured in a clockwise direction from north. The equation of time accounts for the relative position of the observer within the time zone.

PAR is illumination in lux (lx, approximately W m-2) and is calculated based on the solar zenith angle. AstroCalc4R calculates PAR as illumination at wavelengths between 400-700 nm in the marine environment under average marine conditions (Frouin et al. 1989). However, calculations for other wavelengths, terrestrial environments and under other conditions can be carried out by substituting parameters from Frouin et al. (1989). Following Frouin et al. (1989), PAR is assumed to be zero at solar zenith angles ≥ 90o although some sunlight may be visible in the sky when the solar zenith angle is < 108o. Astronomical twilight occurs by definition and the sun contributes negligible illumination to the night time sky when the solar zenith angle is 108o).

The results of calculations for angles in AstroCalc4R are in degrees although radians are used internally for most calculations. Time data and results are in decimal hours (e.g. 11:30 pm = 23.5 h) local time but internal calculations are in Greenwich Mean Time (GMT). The user must specify the local time zone in terms of ± hours relative to GMT to link local time and GMT. For example, the difference between Eastern Standard Time and GMT is -5 hours.

Significance of solar zenith angles and PAR in ecological research

Diurnal movements are linked to daily changes in illumination by the sun. In marine environments, diel movements by plankton, invertebrates and vertebrates are typically off the bottom into the water column at night and towards the bottom during the day (Hjellvik et al. 2001) although reverse diel patterns also occur (Ohman et al. 1983). Survey and fishery bottom trawl catch rates for many species are highest during daytime if the organisms are near the bottom during the day where bottom trawls operate.

Solar zenith angles are useful in interpreting survey and fishery catch rates for species that have diel movement patterns. They may be particularly important if survey data are used to estimate biomass or abundance directly because diurnal movement patterns reduce survey catch rates relative to maximum catch rates during the daytime. Hjellvik et al. (2001) appears to be the first published study using the "altitude of the sun" (presumably the solar declination and possibly measured in the field) in modeling diel patterns. The software in this report builds on Hjellvik et al (2001) and helps scientists relate biological patterns and illumination in terms of variables with clear astronomical definitions, and when neither the position of the sun nor actual illumination was measured in the field.

To the extent that illumination governs diel behavior, the solar zenith angle provides a mechanistic, biologically based predictor for understanding diurnal behavior patterns. Solar zenith angles are more useful than time of day as predictor variables in modeling because illumination at the same time of day will vary substantially with latitude and longitude (Figure 2). Solar zenith angles provide the same information as illumination during the daytime. However, solar zenith angles change continuously through the night while illumination is nearly zero and constant. Therefore, solar zenith angles can be used to ecological phenomena at night that cannot be predicted based on illumination. Zenith angles are functions of and contain information about position, time and date so that the latter variables may be omitted in modeling.

Generalized Additive Models (Wood 2006) and regression tree approaches (Elith et al. 2008) may be particularly useful for modeling diel effects on survey catch rates or other biological phenomena because zenith angles and other environmental effects can be handled in a flexible nonparametric fashion. Based on L. Jacobson's experience, underlying relationships between illumination, other environmental variables and survey catch data are difficult to represent parametrically (e.g. using polynomials). Moreover, the use of solar zenith data provides opportunities to simplify complex models that might otherwise have to include date, time of day, latitude and longitude.

Consider a GAM model with a dummy variable p for positive tows (i.e. p = 1 if the catch > 0, otherwise p = 0) and Z for the solar zenith angle. In the R programming language and using the mgcv library for R (Wood 2006), the model:

gam(p ~ s(Z), family=binomial)

will predict the probability of a positive tow at a particular date, time of day and location, based only on the solar zenith angle. If the observed proportion of positive tows changes through the night, then the fitted spline should reflect the pattern. If the observed proportion of positive tows is constant through the night, then the spline will approximate a constant for nighttime hours. Moreover, the spline and the solar zenith angle will capture the transition between day and nighttime patterns whether they occur before or after astronomical twilight when illumination from the sun is zero. Of course, seasonal, regional, depth, and temperature effects on catch rates and interactions can be added if desired or necessary (NEFSC 2011).


AstroCalc4R was developed and tested using the R statistical programming language (version 2.12.1). Earlier versions of R may not work properly. R is available at no cost for Windows, Linux and other operating systems ( The MinGW compiler (available free at was used to compile AstroCalc4R.c under Windows. The g++ compiler (distributed with Linux, was used to compile AstroCalc4R under Linux. The MinGW compiler for Windows is included in the RTOOLS package for R ( and RTOOLS is also available for Linux.

AstroCalc4R.c is the principle C source code, contains complete internal documentation for the main algorithms and can be downloaded for free at . It can be compiled to make the dynamic link library AstroCalc4R.dll in Windows or the shared object in Linux although the dynamic link library and shared object are also available on the website. The C functions in myfuncs1.c are used in AstroCalc4R.c and must be in the same directory when it is compiled. The C function parcalc in myfuncs1.cpp computes PAR based on the solar zenith angle and is of particular interest. Appendix 1 shows how to use the C function AstroCalc4R from R. Programmers can modify our C code for use in other applications.


Jay O'Riley (NOAA, Northeast Fisheries Science Center, Narragansett, RI) provided initial code based on a slightly different algorithm for the solar zenith angle and initial code for PAR, in addition to helpful suggestions. Scientists at the U.S. National Institute of Science and Technology (NIST) and the U.S. Naval Observatory provided information, references and technical advice. Paul Rago (NOAA, Northeast Fisheries Science Center, Woods Hole, Massachusetts) initiated solar zenith angle and PAR calculations for Northeast Fisheries Science Center bottom trawl survey data in collaboration with O'Riley and others in the course of The Northeast U.S. Continental Shelf Energy Modeling and Analysis exercise (EMAX)" described in Link et al. (2008). Lisa Hendrickson (NOAA, Northeast Fisheries Science Center, Woods Hole, MA) supplied useful advice regarding NEFSC bottom trawl surveys.

References Cited

Azarovitz, T.R. 1981. A brief historical review of the Woods Hole Laboratory trawl survey time series. In: Doubleday, W.G. and Rivard, D. (eds.). Bottom trawl surveys. Can. Spec. Publ. Fish. Aquat. Sci. 58: 62-67.

Elith, J., Leathwick, J.R., and Hastie, T. 2008. A working guide to boosted regression trees. J. Animal Ecol. 77: 802-813.

Frouin, R., Lingner, D., Gautier, C., Baker, K. and Smith, R. 1989. A simple analytical formula to compute total and photosynthetically available solar irradiance at the ocean surface under clear skies. J. Geophys. Res. 94: 9731-9742.

Hjellvik, V., Godo, O., Thjostheim, D. 2001. Modeling diurnal variation of marine populations. Biometrics 57: 189-196.

Link, J., Overholtz, W., O'Reilly, J., Green, J., Dow, D., Palka, D., Legault, C., Vitaliano, J., Guida, V., and Fogarty, M., Brodziak, J., Methratta, L., Stockhausen, W., Col, L., and Griswold, C. 2008. The northeast U.S. continental shelf energy modeling and analysis exercise (EMAX): Ecological network model development and basic ecosystem metrics. J. Mar. Sys. 74: 453-474.

Meeus, J. 2009. Astronomical Algorithms, 2nd Edition. Willmann-Bell, Inc., Richmond, VA.

NEFSC (Northeast Fisheries Science Center). 2011 (in press). 51st Northeast Regional Stock Assessment Workshop (51st SAW) Assessment Report. NEFSC Reference Document. 11-00. National Marine Fisheries Service, 166 Water Street, Woods Hole, MA 02543-1026.

Ohman, M.D., Frost, B.W., and Cohen, E.B. 1983. Reverse diel vertical migration: an escape from invertebrate predators. Science 222: 1404-1407.

Seidelmann, P.K. 2006. Explanatory Supplement to the Astronomical Almanac. University Science Books, Sausalito, CA.

Wood, S.N. 2006. Generalized additive models. An introduction with R. Chapman and Hall/CRC, NY.


[1] The PAR algorithm includes a correction for an error in Frouin et al. (1989) that was identified by Jay O'Riley (NOAA, Northeast Fisheries Science Center, Narragansett, RI). The correction is based on correspondence between O'Riley and Frouin. See the the parcalc function inside myfuncs1.c (Appendix 2) for additional information.

[2] PAR can be calculated for other wavelengths and under terrestrial conditions by substituting values in Frouin et al (1989) for constant parameters in the parcalc function inside myfuncs1.c (Appendix 2).

[3] All of the software and computer programs described in this report can be downloaded gratis at

[4] Civil, nautical, and astronomical twilight occurs at solar zenith angles of 96o, 102o, and 108o. Details of objects become visible and civil twilight. At nautical twilight, only outlines are visible. At astronomical twilight, the sun contributes negligible illumination to the nighttime sky.
NMFS Search
Link Disclaimer
Privacy Policy
(File Modified Jul. 01 2016)

This page has had 5 visits today, 18 visits this week, 85 visits this month, 241 visits this year