Dear all; Many thanks for your replies. This was not homework. I apologize. Let me explain more. There is a dam constructed in a valley with the highest elevation of 1255 m. The area of its reservoir can be calculated by drawing a polygon around the water and it is known. I have the Digital Elevation Model (DEM) of the region (reservoir and its surrounding area). I have calculated the volume of the current reservoir (7e6 m3) using the following codes. library(raster) library(terra) library(exactextractr) library(dplyr) library(sf) # Calculate volume for polygon # Read the DEM raster file r <- rast("E:/...DEM.tif") # Read the polygon shapefile p <- st_read("E:/...Dam.shp")
r <- crop(r, extent(p)) r <- mask(r, p) # Extract the cells in each polygon and calculate the area of each cell x <- exact_extract(r, p, coverage_area = TRUE) # Extract polygon values as a dataframe x1 = as.data.frame(x[1]) head(x1) x1 = na.omit(x1) # Calculate the height above the minimum elevation in the polygon x1$Height = max(x1[,1]) - x1[,1] # Calculate the volume of each cell x1$Vol = x1[,2] * x1[,3] sum(x1$Vol) x2 = x1[,c(1,2,4)] x2 = sort(x2,'value') head(x2) x3 <- aggregate(Vol ~ value, data = x2, FUN = sum) x4 <- aggregate(coverage_area ~ value, data = x2, FUN = sum) x5 = cbind(x3, Area = x4[,2]) library(dplyr) x6 <- x5 %>% mutate(V_sum = cumsum(Vol)) %>% mutate(A_sum = cumsum(Area)) plot(x6$value~x6$V_sum) And I thought that it is possible to get the elevation for a specific volume by linear model between elevation and volume, as follow: # Get a linear model between elevation and the volume lm1 <- lm(value ~ V_sum, data = x6) d <- data.frame(V_sum = 14e6) # predict(lm1, newdata = d) But it is not possible through the LM. Now I want to know what would be the water level in the reservoir if the reservoir volume doubled or we adding a known volume to it? Also what would be the volume if the water level increases to 1250 m? I would be more than happy if you help me to do this. Sincerely On Mon, Apr 8, 2024 at 12:23 AM <avi.e.gr...@gmail.com> wrote: > John, > > Your reaction was what my original reaction was until I realized I had to > find out what a DEM file was and that contains enough of the kind of > depth-dimension data you describe albeit what may be a very irregular cross > section to calculate for areas and thence volumes. > > If I read it correctly, this can be a very real-world problem worthy of a > solution, such as in places like California where they had a tad more rain > than usual and some reservoirs may overflow. Someone else provided what > sounds like a mathematical algorithm but my guess is what is needed here is > perhaps less analytic since there may be no trivial way to create formulas > and take integrals and so on, but simply an approximate way to calculate > incremental volumes for each horizontal "slice" and keep adding or > subtracting them till you reach a target and then read off another variable > at that point such as depth. > > Some care must be taken as water level has to be relative to something and > many natural reservoirs have no unique bottom level. Some water may also be > stored underground and to the side and pour in if the level lowers or can > be > used to escape if the level rises. > > > -----Original Message----- > From: R-help <r-help-boun...@r-project.org> On Behalf Of Sorkin, John > Sent: Sunday, April 7, 2024 3:08 PM > To: Rui Barradas <ruipbarra...@sapo.pt>; javad bayat <j.bayat...@gmail.com > >; > R-help <R-help@r-project.org> > Subject: Re: [R] Question regarding reservoir volume and water level > > Aside from the fact that the original question might well be a class > exercise (or homework), the question is unanswerable given the data given > by > the original poster. One needs to know the dimensions of the reservoir, > above and below the current waterline. Are the sides, above and below the > waterline smooth? Is the region currently above the waterline that can > store > water a mirror image of the region below the waterline? Is the region above > the reservoir include a flood plane? Will the additional water go into the > flood plane? > > The lack of required detail in the question posed by the original poster > suggests that there are strong assumptions, assumptions that typically > would > be made in a class-room example or exercise. > > John > > John David Sorkin M.D., Ph.D. > Professor of Medicine, University of Maryland School of Medicine; > Associate Director for Biostatistics and Informatics, Baltimore VA Medical > Center Geriatrics Research, Education, and Clinical Center; > PI Biostatistics and Informatics Core, University of Maryland School of > Medicine Claude D. Pepper Older Americans Independence Center; > Senior Statistician University of Maryland Center for Vascular Research; > > Division of Gerontology and Paliative Care, > 10 North Greene Street > GRECC (BT/18/GR) > Baltimore, MD 21201-1524 > Cell phone 443-418-5382 > > > > > ________________________________________ > From: R-help <r-help-boun...@r-project.org> on behalf of Rui Barradas > <ruipbarra...@sapo.pt> > Sent: Sunday, April 7, 2024 10:53 AM > To: javad bayat; R-help > Subject: Re: [R] Question regarding reservoir volume and water level > > Às 13:27 de 07/04/2024, javad bayat escreveu: > > Dear all; > > I have a question about the water level of a reservoir, when the volume > > changed or doubled. > > There is a DEM file with the highest elevation 1267 m. The lowest > elevation > > is 1230 m. The current volume of the reservoir is 7,000,000 m3 at 1240 m. > > Now I want to know what would be the water level if the volume rises to > > 1250 m? or what would be the water level if the volume doubled > (14,000,000 > > m3)? > > > > Is there any way to write codes to do this in R? > > I would be more than happy if anyone could help me. > > Sincerely > > > > > > > > > > > > > > > > > Hello, > > This is a simple rule of three. > If you know the level l the argument doesn't need to be named but if you > know the volume v then it must be named. > > > water_level <- function(l, v, level = 1240, volume = 7e6) { > if(missing(v)) { > volume * l / level > } else level * v / volume > } > > lev <- 1250 > vol <- 14e6 > > water_level(l = lev) > #> [1] 7056452 > water_level(v = vol) > #> [1] 2480 > > > Hope this helps, > > Rui Barradas > > > -- > Este e-mail foi analisado pelo software antivírus AVG para verificar a > presença de vírus. > http://www.avg.com/ > > ______________________________________________ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.r-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > > ______________________________________________ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > > -- Best Regards Javad Bayat M.Sc. Environment Engineering Alternative Mail: bayat...@yahoo.com [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.