Skip to content

Commit

Permalink
0.8.2
Browse files Browse the repository at this point in the history
- renamed par_map_args to `par_convert_f`
- clip_*_ext functions are removed
- vect_validate function is removed
- Description update for ellipsis arguments in documentation
  • Loading branch information
sigmafelix committed Sep 9, 2024
1 parent 5843eb9 commit 2b19b0d
Show file tree
Hide file tree
Showing 31 changed files with 158 additions and 631 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: chopin
Title: Computation of Spatial Data by Hierarchical and Objective Partitioning of Inputs for Parallel Processing
Version: 0.8.1
Version: 0.8.2
Authors@R: c(
person("Insang", "Song", , "geoissong@gmail.com", role = c("aut", "cre"),
comment = c(ORCID = "0000-0001-8732-3256")),
Expand All @@ -25,7 +25,7 @@ URL: https://github.com/NIEHS/chopin
BugReports: https://github.com/NIEHS/chopin/issues
Depends:
R (>= 4.1)
SystemRequirements: NetCDF4
SystemRequirements: netcdf
Encoding: UTF-8
LazyData: true
LazyDataCompression: xz
Expand Down
6 changes: 1 addition & 5 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

export(extract_at)
export(kernelfunction)
export(par_convert_f)
export(par_grid)
export(par_hierarchy)
export(par_map_args)
export(par_merge_grid)
export(par_multirasters)
export(par_pad_balanced)
Expand Down Expand Up @@ -54,11 +54,9 @@ importFrom(sf,st_coordinates)
importFrom(sf,st_crs)
importFrom(sf,st_geometry_type)
importFrom(sf,st_interpolate_aw)
importFrom(sf,st_intersection)
importFrom(sf,st_intersects)
importFrom(sf,st_length)
importFrom(sf,st_make_grid)
importFrom(sf,st_make_valid)
importFrom(sf,st_read)
importFrom(sf,st_relate)
importFrom(sf,st_set_crs)
Expand All @@ -74,15 +72,13 @@ importFrom(terra,area)
importFrom(terra,as.polygons)
importFrom(terra,buffer)
importFrom(terra,crds)
importFrom(terra,crop)
importFrom(terra,crs)
importFrom(terra,distance)
importFrom(terra,expanse)
importFrom(terra,ext)
importFrom(terra,geom)
importFrom(terra,geomtype)
importFrom(terra,intersect)
importFrom(terra,makeValid)
importFrom(terra,nearby)
importFrom(terra,project)
importFrom(terra,rast)
Expand Down
53 changes: 19 additions & 34 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# 0.7.8
- `.check_package` refactoring: no `library()` call is required
# 0.8
- Bumped version from 0.7.8 to 0.8.0: improving package coverage
- README.md: two mermaid plots are pre-generated as png files
- Internal `clip_*()` functions are removed
- `par_map_args()` is renamed to `par_convert_f()`

# 0.7.7
- Documentation is revised

# 0.7.6
# 0.7
- `.check_package` refactoring: no `library()` call is required
- Internal function .check_par_spatraster is added to main `par_*` functions

# 0.7.5
- Internal: Preprocessing "dot-functions" -- universally usable functions are plain S3, whereas others that are class-specific were implemented in S4
- Internal preprocessing "dot-functions" -- universally usable functions are plain S3, whereas others that are class-specific were implemented in S4
- Added
- CITATION.cff
- `par_*`: argument `pad_y` to enable applying padded extent to x or y (e.g., y in raster-vector overlay and x otherwise)
Expand All @@ -20,69 +20,54 @@
- `any_class_args`, `is_within_ref`, `par_fallback`, `check_dist_incorrect`
- `par_grid` argument: `grids_input_ids`
- Data: SRTM (TIFF replaces RDS)

# 0.7.4
- Data preprocessing parts are separated into internal functions
- Name change
- `check_subject` to `.check_vector`
- `reproject_b2r` to `reproject_to_raster`
- `vect_valid_repair` to `vect_validate`
- targets-friendly helper function: `par_split_list`
- Vignette for `par_split_list`

# 0.7.3
- BREAKING
- `par_*` family naming hierarchy: `par_make_*` to `par_pad_*`
- Plain gridding (`par_make_grid`) and clustering (`par_make_balanced`) functions are internal
- Main `par_*` runners (par_grid, par_hierarchy, par_multirasters) are kept
- `par_*` family naming hierarchy: `par_make_*` to `par_pad_*`
- Plain gridding (`par_make_grid`) and clustering (`par_make_balanced`) functions are internal
- Main `par_*` runners (par_grid, par_hierarchy, par_multirasters) are kept
- `extract_at` is redesigned as a S4 method
- All messaging is managed by `cli` package
- Added zzz.R for startup message

# 0.7.2
- `summarize_aw` gets generic argument names `x` and `y`
- `mirai` backend is introduced
- Internal functions are not exported

# 0.7.0
- Type check function `check_subject` is added. This function is internal.
- `vapply` argument `FUN.VALUE` fixed

# 0.6.4
- FIX: `grid_target_id` in `par_grid` accepts numeric or character input to filter grids
# 0.6
- Fixed: `grid_target_id` in `par_grid` accepts numeric or character input to filter grids
- `par_fallback` is returning error_message field with actual error messages
- `collapse` package is added to Imports (i.e., `rowbind` function is used in place of `dplyr::bind_rows`)
- Tests were fixed following refactoring/updating `par_*` functions
- `chopin` processing functions now support file path input with extents in `par_grid`

# 0.6.3
- FIX: Missing argument passing in `par_pad_grid` with `mode = "grid_advanced"`
- Fixed: Missing argument passing in `par_pad_grid` with `mode = "grid_advanced"`
- Vignette update: v01

# 0.6.2
- FIX: align input-output classes in `par_merge_grid`
- IMPROVE: grid_advanced mode supports the maximum of merged unit grids
- Fixed: align input-output classes in `par_merge_grid`
- Improved: grid_advanced mode supports the maximum of merged unit grids
- Added the balanced number mode of splitting input points (`par_pad_balanced`; thanks to comments of Dr. Michael Fessler)
- Added function of the balanced mode for `par_grid` (`par_group_grid`)
- All internal `sapply` is changed to `vapply`
- Added a diagram for guiding users' choice for `par_*` functions for parallelization considering raster/vector data situations
- litr R Markdown file is moved to the archive

# 0.5.0
# 0.5
- `par_grid` unifies the classes of grid inputs
- `par_cut_coords`: a supplementary function effectively operating with `par_def_q` for `mode = "grid_quantile"` in `par_pad_grid`. X- and Y-coordinates (of centroids for polygon inputs) are split into quantile groups to balance the number of features in each grid; does not account for geometric complexity (i.e., number of vertices)
- Padded grid generation in `par_pad_grid` is done only by `terra::buffer`
- `extract_at*` functions get `max_cells`, which is passed to `exactextractr::exact_extract` for speedup in expense of memory pressure
- Added a new vignette on the demonstration of climate/weather data extraction

# 0.4.0
# 0.4
- `surf` argument in `extract_at*()` accepts file paths
- Raster cropping is now optional

# 0.3.1
# 0.3
- Dropped `rast_short`
- Added examples

# 0.3.0
- README.md is replaced by README.Rmd
- Documentation is clarified about the second argument in `...` in `par_*` functions
39 changes: 1 addition & 38 deletions R/check.R
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ reproject_std <-

#' @title Align vector CRS to raster's
#' @family Helper functions
#' @keywords internal soft-deprecated
#' @keywords internal
#' @param vector `sf`/`stars`/`SpatVector`/`SpatRaster` object
#' @param raster `SpatRaster` object
#' @returns Reprojected object in the same class as \code{vector}
Expand Down Expand Up @@ -254,43 +254,6 @@ reproject_to_raster <-



#' Validate and repair input vector data
#' @family Helper functions
#' @keywords internal soft-deprecated
#' @description It tries repairing input vector data.
#' Vector validity violation usually appears in polygon data with
#' self-crossing or
#' hole orders. This function will pass the input_vector object to
#' [`sf::st_make_valid`] (if input_vector is sf) or
#' [`terra::makeValid`] (if input_vector is SpatVector).
#' May take some time depending on the geometry complexity.
#' @author Insang Song
#' @param input_vector One of sf or vect class. Target points of computation.
#' @returns A repaired `sf` or `SpatVector` object depending on
#' the class of input_vector.
#' @note This function works with GEOS (>=3.8).
#' @examples
#' \dontrun{
#' library(terra)
#' library(sf)
#' ncpath <- system.file("gpkg/nc.gpkg", package = "sf")
#' nc <- terra::vect(ncpath)
#'
#' nc_valid <- vect_validate(nc)
#' }
#' @importFrom terra makeValid
#' @importFrom sf st_make_valid
vect_validate <- function(input_vector) {
detected <- dep_check(input_vector)

validated <- switch(detected,
terra = terra::makeValid(input_vector),
sf = sf::st_make_valid(input_vector)
)

return(validated)
}


# ## .intersect_extent ####
#' Get intersection extent
Expand Down
1 change: 0 additions & 1 deletion R/gridding.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
#' @description Using input points, the bounding box is split to
#' the predefined numbers of columns and rows.
#' Each grid will be buffered by the radius.
#' @seealso [`par_merge_grid`]
#' @author Insang Song
#' @examples
#' # data
Expand Down
109 changes: 1 addition & 108 deletions R/preprocessing.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#' @param extrusion numeric(1). The extent extrusion factor.
#' Default is 1.1, meaning that the actual padding is 10 percent
#' wider than `radius`.
#' @returns A `terra::ext` or sfc_POLYGON object of the computation extent.
#' @returns A [`terra::ext`] or sfc_POLYGON object of the computation extent.
#' @examples
#' \dontrun{
#' library(sf)
Expand Down Expand Up @@ -47,110 +47,3 @@ get_clip_ext <- function(
}
return(ext_input)
}


#' Clip to the buffered extent of input vector
#' @family Helper functions
#' @description Clip input vector by
#' the expected maximum extent of computation.
#' @keywords internal
#' @author Insang Song
#' @param x `sf` or `SpatVector` object to be clipped
#' @param y `sf` or `SpatVector` object
#' @param radius `numeric(1)`. Circular buffer radius.
#' this value will be automatically multiplied by 1.1
#' @returns A clipped `sf` or `SpatVector` object.
#' @examples
#' \dontrun{
#' library(sf)
#' library(stars)
#' library(terra)
#' options(sf_use_s2 = FALSE)
#'
#' bcsd_path <- system.file(package = "stars", "nc/bcsd_obs_1999.nc")
#' bcsd <- stars::read_stars(bcsd_path)
#' bcsd <- sf::st_as_sf(bcsd)
#' bcsd_rpnt <- sf::st_as_sf(sf::st_sample(bcsd, 4L))
#' bcsd_rpntm <- sf::st_as_sf(sf::st_sample(bcsd, 1000L))
#' clip_vec_ext(bcsd_rpntm, 1000, bcsd_rpnt)
#' }
#' @importFrom sf st_intersection
#' @importFrom terra intersect
clip_vec_ext <- function(
x,
y,
radius
) {
if (any(
vapply(
list(x, y, radius),
FUN = is.null,
FUN.VALUE = logical(1)
)
)) {
cli::cli_abort(
c("x" = "One or more required arguments are NULL. Please check.\n")
)
}
detected_pnts <- dep_check(y)
detected_target <- dep_check(x)

if (detected_pnts != detected_target) {
cli::cli_warn(c("Inputs are not the same class.\n"))
x <- dep_switch(x)
}

ext_input <- get_clip_ext(y, radius)

cli::cli_inform(
c("i" = "Clip target features with the input feature extent...\n")
)
if (detected_pnts == "sf") {
cae <-
sf::st_intersection(x = x, y = ext_input)
}
if (detected_pnts == "terra") {
cae <- terra::intersect(x, ext_input)
}

return(cae)
}

#' Clip input raster with a buffered vector extent.
#' @family Helper functions
#' @keywords internal soft-deprecated
#' @description Clip input raster by the expected maximum extent of
#' computation.
#' @param x `SpatRaster` object to be clipped
#' @param y `sf` or `SpatVector` object
#' @param radius numeric(1). buffer radius.
#' This value will be automatically multiplied by `extrusion`
#' @param nqsegs integer(1). the number of points per a quarter circle.
#' Default is 180L.
#' @param extrusion numeric(1). Extrusion factor for the extent. Default is 1.1.
#' @returns A clipped `SpatRaster` object.
#' @author Insang Song
#' @importFrom terra vect crop
clip_ras_ext <- function(
x = NULL,
y = NULL,
radius = NULL,
nqsegs = 180L,
extrusion = 1.1
) {
if (any(
vapply(list(y, radius, x),
FUN = is.null,
FUN.VALUE = logical(1))
)) {
cli::cli_abort(
c("x" = "Any of required arguments are NULL. Please check.\n")
)
}
radius <- extrusion * radius
ext_input <- get_clip_ext(y, radius)
ext_input <- terra::vect(ext_input)

cae <- terra::crop(x, ext_input, snap = "out")
return(cae)
}
2 changes: 1 addition & 1 deletion R/processing.R
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,7 @@ summarize_sedc <-
#' It only works with `x` of character(1) file path.
#' See [`terra::ext`] for more details. Coordinate systems should match.
#' @param out_class character(1). "sf" or "terra". Output class.
#' @param ... Placeholder.
#' @param ... Additional arguments depending on class of `x` and `y`.
#' @returns A data.frame with all numeric fields of area-weighted means.
#' @description When `x` and `y` are different classes,
#' `poly_weight` will be converted to the class of `x`.
Expand Down
Loading

0 comments on commit 2b19b0d

Please sign in to comment.