sosoc / croc

Ocean colour with R
3 stars 1 forks source link

remove C++ #10

Closed mdsumner closed 6 years ago

mdsumner commented 6 years ago

We don't need it, this should be enough to replace bin2lonlat:


b2ll <- function(bins, nrows) {
  row <- seq_len(nrows) - 1
  latbin = ((row + 0.5)*180.0/nrows) - 90.0;
  numbin <- as.integer((2*nrows*cos(latbin*pi/180.0) + 0.5))
  basebin <- c(1L, head(cumsum(numbin) + 1L, -1L))
  totbins <- tail(basebin, 1) + tail(numbin, 1) - 1
  index <- findInterval(bins, basebin)
  lat <- latbin[index]
  lon <- 360.0*(bins - basebin[index] + 0.5)/numbin[index] - 180.0;
  cbind(lon, lat)
}
mdsumner commented 6 years ago

Looks good:

set.seed(1)
rando <- sample(roc::initbin(4320)$totbins, 10000)
sum(do.call(cbind, roc::bin2lonlat(rando, 4320)) - b2ll(rando, 4320))

rando <- sample(roc::initbin(8260)$totbins, 10000)
sum(do.call(cbind, roc::bin2lonlat(rando, 8260)) - b2ll(rando, 8260))

rando <- sample(roc::initbin(126)$totbins, 10000)
sum(do.call(cbind, roc::bin2lonlat(rando, 126)) - b2ll(rando, 126))
mdsumner commented 6 years ago

done in https://github.com/sosoc/roc/commit/66d5564416475f2ccb7d22f6e41abaad20c5828a