| Title: | Build Potentiometric Surfaces and Flow Arrows |
|---|---|
| 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>. |
| Authors: | Elvin Cordero [aut, cre] |
| Maintainer: | Elvin Cordero <[email protected]> |
| License: | GPL-3 |
| Version: | 0.1.0 |
| Built: | 2026-05-29 13:00:58 UTC |
| Source: | https://github.com/cran/potentiomap |
Extract arrow base or tip points
ps_arrow_vertices(arrows, which = c("last", "first"), out_file = NULL)ps_arrow_vertices(arrows, which = c("last", "first"), out_file = NULL)
arrows |
A line |
which |
|
out_file |
Optional output vector path. |
A point SpatVector.
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") tipsdata("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
ps_contours(surface, interval = 1, levels = NULL)ps_contours(surface, interval = 1, levels = NULL)
surface |
A |
interval |
Contour interval in map elevation units. |
levels |
Optional explicit contour levels. When supplied, |
A line terra::SpatVector of contours.
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) ctrdata("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
ps_export_surfaces( surfaces, out_dir, out_stub = "gw", contour_interval = 1, points = NULL, write_raster = TRUE, write_contours = TRUE, write_png = TRUE )ps_export_surfaces( surfaces, out_dir, out_stub = "gw", contour_interval = 1, points = NULL, write_raster = TRUE, write_contours = TRUE, write_png = TRUE )
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. |
A data frame listing written files.
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()) outdata("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
Derives slope, aspect, hydraulic gradient, and downgradient arrows from a potentiometric surface raster.
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" )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" )
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. |
A list with raster, points, and arrows.
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$arrowsdata("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
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.
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 )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 )
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 |
A named list of SpatRaster surfaces.
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)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)
Convert a coordinate table, sf point object, or terra vector to a
SpatVector with standard Z and Name fields.
ps_make_points(data, x = "x", y = "y", value, name_col = NULL, crs = NULL)ps_make_points(data, x = "x", y = "y", value, name_col = NULL, crs = NULL)
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
|
A point terra::SpatVector with standardized attributes.
data("synthetic_wells") pts <- ps_make_points( synthetic_wells, x = "x", y = "y", value = "gw_elevation", name_col = "well_id", crs = "EPSG:26916" ) ptsdata("synthetic_wells") pts <- ps_make_points( synthetic_wells, x = "x", y = "y", value = "gw_elevation", name_col = "well_id", crs = "EPSG:26916" ) pts
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.
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 )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 )
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. |
A point terra::SpatVector with surface_elevation,
depth_to_water, and Z groundwater elevation fields.
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))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
ps_quicklook( surface, contours = NULL, points = NULL, file = NULL, title = "Potentiometric surface", label_points = TRUE, width = 1600, height = 1200, res = 180 )ps_quicklook( surface, contours = NULL, points = NULL, file = NULL, title = "Potentiometric surface", label_points = TRUE, width = 1600, height = 1200, res = 180 )
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. |
Invisibly returns file.
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")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
ps_sample_aoi()ps_sample_aoi()
A terra::SpatVector polygon in EPSG:26916.
aoi <- ps_sample_aoi() aoiaoi <- ps_sample_aoi() aoi
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.
ps_smooth_surface( surface, window_size = 3, method = c("mean", "median"), weights = NULL, iterations = 1, na.rm = TRUE, preserve_na = TRUE, filename = "", overwrite = FALSE )ps_smooth_surface( surface, window_size = 3, method = c("mean", "median"), weights = NULL, iterations = 1, na.rm = TRUE, preserve_na = TRUE, filename = "", overwrite = FALSE )
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 |
A smoothed terra::SpatRaster.
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) smootheddata("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
A small artificial DEM matching synthetic_wells, stored as a packed
terra raster. Use terra::rast(synthetic_dem) to unpack it.
synthetic_demsynthetic_dem
A terra::PackedSpatRaster with one layer named
surface_elevation.
data("synthetic_dem") dem <- terra::rast(synthetic_dem) demdata("synthetic_dem") dem <- terra::rast(synthetic_dem) dem
Artificial land-surface elevation points for demonstrating workflows that do not start with a DEM raster.
synthetic_surface_pointssynthetic_surface_points
A data frame with coordinate, surface-elevation, and name columns.
data("synthetic_surface_points") head(synthetic_surface_points)data("synthetic_surface_points") head(synthetic_surface_points)
A real-looking artificial monitoring dataset with coordinates, land-surface elevation, depth to water, and calculated groundwater elevation.
synthetic_wellssynthetic_wells
A data frame with 32 rows and 6 columns:
Synthetic well identifier.
Easting in EPSG:26916 map units.
Northing in EPSG:26916 map units.
Land-surface elevation.
Depth to groundwater below land surface.
Groundwater elevation.
data("synthetic_wells") head(synthetic_wells)data("synthetic_wells") head(synthetic_wells)