Skip to content

Commit

Permalink
autoimport
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiste committed Feb 9, 2025
1 parent ee322ca commit aea4e67
Show file tree
Hide file tree
Showing 18 changed files with 163 additions and 112 deletions.
35 changes: 25 additions & 10 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -126,29 +126,49 @@ importFrom(dplyr,as_tibble)
importFrom(dplyr,bind_rows)
importFrom(dplyr,filter)
importFrom(dplyr,full_join)
importFrom(dplyr,left_join)
importFrom(dplyr,mutate)
importFrom(dplyr,near)
importFrom(dplyr,pull)
importFrom(dplyr,rename)
importFrom(dplyr,select)
importFrom(dplyr,summarise)
importFrom(dplyr,ungroup)
importFrom(dplyr,tibble)
importFrom(expm,expm)
importFrom(expm,logm)
importFrom(ggforce,geom_circle)
importFrom(ggplot2,aes)
importFrom(ggplot2,annotate)
importFrom(ggplot2,coord_fixed)
importFrom(ggplot2,coord_map)
importFrom(ggplot2,element_blank)
importFrom(ggplot2,element_text)
importFrom(ggplot2,geom_abline)
importFrom(ggplot2,geom_contour)
importFrom(ggplot2,geom_contour_filled)
importFrom(ggplot2,geom_hline)
importFrom(ggplot2,geom_line)
importFrom(ggplot2,geom_path)
importFrom(ggplot2,geom_point)
importFrom(ggplot2,geom_polygon)
importFrom(ggplot2,geom_text)
importFrom(ggplot2,geom_tile)
importFrom(ggplot2,geom_vline)
importFrom(ggplot2,ggplot)
importFrom(ggplot2,labs)
importFrom(ggplot2,scale_x_continuous)
importFrom(ggplot2,scale_y_continuous)
importFrom(ggplot2,theme)
importFrom(ggplot2,theme_classic)
importFrom(grDevices,colorRamp)
importFrom(grDevices,gray)
importFrom(graphics,lines)
importFrom(graphics,points)
importFrom(graphics,segments)
importFrom(graphics,text)
importFrom(graphics,title)
importFrom(lubridate,as_datetime)
importFrom(plyr,.)
importFrom(plyr,rbind.fill)
importFrom(readxl,read_xlsx)
importFrom(rjson,fromJSON)
importFrom(rlang,check_installed)
importFrom(rotasym,d_vMF)
importFrom(rotasym,r_unif_sphere)
importFrom(rotasym,r_vMF)
Expand All @@ -161,12 +181,7 @@ importFrom(sf,st_make_grid)
importFrom(sf,st_transform)
importFrom(stats,aggregate)
importFrom(stats,qf)
importFrom(tectonicr,deg2rad)
importFrom(tectonicr,dist_greatcircle)
importFrom(tectonicr,rad2deg)
importFrom(tibble,as_tibble)
importFrom(tibble,tibble)
importFrom(tidyr,drop_na)
importFrom(tidyr,pivot_longer)
importFrom(tidyr,pivot_wider)
importFrom(tidyselect,starts_with)
157 changes: 79 additions & 78 deletions R/allmendinger.R
Original file line number Diff line number Diff line change
Expand Up @@ -120,84 +120,85 @@ CartToSph <- function(cn, ce, cd) {
}


#' calculates the mean vector for a given series of lines
#'
#' @param t,p numeric vectors of trends and plunges (in radians)
#'
#' @returns calculates the trend (trd) and plunge (plg) of the mean vector (in radians),
#' its normalized length, and Fisher statistics (concentration factor (conc),
#' 99 (d99) and 95 (d95) % uncertainty cones, in radians)
#' @export
#'
CalcMV <- function(t, p) {
# Number of lines
nlines <- length(t)

# Initialize the 3 direction cosines which contain the sums of the
# individual vectors (i.e. the coordinates of the resultant vector)
CNsum <- 0
CEsum <- 0
CDsum <- 0

# Now add up all the individual vectors
for (i in 1:nlines) {
cs <- SphToCart(t(i), p(i), 0)
cn <- cs[, 1]
ce <- cs[, 2]
cd <- cs[, 3]
CNsum <- CNsum + cn
CEsum <- CEsum + ce
CDsum <- CDsum + cd
}

# R is the length of the resultant vector and Rave is the length of
# the resultant vector normalized by the number of lines
R <- sqrt(CNsum * CNsum + CEsum * CEsum + CDsum * CDsum)
Rave <- R / nlines

# If Rave is lower than 0.1, the mean vector is insignificant, return error
if (Rave < 0.1) {
stop("Mean vector is insignificant")
} else {
# Divide the resultant vector by its length to get the average
# unit vector
CNsum <- CNsum / R
CEsum <- CEsum / R
CDsum <- CDsum / R

# Use the following 'if' statement if you want to convert the
# mean vector to the lower hemisphere
if (CDsum < 0) {
CNsum <- -CNsum
CEsum <- -CEsum
CDsum <- -CDsum
}

# Convert the mean vector from direction cosines to trend and plunge
vec <- CartToSph(CNsum, CEsum, CDsum)
trd <- vec[, 1]
plg <- vec[, 2]

# If there are enough measurements calculate the Fisher Statistics
# For more information on these statistics see Fisher et al. (1987)
if (R < nlines) {
if (nlines < 16) {
afact <- 1 - (1 / nlines)
conc <- (nlines / (nlines - R)) * afact^2
} else {
conc <- (nlines - 1) / (nlines - R)
}
}
if (Rave >= 0.65 && Rave < 1) {
afact <- 1 / 0.01
bfact <- 1 / (nlines - 1)
d99 <- acos(1 - ((nlines - R) / R) * (afact^bfact - 1.0))
afact <- 1 / 0.05
d95 <- acos(1 - ((nlines - R) / R) * (afact^bfact - 1.0))
}
}
cbind(trd, plg, Rave, conc, d99, d95)
}
#' #' calculates the mean vector for a given series of lines
#' #'
#' #' @param t,p numeric vectors of trends and plunges (in radians)
#' #'
#' #' @returns calculates the trend (trd) and plunge (plg) of the mean vector (in radians),
#' #' its normalized length, and Fisher statistics (concentration factor (conc),
#' #' 99 (d99) and 95 (d95) % uncertainty cones, in radians)
#' #' @export
#' #'
#' #' @importFrom shiny p
#' CalcMV <- function(t, p) {
#' # Number of lines
#' nlines <- length(t)
#'
#' # Initialize the 3 direction cosines which contain the sums of the
#' # individual vectors (i.e. the coordinates of the resultant vector)
#' CNsum <- 0
#' CEsum <- 0
#' CDsum <- 0
#'
#' # Now add up all the individual vectors
#' for (i in 1:nlines) {
#' cs <- SphToCart(t(i), p(i), 0)
#' cn <- cs[, 1]
#' ce <- cs[, 2]
#' cd <- cs[, 3]
#' CNsum <- CNsum + cn
#' CEsum <- CEsum + ce
#' CDsum <- CDsum + cd
#' }
#'
#' # R is the length of the resultant vector and Rave is the length of
#' # the resultant vector normalized by the number of lines
#' R <- sqrt(CNsum * CNsum + CEsum * CEsum + CDsum * CDsum)
#' Rave <- R / nlines
#'
#' # If Rave is lower than 0.1, the mean vector is insignificant, return error
#' if (Rave < 0.1) {
#' stop("Mean vector is insignificant")
#' } else {
#' # Divide the resultant vector by its length to get the average
#' # unit vector
#' CNsum <- CNsum / R
#' CEsum <- CEsum / R
#' CDsum <- CDsum / R
#'
#' # Use the following 'if' statement if you want to convert the
#' # mean vector to the lower hemisphere
#' if (CDsum < 0) {
#' CNsum <- -CNsum
#' CEsum <- -CEsum
#' CDsum <- -CDsum
#' }
#'
#' # Convert the mean vector from direction cosines to trend and plunge
#' vec <- CartToSph(CNsum, CEsum, CDsum)
#' trd <- vec[, 1]
#' plg <- vec[, 2]
#'
#' # If there are enough measurements calculate the Fisher Statistics
#' # For more information on these statistics see Fisher et al. (1987)
#' if (R < nlines) {
#' if (nlines < 16) {
#' afact <- 1 - (1 / nlines)
#' conc <- (nlines / (nlines - R)) * afact^2
#' } else {
#' conc <- (nlines - 1) / (nlines - R)
#' }
#' }
#' if (Rave >= 0.65 && Rave < 1) {
#' afact <- 1 / 0.01
#' bfact <- 1 / (nlines - 1)
#' d99 <- acos(1 - ((nlines - R) / R) * (afact^bfact - 1.0))
#' afact <- 1 / 0.05
#' d95 <- acos(1 - ((nlines - R) / R) * (afact^bfact - 1.0))
#' }
#' }
#' cbind(trd, plg, Rave, conc, d99, d95)
#' }



Expand Down
2 changes: 1 addition & 1 deletion R/alphabeta.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#'
#' @export
#'
#' @return object of calss `"plane"`. If gamma is specified, `"line"` object is
#' @return object of class `"plane"`. If gamma is specified, `"line"` object is
#' returned.
#'
#' @examples
Expand Down
2 changes: 1 addition & 1 deletion R/best_pole_ramsay.R
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ best_cone_ramsay <- function(x) {
}

#' @rdname best_pole
best_cone_ramsay <- function(x) {
best_cone_ramsay2 <- function(x) {
l <- m <- n <- l2 <- m2 <- lm <- ln <- mn <- numeric()
xsum <- data.frame(l = x[, 1], m = x[, 2], n = x[, 3]) |>
dplyr::mutate(
Expand Down
2 changes: 2 additions & 0 deletions R/contouring.R
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,8 @@ reshape_grid <- function(m, n) {

}

#' @importFrom graphics contour filled.contour
#' @importFrom stats xtabs
stereo_density <- function(x, nlevels = 20, ..., filled = FALSE, upper.hem = FALSE) {
d <- density_grid(x, ...)
d$grid <- fix_symm(d$grid)
Expand Down
3 changes: 1 addition & 2 deletions R/coordinates.R
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,6 @@ is.spherical <- function(l) {
#' }
#' @source Ramsay, 1967, p. 15-16
#' @name ramsay_coords
#' @importFrom tectonicr deg2rad rad2deg
#' @examples
#' \dontrun{
#' # Stereographic coordinates (angle notation):
Expand Down Expand Up @@ -357,7 +356,7 @@ cartesian_to_acosvec <- function(x) {
#' @export
acoscartesian_to_cartesian <- function(x) {
# tectonicr::deg2rad(x) |> cos()
x <- tectonicr::deg2rad(x)
x <- deg2rad(x)
cx <- cos(x[, 1])
cy <- cos(x[, 2])
cz <- cos(x[, 3])
Expand Down
3 changes: 3 additions & 0 deletions R/density.R
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ calculate_density <- function(x, sigma = NULL, sigma.norm = TRUE, trimzero = TRU
#' stereoplot()
#' stereo_density_contour(x)
#' stereo_point(x)
#' @importFrom graphics filled.contour
#' @importFrom stats xtabs
stereo_density_contour <- function(x, sigma = NULL, sigma.norm = TRUE, trimzero = TRUE, ngrid = 100, grid.type = c("gss", "sfs"), ...) {
# stereoplot()
densgrd <- calculate_density(
Expand Down Expand Up @@ -192,6 +194,7 @@ blank_grid <- function(n = 3000, ...) {
}
#'
#'
#' @importFrom dplyr near
project_data0 <- function(self, x, y, z) {
# Equal-area projection
d <- sqrt(x * x + y * y + z * z)
Expand Down
6 changes: 5 additions & 1 deletion R/gg_stereonet.R
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ ggl <- function(x, ..., d = 90, n = 1e3) {
#' @param ... optional graphical parameters passed to [ggplot2::geom_polygon()]
#'
#' @export
#' @importFrom ggplot2 aes geom_polygon
ggframe <- function(n = 1e4, color = "black", fill = NA, lwd = 1, ...) {
prim.lat <- rep(c(0), times = n)
prim.l1 <- seq(0, 180, length = n / 2)
Expand All @@ -189,6 +190,7 @@ ggframe <- function(n = 1e4, color = "black", fill = NA, lwd = 1, ...) {
geom_polygon(aes(x = prim.long, y = prim.lat), data = prim_df, color = color, fill = fill, lwd = lwd, ..., inherit.aes = FALSE)
}

#' @importFrom ggplot2 aes geom_path
ggstereo_grid <- function(d = 10, rot = 0, ...) {
x <- y <- group <- NULL
# small circles
Expand Down Expand Up @@ -235,7 +237,7 @@ ggstereo_grid <- function(d = 10, rot = 0, ...) {
#' @param ... argument passed to [ggplot2::geom_polygon()]
#'
#' @import ggplot2
#' @importFrom rlang check_installed
#' @importFrom ggplot2 aes annotate coord_map element_blank element_text ggplot scale_x_continuous scale_y_continuous theme
#'
#' @return ggplot
#' @export
Expand Down Expand Up @@ -389,6 +391,7 @@ NULL

#' @rdname ggstereocontour
#' @export
#' @importFrom ggplot2 aes geom_contour
geom_contour_stereo <- function(data, ngrid = 200, hw = NULL, optimal_bw = c("cross", "rot"), norm = FALSE, threshold = 0, ...) {
Long <- Lat <- Density <- NULL
xtot <- full_hem(data)
Expand All @@ -407,6 +410,7 @@ geom_contour_stereo <- function(data, ngrid = 200, hw = NULL, optimal_bw = c("cr

#' @rdname ggstereocontour
#' @export
#' @importFrom ggplot2 aes geom_contour_filled geom_tile
geom_contourf_stereo <- function(data, ngrid = 200, hw = NULL, optimal_bw = c("cross", "rot"), norm = FALSE, smooth = FALSE, threshold = 0, ...) {
Long <- Lat <- Density <- NULL
xtot <- full_hem(data)
Expand Down
17 changes: 12 additions & 5 deletions R/helper.R
Original file line number Diff line number Diff line change
Expand Up @@ -132,16 +132,23 @@ assign_col_binned <- function(x, breaks, pal = viridis::viridis, ...) {
named_cols
}

color_func <- function(x, pal = viridis::viridis) {
color_func0 <- colorRamp(do.call(pal, args = list(n = 10000)))
grDevices::rgb(color_func0(x) / 255)
#' @importFrom grDevices colorRamp
color_func <- function(x, pal = viridis::viridis, ...) {
color_func0 <- colorRamp(do.call(pal, args = list(n = 10000, ...)))

grDevices::rgb(color_func0(x, ...) / 255)
}

#' @rdname colorize
#' @export
legend_c <- function(breaks, title = NULL, pal = viridis::viridis) {
legend_c <- function(breaks, title = NULL, pal = viridis::viridis, ...) {
label_pos <- normalize(breaks)
legend_image <- grDevices::as.raster(matrix(color_func(seq(0, 1, .001)), ncol = 1))
legend_image <- grDevices::as.raster(
matrix(
color_func(seq(0, 1, .001), pal = pal, ...),
ncol = 1
)
)

graphics::par(new = TRUE)
graphics::layout(matrix(1, 1))
Expand Down
Loading

0 comments on commit aea4e67

Please sign in to comment.