Skip to content

Commit

Permalink
subset,argo-method can test new 'sf' method
Browse files Browse the repository at this point in the history
To get the test, first execute

   options("oce:test_sf"=1)
  • Loading branch information
dankelley committed Dec 8, 2019
1 parent afb97a4 commit ebfab31
Show file tree
Hide file tree
Showing 55 changed files with 136 additions and 115 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Encoding: UTF-8
URL: https://dankelley.github.io/oce
LazyData: false
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.0.0
RoxygenNote: 7.0.2
BuildVignettes: true
VignetteBuilder: knitr
NeedsCompilation: yes
Expand Down
38 changes: 30 additions & 8 deletions R/argo.R
Original file line number Diff line number Diff line change
Expand Up @@ -485,13 +485,12 @@ argoNames2oceNames <- function(names, ignore.case=TRUE)
#' plotTS(subset(argo, "adjusted"))
#'
#' # Example 4. Subset by a polygon determined with locator()
#'\dontrun{
#' par(mfrow=c(2, 1))
#' par(mfrow=c(1, 2))
#' plot(argo, which="map")
#' bdy <- locator(4) # Click the mouse on 4 boundary points
#' ## Can get a boundary with e.g. locator(4)
#' bdy <- list(x=c(-65, -40, -40, -65), y=c(65, 65, 45, 45))
#' argoSubset <- subset(argo, within=bdy)
#' plot(argoSubset, which="map")
#'}
#'
#' @author Dan Kelley
#'
Expand All @@ -505,11 +504,9 @@ setMethod(f="subset",
dots <- list(...)
dotsNames <- names(dots)
withinGiven <- length(dots) && ("within" %in% dotsNames)
debug <- getOption("oceDebug")
if (length(dots) && ("debug" %in% names(dots)))
debug <- dots$debug
debug <- if (length(dots) && ("debug" %in% names(dots))) dots$debug else getOption("oceDebug")
if (withinGiven) {
oceDebug(debug, "subsetting with 'within' method")
oceDebug(debug, "subsetting with 'within' method\n")
polygon <- dots$within
if (!is.data.frame(polygon) && !is.list(polygon))
stop("'within' must be a data frame or a polygon")
Expand All @@ -535,6 +532,31 @@ setMethod(f="subset",
} else {
stop("cannot use 'within' because the 'sp' package is not installed")
}
if (debug > 0) {
oceDebug(debug, "testing oce:convert_to_sp for subset(..., within=...)\n")
oceDebug(debug, " polygon ", vectorShow(lonp))
oceDebug(debug, " polygon ", vectorShow(latp))
oceDebug(debug, " keeping ", sum(keep)/length(keep)*100, "% of profiles, viz. ",
paste(which(keep), collapse=" "), "\n", sep="")
}
if (!is.null(options("oce:test_sf")$`oce:test_sf`)) {
message("NOTE: options(\"oce:test_sf\"=1), so testing whether the proposed new 'sf' method works")
if (requireNamespace("sf", quietly=TRUE)) {
## st_polygon requires a closed x,y path, hence the appending of the first point
polyNew <- sf::st_polygon(list(outer=cbind(c(lonp, lonp[1]), c(latp, latp[1]))))
## There may be a more elegant way of intersecting, but this works on example 4 of the documentation
keepNew <- as.logical(lapply(seq_along(lon),
function(i)
lengths(sf::st_intersects(sf::st_point(c(lon[i],lat[i])), polyNew))))
if (!all.equal(keepNew, keep)) {
warning("'keep' list disagreement, between old method and proposed new 'sf' method\n")
} else {
message(" the 'keep' vector from the 'sf' method matches that from the previous 'sp' method")
}
} else {
stop("cannot use 'within' argument with options(\"oce:test_sf\"=1) because the 'sf' package is not installed")
}
}
## Metadata
for (name in names(x@metadata)) {
oceDebug(debug, "subsetting metadata item named '", name, "'\n", sep="")
Expand Down
4 changes: 2 additions & 2 deletions R/geod.R
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@
#' angleUTM <- 180/pi*atan(coef(lm(northing~easting, data=UTM))[2])
#' mapCoordinateSystem(lonR, latR, 500, angleUTM, col=3)
#' legend("topright", lwd=1, col=2:3, bg="white", title="Axis Rotation Angle",
#' legend=c(sprintf("geod: \%.1f deg", angle),
#' sprintf("utm: \%.1f deg", angleUTM)))
#' legend=c(sprintf("geod: %.1f deg", angle),
#' sprintf("utm: %.1f deg", angleUTM)))
#'}
#' @family functions relating to geodesy
geodXy <- function(longitude, latitude, longitudeRef, latitudeRef, debug=getOption("oceDebug"))
Expand Down
2 changes: 1 addition & 1 deletion man/ODFNames2oceNames.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions man/cnvName2oceName.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/colormap.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions man/ctimeToSeconds.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/integerToAscii.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/integrateTrapezoid.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/julianCenturyAnomaly.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/mapPlot.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/oce.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/oceDebug.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions man/oceEdit.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/oceGetData.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/oceGetMetadata.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions man/oceSpectrum.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/plot-tidem-method.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions man/pwelch.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/read.argo.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions man/read.g1sst.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/read.landsat.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions man/secondsToCtime.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/sectionAddStation.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/sub-sub-adp-method.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/sub-sub-adv-method.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/sub-sub-amsr-method.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/sub-sub-argo-method.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit ebfab31

Please sign in to comment.