| Title: | Build Potentiometric Surfaces and Flow Arrows |
| Version: | 0.1.0 |
| Author: | Elvin Cordero [aut, cre] |
| Maintainer: | Elvin Cordero <elvin.cordero@seamountgeo.com> |
| Description: | Builds potentiometric surface products from groundwater monitoring data. The package prepares groundwater observations from direct water-level measurements or depth-to-water data paired with land-surface elevations, interpolates thin-plate spline surfaces by default, supports alternative and user-supplied interpolation methods, exports raster and contour products, and derives hydraulic-gradient flow arrows. Raster operations use methods from Hijmans (2025) <doi:10.32614/CRAN.package.terra>, thin-plate spline interpolation uses methods from Nychka et al. (2021) <doi:10.5065/D6W957CT>, and geostatistical interpolation uses methods from Pebesma (2004) <doi:10.1016/j.cageo.2004.03.012>. |
| License: | GPL-3 |
| Encoding: | UTF-8 |
| LazyData: | true |
| RoxygenNote: | 7.3.3 |
| Depends: | R (≥ 4.1) |
| Imports: | fields, grDevices, graphics, gstat, sf, stats, terra |
| Suggests: | testthat (≥ 3.0.0) |
| Config/testthat/edition: | 3 |
| NeedsCompilation: | no |
| Packaged: | 2026-05-25 04:22:47 UTC; ec |
| Repository: | CRAN |
| Date/Publication: | 2026-05-29 10:10:02 UTC |
Extract arrow base or tip points
Description
Extract arrow base or tip points
Usage
ps_arrow_vertices(arrows, which = c("last", "first"), out_file = NULL)
Arguments
arrows |
A line |
which |
|
out_file |
Optional output vector path. |
Value
A point SpatVector.
Examples
data("synthetic_wells")
pts <- ps_make_points(synthetic_wells, "x", "y", "gw_elevation",
"well_id", "EPSG:26916")
s <- ps_interpolate(pts, methods = "IDW", grid_res = 100)
arrows <- ps_flow_arrows(s$IDW, res_factor = 4, scale = 60)
tips <- ps_arrow_vertices(arrows$arrows, which = "last")
tips
Create contours from a surface raster
Description
Create contours from a surface raster
Usage
ps_contours(surface, interval = 1, levels = NULL)
Arguments
surface |
A |
interval |
Contour interval in map elevation units. |
levels |
Optional explicit contour levels. When supplied, |
Value
A line terra::SpatVector of contours.
Examples
data("synthetic_wells")
pts <- ps_make_points(synthetic_wells, "x", "y", "gw_elevation",
"well_id", "EPSG:26916")
s <- ps_interpolate(pts, methods = "IDW", grid_res = 100)
ctr <- ps_contours(s$IDW, interval = 1)
ctr
Export surfaces, contours, and quicklook PNGs
Description
Export surfaces, contours, and quicklook PNGs
Usage
ps_export_surfaces(
surfaces,
out_dir,
out_stub = "gw",
contour_interval = 1,
points = NULL,
write_raster = TRUE,
write_contours = TRUE,
write_png = TRUE
)
Arguments
surfaces |
A named list of |
out_dir |
Output directory. |
out_stub |
File prefix. |
contour_interval |
Contour interval. |
points |
Optional observation points to draw on quicklook figures. |
write_raster, write_contours, write_png |
Choose which outputs to write. |
Value
A data frame listing written files.
Examples
data("synthetic_wells")
pts <- ps_make_points(synthetic_wells, "x", "y", "gw_elevation",
"well_id", "EPSG:26916")
s <- ps_interpolate(pts, methods = "IDW", grid_res = 100)
out <- ps_export_surfaces(s, points = pts, out_dir = tempdir())
out
Generate hydraulic-gradient flow arrows
Description
Derives slope, aspect, hydraulic gradient, and downgradient arrows from a potentiometric surface raster.
Usage
ps_flow_arrows(
surface,
res_factor = 7,
scale = 50,
min_gradient = 1e-05,
log_gradient = FALSE,
log_arrow = FALSE,
out_dir = NULL,
out_stub = "gw"
)
Arguments
surface |
A groundwater elevation |
res_factor |
Factor used to thin arrows by resampling to a coarser grid. |
scale |
Arrow length multiplier. |
min_gradient |
Gradients below this value are dropped. |
log_gradient |
Store |
log_arrow |
Use |
out_dir |
Optional output directory. When supplied, files are written. |
out_stub |
File prefix used when writing outputs. |
Value
A list with raster, points, and arrows.
Examples
data("synthetic_wells")
pts <- ps_make_points(synthetic_wells, "x", "y", "gw_elevation",
"well_id", "EPSG:26916")
s <- ps_interpolate(pts, methods = "IDW", grid_res = 100)
arrows <- ps_flow_arrows(s$IDW, res_factor = 4, scale = 60)
arrows$arrows
Interpolate potentiometric surfaces
Description
Creates one raster per requested interpolation method. The default method is
thin-plate spline ("TPS"). Other built-in methods are inverse distance
weighting ("IDW"), ordinary kriging ("OK"), and universal kriging with
quadratic drift ("UK"). Advanced users can also pass named custom
interpolation functions through custom_methods.
Usage
ps_interpolate(
points,
value = "Z",
methods = "TPS",
grid_res = NULL,
template = NULL,
mask = NULL,
padding = NULL,
idw_power = 2,
idw_nmax = 15,
tps_lambda = NULL,
kr_auto_cutoff = TRUE,
kr_cutoff = NA_real_,
kr_width = NA_real_,
custom_methods = NULL,
x = "x",
y = "y",
name_col = NULL,
crs = NULL
)
Arguments
points |
A point |
value |
Data column name when |
methods |
Character vector of interpolation methods. Built-in values are
|
grid_res |
Output raster cell size in map units. |
template |
Optional template |
mask |
Optional AOI polygon used to crop and mask output rasters. |
padding |
Padding added around the convex hull extent when building a template from points. |
idw_power, idw_nmax |
IDW power and maximum neighbors. |
tps_lambda |
Thin-plate spline smoothing parameter. |
kr_auto_cutoff |
Use automatic variogram cutoff and lag width. |
kr_cutoff, kr_width |
Manual variogram cutoff and lag width. |
custom_methods |
Optional named list of custom interpolation functions.
Each function is called as |
x, y, name_col, crs |
Used when |
Value
A named list of SpatRaster surfaces.
Examples
data("synthetic_wells")
pts <- ps_make_points(synthetic_wells, "x", "y", "gw_elevation",
"well_id", "EPSG:26916")
surfaces <- ps_interpolate(pts, grid_res = 100)
names(surfaces)
Make groundwater observation points
Description
Convert a coordinate table, sf point object, or terra vector to a
SpatVector with standard Z and Name fields.
Usage
ps_make_points(data, x = "x", y = "y", value, name_col = NULL, crs = NULL)
Arguments
data |
A data frame, |
x, y |
Coordinate column names for tabular data. |
value |
Groundwater elevation column name. |
name_col |
Optional well or station name column. |
crs |
Coordinate reference system for tabular data, such as
|
Value
A point terra::SpatVector with standardized attributes.
Examples
data("synthetic_wells")
pts <- ps_make_points(
synthetic_wells,
x = "x", y = "y",
value = "gw_elevation",
name_col = "well_id",
crs = "EPSG:26916"
)
pts
Build potentiometric points from depth-to-water measurements
Description
Calculates groundwater elevation as surface elevation minus depth to water. Surface elevation can come from a DEM raster, a column in the depth table, or separate surface-elevation points. Separate surface points are matched by name when possible; otherwise their elevations are interpolated to the depth points with inverse distance weighting.
Usage
ps_potentiometric_points(
data,
x = "x",
y = "y",
depth_col,
surface = NULL,
surface_col = NULL,
name_col = NULL,
surface_name_col = name_col,
crs = NULL,
idw_power = 2
)
Arguments
data |
Depth-to-water observations as a data frame, |
x, y |
Coordinate column names for tabular depth data. |
depth_col |
Depth-to-water column name. Positive values are assumed to be depth below land surface. |
surface |
A DEM |
surface_col |
Surface-elevation column in |
name_col |
Optional name column in |
surface_name_col |
Optional name column in separate surface observations. |
crs |
CRS for tabular depth data. |
idw_power |
Power used when interpolating separate surface points. |
Value
A point terra::SpatVector with surface_elevation,
depth_to_water, and Z groundwater elevation fields.
Examples
data("synthetic_wells")
data("synthetic_dem")
gw <- ps_potentiometric_points(
synthetic_wells,
x = "x", y = "y",
depth_col = "depth_to_water",
surface = synthetic_dem,
name_col = "well_id",
crs = "EPSG:26916"
)
head(terra::values(gw))
Draw a quicklook surface plot
Description
Draw a quicklook surface plot
Usage
ps_quicklook(
surface,
contours = NULL,
points = NULL,
file = NULL,
title = "Potentiometric surface",
label_points = TRUE,
width = 1600,
height = 1200,
res = 180
)
Arguments
surface |
A |
contours |
Optional contour |
points |
Optional observation point |
file |
Optional PNG output path. When |
title |
Plot title. |
label_points |
Label points with |
width, height, res |
PNG dimensions and resolution. |
Value
Invisibly returns file.
Examples
data("synthetic_wells")
pts <- ps_make_points(synthetic_wells, "x", "y", "gw_elevation",
"well_id", "EPSG:26916")
s <- ps_interpolate(pts, methods = "IDW", grid_res = 100)
ps_quicklook(s$IDW, points = pts, title = "Synthetic IDW")
Make the sample area-of-interest polygon
Description
Make the sample area-of-interest polygon
Usage
ps_sample_aoi()
Value
A terra::SpatVector polygon in EPSG:26916.
Examples
aoi <- ps_sample_aoi()
aoi
Smooth a potentiometric surface raster
Description
Applies a focal moving-window smoother to a potentiometric surface raster. This can be useful when an interpolated surface is technically valid but too locally rough for contour development or hydraulic-gradient visualization.
Usage
ps_smooth_surface(
surface,
window_size = 3,
method = c("mean", "median"),
weights = NULL,
iterations = 1,
na.rm = TRUE,
preserve_na = TRUE,
filename = "",
overwrite = FALSE
)
Arguments
surface |
A |
window_size |
Odd integer window size used when |
method |
Smoothing statistic. Supported values are |
weights |
Optional odd-dimension numeric matrix of focal weights.
|
iterations |
Number of smoothing passes. |
na.rm |
Ignore missing values inside the focal window. |
preserve_na |
Preserve the original |
filename |
Optional output raster filename. |
overwrite |
Overwrite |
Value
A smoothed terra::SpatRaster.
Examples
data("synthetic_wells")
pts <- ps_make_points(synthetic_wells, "x", "y", "gw_elevation",
"well_id", "EPSG:26916")
s <- ps_interpolate(pts, grid_res = 100)
smoothed <- ps_smooth_surface(s$TPS, window_size = 5)
smoothed
Synthetic DEM raster
Description
A small artificial DEM matching synthetic_wells, stored as a packed
terra raster. Use terra::rast(synthetic_dem) to unpack it.
Usage
synthetic_dem
Format
A terra::PackedSpatRaster with one layer named
surface_elevation.
Examples
data("synthetic_dem")
dem <- terra::rast(synthetic_dem)
dem
Synthetic surface elevation measurement points
Description
Artificial land-surface elevation points for demonstrating workflows that do not start with a DEM raster.
Usage
synthetic_surface_points
Format
A data frame with coordinate, surface-elevation, and name columns.
Examples
data("synthetic_surface_points")
head(synthetic_surface_points)
Synthetic groundwater monitoring wells
Description
A real-looking artificial monitoring dataset with coordinates, land-surface elevation, depth to water, and calculated groundwater elevation.
Usage
synthetic_wells
Format
A data frame with 32 rows and 6 columns:
- well_id
Synthetic well identifier.
- x
Easting in EPSG:26916 map units.
- y
Northing in EPSG:26916 map units.
- surface_elevation
Land-surface elevation.
- depth_to_water
Depth to groundwater below land surface.
- gw_elevation
Groundwater elevation.
Examples
data("synthetic_wells")
head(synthetic_wells)