Publications by Dan Kelley Blog/R
map projections in rgdal and sf
Executive Summary. a transition of oce to sf will require the removal of healpix, nesper, pconic and rhealpix projections, all of which cause errors in sf. The loss of healpix, rhealpix and pconic projections is not of much concern, since these were interrupted projections that were not handled properly by oce::mapPlot() anyway (see http://dankel...
2445 sym R (15393 sym/98 pcs) 190 img
oce map projections in context of switch from rgdal to sf
Executive Summary. this updates a previous posting by removing healpix and rhealpix, which are not handled properly by sf. These projections were useless anyway, since oce::mapPlot() plotted in the off-world regions (see http://dankelley.github.io/r/2020/01/04/oce-proj.html). Introduction The goal is to test the existing oce projections, and also...
1642 sym R (64262 sym/18 pcs)
Why I use base graphics instead of ggplot2
With base graphics, a histogram of 100 million points d <- data.frame(x=rnorm(1e8)) system.time(hist(x)) takes just user system elapsed 0.044 0.004 0.052 which means that the result is ready as my pinkie finger is rising from the ‘Return’ key. In contrast, if I use ggplot as in library(ggplot2) system.time({p<-ggplot(d) + aes(...
1418 sym R (308 sym/4 pcs)
Day length calculation
The winter solstice has been on many minds lately. The days are about to start getting longer … but just how fast will they do that? This post provides R that calculates and graphs day length and its variation, using uniroot() to find sunrises and sunsets as indicated by solar altitude that is calculated with sunAngle() in the oce package. The...
1746 sym R (851 sym/10 pcs) 2 img 5 tbl
Solstice sunrise-sunset
Introduction The sunAngle() function in the oce package provides a handy way to determine sunrise/sunset azimuth angles, and this is used to find alignments for the winter solstice in Halifax, NS. Methods First, set up the problem; these may be the only lines that need editing for other places or times. 1 2 3t <- as.POSIXct("2013-12-21 17:11:00",...
1432 sym R (1124 sym/12 pcs) 2 img 6 tbl
Moon phase calculation
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 7library(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, ...
726 sym R (418 sym/4 pcs) 2 img 2 tbl
A new Oce coastline
Part 1: coastal applications The oce package has a world coastline file that is visibly crude on a scale suitable for continental-shelf work. At the cost of about 1 Mbyte of storage, a candidate for a replacement is a 1:10million scale version downloaded from naturalearthdata.com (full link below). As illustrated below with plots near two ocea...
4840 sym R (1817 sym/4 pcs) 4 img 2 tbl
Analemma graphs
Continuing on the theme of solar angles, the code given below produces an analemma diagram similar to that of Lynch (2012, figure 2). 1 2 3 4 5 6 7 8 9 10library(oce) loc <- list(lon=-0.0015, lat=51.4778) # Greenwich Observatory t <- seq.POSIXt(as.POSIXct("2014-01-01 12:00:00", tz="UTC"), as.POSIXct("2015-01-01 12:00:00"...
645 sym R (449 sym/2 pcs) 2 img 1 tbl
Sundial calculations
After experimenting with calculations for what I eventually came to realize were analemma-based sundials (with shadow cast by a vertical pole), I remembered that the common sundial has a wedge as the shadow-maker. A bit of research told me that the wedge is called a gnomon. It is a right triangle with one vertex (the centre vertex, shall we say)...
2256 sym R (3264 sym/2 pcs) 2 img 1 tbl
R interface to WebTide
A previous posting explained how to install WebTide on an OSX machine. This one shows how to hook up to an installed WebTide database, so that R code can get tidal predictions. The following code in the R language will produce a graph in which the top panel mimics the tidal-elevation graph produced by WebTide itself (see previous blog posting for...
1023 sym R (493 sym/4 pcs) 4 img 2 tbl