Skip to content

Commit

Permalink
Merge branch 'joss' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeldumelle authored Dec 4, 2023
2 parents 7d00f8a + 01c23ba commit aea3909
Show file tree
Hide file tree
Showing 38 changed files with 2,447 additions and 148 deletions.
2 changes: 1 addition & 1 deletion .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
^docs$
^pkgdown$
^CRAN-SUBMISSION$
^CONTRIBUTING\.md$
^CONTRIBUTING\.md$
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: SSN2
Title: Spatial Modeling on Stream Networks
Version: 0.1.0
Version: 0.1.1
Authors@R: c(
person(given = "Michael",
family = "Dumelle",
Expand Down
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export(randcov_initial)
export(randcov_params)
export(ssn_create_distmat)
export(ssn_get_data)
export(ssn_get_netgeometry)
export(ssn_get_netgeom)
export(ssn_get_stream_distmat)
export(ssn_glm)
export(ssn_import)
Expand Down
8 changes: 8 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# SSN 0.1.1

## Minor Updates

* Changed network geometry name from `netgeometry` to `netgeom` to avoid exceeding the 10 character limit for column/field names while writing to shapefiles [(#2)](https://github.com/USEPA/SSN2/issues/2).

## Bug Fixes

# SSN2 0.1.0

* Initial CRAN submission.
12 changes: 6 additions & 6 deletions R/SSN_to_SSN2.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ SSN_to_SSN2 <- function(object, edge_additive = NULL, site_additive = NULL) {
}

## ---------------------------------------------------
## Convert edges to sf and add netgeometry column
## Convert edges to sf and add netgeom column
## ---------------------------------------------------

sl <- sp::SpatialLines(object@lines, proj4string = object@proj4string)
Expand All @@ -62,7 +62,7 @@ SSN_to_SSN2 <- function(object, edge_additive = NULL, site_additive = NULL) {

nl.coords <- object@network.line.coords

edges$netgeometry <- paste("ENETWORK",
edges$netgeom <- paste("ENETWORK",
paste("(",
paste(
nl.coords$NetworkID,
Expand Down Expand Up @@ -100,7 +100,7 @@ SSN_to_SSN2 <- function(object, edge_additive = NULL, site_additive = NULL) {


## ------------------------------------------------
## Convert observed sites to sf and add netgeometry
## Convert observed sites to sf and add netgeom
## ------------------------------------------------
## sites<- st_as_sf(sp::SpatialPointsDataFrame(object@obspoints@SSNPoints[[1]]@point.coords,
## object@obspoints@SSNPoints[[1]]@point.data,
Expand All @@ -116,7 +116,7 @@ SSN_to_SSN2 <- function(object, edge_additive = NULL, site_additive = NULL) {
np.coords <- object@obspoints@SSNPoints[[1]]@network.point.coords
np.coords <- cbind(np.coords, sites[, c("ratio", "locID")])
np.coords$pid <- rownames(object@obspoints@SSNPoints[[1]]@network.point.coords)
sites$netgeometry <- paste(
sites$netgeom <- paste(
"SNETWORK",
paste(
"(",
Expand Down Expand Up @@ -161,7 +161,7 @@ SSN_to_SSN2 <- function(object, edge_additive = NULL, site_additive = NULL) {

## ------------------------------------------------------------- If
## prediction sites are present, convert to list of sf data.frames
## and add netgeometry column
## and add netgeom column
## -------------------------------------------------------------

if (length(object@predpoints@ID) > 0) {
Expand All @@ -184,7 +184,7 @@ SSN_to_SSN2 <- function(object, edge_additive = NULL, site_additive = NULL) {
tmp.sf[, c("ratio", "locID")]
)
np.coords$pid <- rownames(object@predpoints@SSNPoints[[i]]@network.point.coords)
tmp.sf$netgeometry <- paste(
tmp.sf$netgeom <- paste(
"SNETWORK",
paste(
"(",
Expand Down
4 changes: 2 additions & 2 deletions R/amongSitesDistMat.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ amongSitesDistMat <- function(ssn, pids, name = "obs", bin.table) {
if (name != "obs") {
ind.pids <- ssn$preds[[name]]$ng.pid %in% as.character(pids)
locID.pid.data <- ssn$preds[[name]]$locID[ind.pids]
pid.data <- ssn_get_netgeometry(ssn$preds[[name]][ind.pids, ], c(
pid.data <- ssn_get_netgeom(ssn$preds[[name]][ind.pids, ], c(
"pid", "SegmentID", "locID",
"DistanceUpstream"
))
Expand All @@ -22,7 +22,7 @@ amongSitesDistMat <- function(ssn, pids, name = "obs", bin.table) {
} else {
ind.pids <- ssn$obs$ng.pid %in% as.character(pids)
locID.pid.data <- ssn$obs$locID[ind.pids]
pid.data <- ssn_get_netgeometry(ssn$obs[ind.pids, ], c(
pid.data <- ssn_get_netgeom(ssn$obs[ind.pids, ], c(
"pid", "SegmentID", "locID",
"DistanceUpstream"
), reformat = TRUE)
Expand Down
4 changes: 2 additions & 2 deletions R/augment.R
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ augment.ssn_lm <- function(x, drop = TRUE, newdata = NULL, se_fit = FALSE,
augment_data$.se.fit <- preds_data$se.fit
}
tibble_out <- tibble::tibble(cbind(data, augment_data, influence(x)))
tibble_out$pid <- ssn_get_netgeometry(x$ssn.object$obs, netvars = "pid")$pid
tibble_out$pid <- ssn_get_netgeom(x$ssn.object$obs, netvars = "pid")$pid
coords <- sf::st_coordinates(x$ssn.object$obs)
tibble_out$.xcoord <- coords[, 1, drop = TRUE]
tibble_out$.ycoord <- coords[, 2, drop = TRUE]
Expand Down Expand Up @@ -158,7 +158,7 @@ augment.ssn_lm <- function(x, drop = TRUE, newdata = NULL, se_fit = FALSE,
}
coords <- sf::st_coordinates(newdata)
tibble_out <- tibble::tibble(cbind(sf::st_drop_geometry(newdata), augment_newdata))
augment_newdata$pid <- ssn_get_netgeometry(newdata, netvars = "pid")$pid
augment_newdata$pid <- ssn_get_netgeom(newdata, netvars = "pid")$pid
tibble_out$.xcoord <- coords[, 1, drop = TRUE]
tibble_out$.ycoord <- coords[, 2, drop = TRUE]
tibble_out <- sf::st_as_sf(tibble_out, coords = c(".xcoord", ".ycoord"), crs = x$crs)
Expand Down
10 changes: 5 additions & 5 deletions R/create_netgeometry.R
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
## Add netgeometry column to sf data.frame sf_data
create_netgeometry <- function(sf_data, type = NULL) {
## Add netgeom column to sf data.frame sf_data
create_netgeom <- function(sf_data, type = NULL) {
if (type == "point") {
sf_data[, "netgeometry"] <- paste0("SNETWORK (", paste(
sf_data[, "netgeom"] <- paste0("SNETWORK (", paste(
sf_data$netID, sf_data$rid, sf_data$upDist,
sf_data$ratio, sf_data$pid, sf_data$locID
), ")", sep = "")
} else {
sf_data[, "netgeometry"] <- paste0("ENETWORK (", paste(
sf_data[, "netgeom"] <- paste0("ENETWORK (", paste(
sf_data$netID,
sf_data$rid,
sf_data$upDist
Expand All @@ -15,5 +15,5 @@ create_netgeometry <- function(sf_data, type = NULL) {
sep = ""
)
}
return(sf_data) ## Return sf data.frame with netgeometry column added
return(sf_data) ## Return sf data.frame with netgeom column added
}
2 changes: 1 addition & 1 deletion R/get_data_object.R
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ get_data_object <- function(formula, ssn.object, additive, anisotropy,
order <- unlist(split(seq_len(n), local$index), use.names = FALSE)

# store global pid
pid <- ssn_get_netgeometry(ssn.object$obs, "pid")$pid
pid <- ssn_get_netgeom(ssn.object$obs, "pid")$pid

# restructure ssn
ssn.object <- restruct_ssn_missing(ssn.object, observed_index, missing_index)
Expand Down
2 changes: 1 addition & 1 deletion R/get_data_object_glm.R
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ get_data_object_glm <- function(formula, ssn.object, family, additive, anisotrop
order <- unlist(split(seq_len(n), local$index), use.names = FALSE)

# store global pid
pid <- ssn_get_netgeometry(ssn.object$obs, "pid")$pid
pid <- ssn_get_netgeom(ssn.object$obs, "pid")$pid

# restructure ssn
ssn.object <- restruct_ssn_missing(ssn.object, observed_index, missing_index)
Expand Down
8 changes: 4 additions & 4 deletions R/get_dist_object.R
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# parent function to get the distance object
get_dist_object <- function(ssn.object, initial_object, additive, anisotropy) {
# get netgeometry
netgeometry <- ssn_get_netgeometry(ssn.object$obs, reformat = TRUE)
# get netgeom
netgeom <- ssn_get_netgeom(ssn.object$obs, reformat = TRUE)

# get network index
network_index <- netgeometry$NetworkID
network_index <- netgeom$NetworkID

# get pid
pid <- netgeometry$pid # not needed now but can reorder by it later
pid <- netgeom$pid # not needed now but can reorder by it later

# distance order
dist_order <- order(network_index, pid)
Expand Down
16 changes: 8 additions & 8 deletions R/get_dist_pred_object.R
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
# parent function to get the distance object
get_dist_pred_object <- function(object, newdata_name, initial_object) {
# get netgeometry
netgeometry <- ssn_get_netgeometry(object$ssn.object$obs, reformat = TRUE)
# get netgeom
netgeom <- ssn_get_netgeom(object$ssn.object$obs, reformat = TRUE)

# get network index
network_index <- netgeometry$NetworkID
network_index <- netgeom$NetworkID

# get pid
pid <- netgeometry$pid
pid <- netgeom$pid

# distance order
dist_order <- order(network_index, pid)

# inverse of distance order
inv_dist_order <- order(dist_order)

# get netgeometry
netgeometry_pred <- ssn_get_netgeometry(object$ssn.object$preds[[newdata_name]], reformat = TRUE)
# get netgeom
netgeom_pred <- ssn_get_netgeom(object$ssn.object$preds[[newdata_name]], reformat = TRUE)

# get network pred index
network_index_pred <- netgeometry_pred$NetworkID
network_index_pred <- netgeom_pred$NetworkID

# get pid
pid_pred <- netgeometry_pred$pid
pid_pred <- netgeom_pred$pid

# distance order
dist_order_pred <- order(network_index_pred, pid_pred)
Expand Down
8 changes: 4 additions & 4 deletions R/get_dist_predbk_object.R
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# parent function to get the distance object
get_dist_predbk_object <- function(object, newdata_name, initial_object) {
# get netgeometry
netgeometry <- ssn_get_netgeometry(object$ssn.object$preds[[newdata_name]], reformat = TRUE)
# get netgeom
netgeom <- ssn_get_netgeom(object$ssn.object$preds[[newdata_name]], reformat = TRUE)

# get network index
network_index <- netgeometry$NetworkID
network_index <- netgeom$NetworkID

# get pid
pid <- netgeometry$pid
pid <- netgeom$pid

# distance order
dist_order <- order(network_index, pid)
Expand Down
14 changes: 7 additions & 7 deletions R/ssn_create_distmat.R
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,9 @@ ssn_create_distmat <- function(ssn.object, predpts = NULL, overwrite = FALSE,
if (!file.exists(file.path(ssn$path, "distance", predpts))) {
dir.create(file.path(ssn$path, "distance", predpts))
}
## Extract netgeometry data from predpts and format
## Extract netgeom data from predpts and format
tmp.df <- ssn_get_data(ssn, predpts)
n.geom <- ssn_get_netgeometry(ssn$preds[[predpts]])
n.geom <- ssn_get_netgeom(ssn$preds[[predpts]])
colnames(n.geom)[4:6] <- paste0("ng.", colnames(n.geom[4:6]))
n.geom$NetworkID <- as.factor(n.geom$NetworkID)
n.geom$DistanceUpstream <- as.numeric(n.geom$DistanceUpstream)
Expand All @@ -208,9 +208,9 @@ ssn_create_distmat <- function(ssn.object, predpts = NULL, overwrite = FALSE,
rm(tmp.df, n.geom)
}

## Extract netgeometry and format obs data
## Extract netgeom and format obs data
tmp.df <- ssn_get_data(ssn)
n.geom <- ssn_get_netgeometry(ssn$obs)
n.geom <- ssn_get_netgeom(ssn$obs)
colnames(n.geom)[4:6] <- paste0("ng.", colnames(n.geom[4:6]))
n.geom$NetworkID <- as.factor(n.geom$NetworkID)
n.geom$DistanceUpstream <- as.numeric(n.geom$DistanceUpstream)
Expand All @@ -229,8 +229,8 @@ ssn_create_distmat <- function(ssn.object, predpts = NULL, overwrite = FALSE,
net.count <- length(site.nets)
warned.overwrite <- FALSE

## Extract netgeometry and format edges data
ssn$edges <- cbind(ssn$edges, ssn_get_netgeometry(ssn$edges))
## Extract netgeom and format edges data
ssn$edges <- cbind(ssn$edges, ssn_get_netgeom(ssn$edges))
ssn$edges$NetworkID <- as.factor(ssn$edges$NetworkID)
ssn$edges$DistanceUpstream <- as.numeric(ssn$edges$DistanceUpstream)

Expand Down Expand Up @@ -368,7 +368,7 @@ ssn_create_distmat <- function(ssn.object, predpts = NULL, overwrite = FALSE,
## locID.obi<- ssn$obs$ng.locID

## Create data.frame for obs with columns pid, rid, locID
ob.i <- ssn_get_netgeometry(ssn$obs[ind.obs, ], c("pid", "SegmentID", "locID"),
ob.i <- ssn_get_netgeom(ssn$obs[ind.obs, ], c("pid", "SegmentID", "locID"),
reformat = TRUE)
##ob.i <- as.data.frame(sapply(ob.i, as.numeric))
colnames(ob.i) <- c("pid", "rid", "locID")
Expand Down
24 changes: 12 additions & 12 deletions R/ssn_get_netgeometry.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#' @title Extract netgeometry column
#' @title Extract netgeom column
#'
#' @description Extract topological information from netgeometry column
#' @description Extract topological information from netgeom column
#'
#' @param x An sf data.frame found in an \code{SSN} object or the
#' netgeometry column as a vector
#' netgeom column as a vector
#'
#' @param netvars Network coordinate variables to return. Default is
#' "all". For edges, valid column names include: "NetworkID",
Expand All @@ -13,17 +13,17 @@
#' @param reformat Convert network coordinate variables from character to numeric.
#'
#' @details When an \code{SSN} object is generated using the
#' \code{importSSN} function, a text column named "netgeometry" is added
#' \code{importSSN} function, a text column named "netgeom" is added
#' to the edges, observed sites, and prediction sites (if they
#' exist) data.frames. The netgeometry column contains data used to
#' exist) data.frames. The netgeom column contains data used to
#' describe how edge and site features relate to one another in
#' topological space. For edges, netgeometry values contain the
#' topological space. For edges, netgeom values contain the
#' "ENETWORK" prefix, with 3 space delimited values in parentheses:
#' "ENETWORK (NetworkID SegmentID DistanceUpstream)". For point
#' datasets (observed and prediction sites), the values contain the
#' "SNETWORK" prefix, followed by 6 space delimited values in parentheses:
#' "SNETWORK (NetworkID SegmentID DistanceUpstream ratio pid locID)". The
#' \code{ssn_get_netgeometry} function extracts and converts these
#' \code{ssn_get_netgeom} function extracts and converts these
#' values from text to numeric, returning either a data.frame
#' (default) or vector containing the variables requested via
#' \code{netvars}.
Expand All @@ -32,7 +32,7 @@
#' function returns a data.frame (default). If only one column is
#' requested, the result is a vector.
#'
#' @name ssn_get_netgeometry
#' @name ssn_get_netgeom
#' @export
#'
#' @examples
Expand All @@ -43,9 +43,9 @@
#' temp_path <- paste0(tempdir(), "/MiddleFork04.ssn")
#' mf04p <- ssn_import(temp_path, overwrite = TRUE)
#'
#' ssn_get_netgeometry(mf04p$obs)
#' ssn_get_netgeometry(mf04p$edges, "DistanceUpstream")
ssn_get_netgeometry <- function(x, netvars = "all", reformat = FALSE) {
#' ssn_get_netgeom(mf04p$obs)
#' ssn_get_netgeom(mf04p$edges, "DistanceUpstream")
ssn_get_netgeom <- function(x, netvars = "all", reformat = FALSE) {
# I think this should be an SSN obejct and we should have another column
# for "type" which can be "edges", "obs", or a prediction name
if (inherits(x, "SSN")) {
Expand All @@ -54,7 +54,7 @@ ssn_get_netgeometry <- function(x, netvars = "all", reformat = FALSE) {


if (inherits(x, "data.frame")) {
x <- x$netgeometry
x <- x$netgeom
}

## delete "network"
Expand Down
Loading

0 comments on commit aea3909

Please sign in to comment.