Skip to content

Commit

Permalink
Correctly sample points in nndm (#161)
Browse files Browse the repository at this point in the history
* Correctly sample points in nndm

Fixes #160

* Refresh autoplots

* Still test on Windows, just not 3.6

* Use st_bbox

st_convex_hull() requires a relatively new GEOS, not on old Ubuntu
  • Loading branch information
mikemahoney218 authored Sep 4, 2024
1 parent 9877514 commit c6d6e16
Show file tree
Hide file tree
Showing 15 changed files with 64 additions and 42 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ jobs:
- {os: macos-latest, r: 'release'}

- {os: windows-latest, r: 'release'}
# Use 3.6 to trigger usage of RTools35
- {os: windows-latest, r: '3.6'}
# use 4.1 to check with rtools40's older compiler
- {os: windows-latest, r: '4.1'}

Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# spatialsample (development version)

* Fixed bug where passing a polygon to `spatial_nndm_cv()` forced leave-one-out
CV, rather than the intended sampling of prediction points from the polygon.

# spatialsample 0.5.1

* `spatial_block_cv()` now adds an `expand_bbox` attribute to the resulting rset
Expand Down
10 changes: 5 additions & 5 deletions R/spatial_nndm_cv.R
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,15 @@ spatial_nndm_cv <- function(data, prediction_sites, ...,
)

if (use_provided_points) {
sample_points <- prediction_sites
prediction_sites <- prediction_sites
} else if (sample_provided_poly) {
sample_points <- sf::st_sample(
prediction_sites <- sf::st_sample(
x = sf::st_geometry(prediction_sites),
size = prediction_sample_size,
...
)
} else {
sample_points <- sf::st_sample(
prediction_sites <- sf::st_sample(
x = sf::st_as_sfc(sf::st_bbox(prediction_sites)),
size = prediction_sample_size,
...
Expand All @@ -145,9 +145,9 @@ spatial_nndm_cv <- function(data, prediction_sites, ...,
# and will _sometimes_ warn instead (systematic sampling)
# but will _often_ strip CRS from the returned data;
# enforce here that our output prediction sites share a CRS with input data
if (is.na(sf::st_crs(sample_points))) {
if (is.na(sf::st_crs(prediction_sites))) {
prediction_sites <- sf::st_set_crs(
sample_points,
prediction_sites,
sf::st_crs(prediction_sites)
)
}
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/_snaps/autoplot/block-split-plots.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions tests/testthat/_snaps/autoplot/buffered-llo-split-plot.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 5 additions & 5 deletions tests/testthat/_snaps/autoplot/buffered-rsample-plot.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 5 additions & 5 deletions tests/testthat/_snaps/autoplot/buffered-rset-plot.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/autoplot/buffered-vfold-plot.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 5 additions & 5 deletions tests/testthat/_snaps/autoplot/buffered-vfold-split.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions tests/testthat/_snaps/autoplot/cluster-split-plots.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/autoplot/repeated-block-cv.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions tests/testthat/_snaps/autoplot/repeated-llo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit c6d6e16

Please sign in to comment.