Moon phase calculation

December 21, 2013
By

(This article was first published on Dan Kelley Blog/R, and kindly contributed to R-bloggers)

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)

moon phase diagram

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 on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers


Sponsors

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)