Skip to content

Commit 6e213d6

Browse files
authored
Merge pull request #123 from ropensci/0.9.9
0.9.9
2 parents c308bea + a86bfd7 commit 6e213d6

17 files changed

+674
-93
lines changed

‎DESCRIPTION‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: chopin
22
Title: Spatial Parallel Computing by Hierarchical Data Partitioning
3-
Version: 0.9.6
3+
Version: 0.9.9
44
Authors@R: c(
55
person("Insang", "Song", email = "[email protected]", role = c("aut", "cre"),
66
comment = c(ORCID = "0000-0001-8732-3256")),

‎NEWS.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
- CRAN ready: unexported function examples are moved to /tools on GitHub
55
- SoftwareX paper is published; DOI and inst/CITATION is added
66
- Supports H3 and DGGRID gridding functions from 0.9.5
7+
- Generic function using all-`sf` inputs in `x` and `y` is supported in `par_*()` functions
78

89
# 0.8
910
- Bumped version from 0.7.8 to 0.8.0: improving package coverage

‎R/check.R‎

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ setMethod(
637637
setMethod(
638638
".check_vector",
639639
signature(input = "sf", input_id = "ANY",
640-
extent = "NULL", out_class = "character"),
640+
extent = "ANY", out_class = "character"),
641641
function(input, input_id, extent, out_class, ...) {
642642
.check_pkgname(out = out_class)
643643
input <- .check_id(input, input_id)
@@ -694,6 +694,7 @@ setMethod(
694694
)
695695

696696

697+
697698
#' @keywords internal
698699
#' @name .check_vector
699700
#' @rdname .check_vector
@@ -825,7 +826,7 @@ setMethod(
825826
setMethod(
826827
".check_vector",
827828
signature(input = "SpatVector", input_id = "ANY",
828-
extent = "NULL", out_class = "character"),
829+
extent = "ANY", out_class = "character"),
829830
function(input, input_id, extent, out_class, ...) {
830831
.check_pkgname(out = out_class)
831832

@@ -952,7 +953,7 @@ setMethod(
952953
# character ingestion
953954
if (is.character(input)) {
954955
cli::cli_inform(
955-
sprintf("Input is a character. Attempt to read it with terra::rast...\n")
956+
"Input is a character. Attempt to read it with terra::rast...\n"
956957
)
957958
input <-
958959
try(terra::rast(input, win = extent, snap = "out"), silent = TRUE)
@@ -985,9 +986,20 @@ setMethod(
985986
)
986987
)
987988
suppressWarnings(
988-
input <- try(terra::sources(input), silent = TRUE)
989+
input_read <- try(terra::sources(input), silent = TRUE)
989990
)
990-
if (inherits(input, "try-error")) {
991+
if (is.character(input_read)) {
992+
if (input_read == "") {
993+
path_temp <- tempfile(fileext = ".tif")
994+
cli::cli_alert_info(
995+
"The data is in memory. Writing a temporary GeoTIFF file to track the data source path..."
996+
)
997+
terra::writeRaster(input, path_temp, overwrite = TRUE)
998+
input_read <- path_temp
999+
}
1000+
return(input_read)
1001+
}
1002+
if (inherits(input_read, "try-error")) {
9911003
cli::cli_abort(
9921004
paste0(
9931005
"Failed to track the data source file path.\n",
@@ -996,8 +1008,9 @@ setMethod(
9961008
)
9971009
}
9981010
}
1011+
input
9991012
}
1000-
return(input)
1013+
input
10011014
}
10021015

10031016

@@ -1022,22 +1035,26 @@ setMethod(
10221035
)[[1]]
10231036
),
10241037
error = function(e) {
1025-
"error"
1038+
if (exists(fun)) {
1039+
"user"
1040+
} else {
1041+
"error"
1042+
}
10261043
}
10271044
)
10281045
},
10291046
FUN.VALUE = character(1)
10301047
)
10311048

1032-
pkgname <- grep("^(terra|sf|chopin)$", pkgname, value = TRUE)
1049+
pkgname <- grep("^(terra|sf|chopin|user)$", pkgname, value = TRUE)
10331050
if (length(pkgname) == 0) {
10341051
cli::cli_abort("No parent package is found.")
10351052
}
10361053
if (length(pkgname) > 1) {
10371054
cli::cli_abort("There are multiple parent packages matched.")
10381055
}
1039-
if (!pkgname %in% c("sf", "terra", "chopin")) {
1040-
cli::cli_abort("Function should be one from sf, terra, or chopin.")
1056+
if (!pkgname %in% c("sf", "terra", "chopin", "user")) {
1057+
cli::cli_abort("Function should be user-defined or one from sf, terra, or chopin.")
10411058
}
10421059
return(pkgname)
10431060
}

‎R/scale_process.R‎

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -122,34 +122,37 @@ par_grid <-
122122
funname <- as.character(substitute(fun_dist))
123123
# is the function extract_at?
124124
is_extract_at <- any(endsWith(funname, "extract_at"))
125+
message(is_extract_at)
125126
funname <- funname[length(funname)]
126127
pkgname <- try(.check_package(funname), silent = TRUE)
127128

128129
# parallel worker will take terra class objects
129130
# if chopin function is used
130-
class_vec <-
131-
if (pkgname == "chopin") {
132-
if (is_extract_at) {
133-
"sf"
134-
} else {
135-
"terra"
136-
}
137-
} else {
138-
pkgname
139-
}
131+
class_vec <- "sf"
132+
# if (pkgname == "chopin") {
133+
# if (is_extract_at) {
134+
# "sf"
135+
# } else {
136+
# "terra"
137+
# }
138+
# } else {
139+
# pkgname
140+
# }
140141

141142
# clean additional arguments
142143
args_input <- list(...)
143-
if (funname == "chopin" && is.null(args_input$.standalone)) {
144+
if (pkgname == "chopin" && is.null(args_input$.standalone)) {
144145
args_input$.standalone <- FALSE
145146
}
146147

147148
# Track spatraster file path
148149
args_input$x <- .check_par_spatraster(args_input$x)
149150
args_input$y <- .check_par_spatraster(args_input$y)
151+
150152
# get hints from the inputs on data model
151153
peek_x <- try(.check_character(args_input$x), silent = TRUE)
152154
peek_y <- try(.check_character(args_input$y), silent = TRUE)
155+
153156
if (inherits(peek_x, "try-error")) {
154157
crs_x <- terra::crs(args_input$x)
155158
} else {
@@ -392,15 +395,15 @@ par_hierarchy <-
392395
# parallel worker will take terra class objects
393396
# if chopin function is used
394397
class_vec <-
395-
if (pkgname == "chopin") {
398+
# if (pkgname == "chopin") {
396399
if (is_extract_at) {
397400
"sf"
398401
} else {
399402
"terra"
400403
}
401-
} else {
402-
pkgname
403-
}
404+
# } else {
405+
# pkgname
406+
# }
404407

405408
# Track spatraster file path
406409
args_input$x <- .check_par_spatraster(args_input$x)
@@ -702,15 +705,15 @@ par_multirasters <-
702705
# parallel worker will take terra class objects
703706
# if chopin function is used
704707
class_vec <-
705-
if (pkgname == "chopin") {
708+
# if (pkgname == "chopin") {
706709
if (is_extract_at) {
707710
"sf"
708711
} else {
709712
"terra"
710713
}
711-
} else {
712-
pkgname
713-
}
714+
# } else {
715+
# pkgname
716+
# }
714717

715718
# Unlike other par_* functions, raster paths are not
716719
# tracked by the function since the raster file paths

‎R/scale_process_mirai.R‎

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -123,20 +123,20 @@ par_grid_mirai <-
123123

124124
# parallel worker will take terra class objects
125125
# if chopin function is used
126-
class_vec <-
127-
if (pkgname == "chopin") {
128-
if (is_extract_at) {
129-
"sf"
130-
} else {
131-
"terra"
132-
}
133-
} else {
134-
pkgname
135-
}
126+
class_vec <- "sf"
127+
# if (pkgname == "chopin") {
128+
# if (is_extract_at) {
129+
# "sf"
130+
# } else {
131+
# "terra"
132+
# }
133+
# } else {
134+
# pkgname
135+
# }
136136

137137
# clean additional arguments
138138
args_input <- list(...)
139-
if (funname == "chopin" && is.null(args_input$.standalone)) {
139+
if (pkgname == "chopin" && is.null(args_input$.standalone)) {
140140
args_input$.standalone <- FALSE
141141
}
142142

@@ -154,7 +154,7 @@ par_grid_mirai <-
154154
}
155155

156156
# class identity check
157-
.check_align_fxy(pkgname, args_input$x, args_input$y)
157+
# .check_align_fxy(pkgname, args_input$x, args_input$y)
158158

159159
# Main parallelization
160160
results <-
@@ -412,15 +412,15 @@ par_hierarchy_mirai <-
412412
# parallel worker will take terra class objects
413413
# if chopin function is used
414414
class_vec <-
415-
if (pkgname == "chopin") {
415+
# if (pkgname == "chopin") {
416416
if (is_extract_at) {
417417
"sf"
418418
} else {
419419
"terra"
420420
}
421-
} else {
422-
pkgname
423-
}
421+
# } else {
422+
# pkgname
423+
# }
424424

425425
# Track spatraster file path
426426
args_input$x <- .check_par_spatraster(args_input$x)
@@ -440,7 +440,7 @@ par_hierarchy_mirai <-
440440
}
441441

442442
# class identity check
443-
.check_align_fxy(pkgname, args_input$x, args_input$y)
443+
# .check_align_fxy(pkgname, args_input$x, args_input$y)
444444

445445
# Region ID cleaning to get unique high-level IDs
446446
# what if regions refers to a path string?
@@ -748,15 +748,15 @@ par_multirasters_mirai <-
748748
# parallel worker will take terra class objects
749749
# if chopin function is used
750750
class_vec <-
751-
if (pkgname == "chopin") {
751+
# if (pkgname == "chopin") {
752752
if (is_extract_at) {
753753
"sf"
754754
} else {
755755
"terra"
756756
}
757-
} else {
758-
pkgname
759-
}
757+
# } else {
758+
# pkgname
759+
# }
760760

761761
# Unlike other par_* functions, raster paths are not
762762
# tracked by the function since the raster file paths

‎README.Rmd‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ suppressWarnings(
249249
)
250250
)
251251
par(mfrow = c(2, 1))
252-
plot(nc_comp_region_h3$original$geometry, main = "H3 grid (lv.4")
252+
plot(nc_comp_region_h3$original$geometry, main = "H3 grid (lv.3)")
253253
plot(nc_comp_region_h3$padded$geometry, main = "H3 padded grid (lv.3)")
254254
par(oldpar)
255255

0 commit comments

Comments
 (0)