HARPgroup / HARParchive

This repo houses HARP code development items, resources, and intermediate work products.
1 stars 0 forks source link

FTABLE Cross -section diagram #786

Open rburghol opened 1 year ago

rburghol commented 1 year ago

Chat GPT attempts

chatGPT: library(ggplot2)

plot_xsection <- function(ftable, river_col = "rno", x_col = "rdis", y_col = "elev",
                           group_col = NULL, title = NULL, xlab = NULL, ylab = NULL,
                           ylim = NULL, color = NULL, size = NULL, alpha = NULL) {

  # Convert ftable to a data frame
  df <- as.data.frame(ftable)

  # Subset to necessary columns
  df <- df[, c(river_col, x_col, y_col)]

  # Set group column if provided
  if (!is.null(group_col)) {
    df$group <- df[, group_col]
  }

  # Plot the cross section
  ggplot(df, aes_string(x_col, y_col, group = "group", color = "group", size = "size", alpha = "alpha")) +
    geom_line() +
    labs(title = title, x = xlab, y = ylab) +
    scale_y_reverse(limits = ylim) +
    scale_color_manual(values = color) +
    scale_size_continuous(range = size) +
    scale_alpha_continuous(range = alpha) +
    theme_classic()

}
megpritch commented 1 year ago

A Proper persp() Plot!

@rburghol - With this code chunk I was able to get a pretty good persp() plot:

x <- c(ftable$x, -ftable$x[-1]) #make sure there aren't 2 rows where x=0 --> otherwise it will not plot
y <- seq(0, clength, length.out=length(x))
z <- c(ftable$depth,ftable$depth)

pair <- cbind(x, z)
pair <- pair[order(x),] #ascending order
x <- pair[,1]
z <- pair[,-1]

for (i in 1:(length(x)-1)){
  z <- cbind(z, pair[,-1])
}
colnames(z) <- y #to conceptualize data
rownames(z) <- x

persp(x, y, z, theta = 10, phi = 15, expand = .2, col = "lightblue", axes=TRUE, nticks=8, 
  ticktype="detailed", scale=TRUE, shade=0.75, border=NA, d=0.6, r=4.5)
image image image
rburghol commented 1 year ago

OK @megpritch now this is some tidy code! Very efficient way of removing the extra zero. That channel look like a great start, though I will look closer tomorrow and try your code out to see what I can see about the oddities you identified in the floodplain.

Thanks for pushing this forward!

megpritch commented 1 year ago

@durelles @jdkleiner - It is confirmed that the newer FTABLEs show the floodplain extending out rather than disregarding the floodplain as older FTABLEs did.

This is Black Creek Reservoir:

image
durelles commented 1 year ago

Awesome!

On Wed, Apr 26, 2023 at 6:22 PM megpritch @.***> wrote:

@durelles https://github.com/durelles @jdkleiner https://github.com/jdkleiner - It is confirmed that the newer FTABLEs show the floodplain extending out rather than disregarding the floodplain as older FTABLEs did.

This is Black Creek Reservoir: [image: image] https://user-images.githubusercontent.com/104520247/234715081-f58a4417-127b-47a7-9840-ffff012ce41a.png

— Reply to this email directly, view it on GitHub https://github.com/HARPgroup/HARParchive/issues/786#issuecomment-1524113636, or unsubscribe https://github.com/notifications/unsubscribe-auth/AC4K425LMFT7SUIP4V2IMQTXDGNYXANCNFSM6AAAAAAWUR2GUM . You are receiving this because you were mentioned.Message ID: @.***>

--

Durelle Scott, Associate Professor and Assistant Department Head for Undergraduate Studies

Virginia Tech | Biological Systems Engineering Blacksburg, VA 24061 (540) 231-2449 | @.***

rburghol commented 1 year ago

This looks great! Thanks @megpritch !!