Moon phase calculation
[This article was first published on Dan Kelley Blog/R, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
The illuminated fraction of the moon can be calculated with moonAngle()
in the oce package, as illustrated graphically and in R code below.
1 2 3 4 5 6 7 | library(oce) par(mar=c(3, 3, 1, 1), mgp=c(2, 0.7, 0)) # tighten margins t <- as.POSIXct("2013-12-1", tz="UTC") + seq(0, 28*24*3600, 3600) f <- moonAngle(t=t, longitude=-63.6, latitude=44.65)$illuminatedFraction plot(t, f, type="l", xlab="Day of 2013", ylab="Moon fraction") grid() |
For interest, add full-moon time as indicated in an almanac.
1 2 3 | full <- as.POSIXct("2013-12-17 05:29:00", tz="AST") abline(v=full) mtext("full", at=full, side=3) |
Exercises (a) Try this for other locations. (b) Detect full moon by using uniroot() on the rate of change of illumination.
To leave a comment for the author, please follow the link and comment on their blog: Dan Kelley Blog/R.
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.