Closed ThamiFontoura closed 1 year ago
Hi There -- it looks like you've come across an awkward error message.
Really, the function should just fail with the warning:
Every year as defined by the yearType argument must be complete,
the following years have missing data: 2015,2101
If you change
floodThresh <- get_peakThreshold(dailyQdf[c("date","discharge")],
annualpeakflow[c("date","discharge")])
to
floodThresh <- get_peakThreshold(dailyQdf[c("date","discharge")],
annualpeakflow[c("date","discharge")],
yearType = "calendar")
It will function. If you want a yearType = "wateryear" to work, you'll have to provide complete data for the water year you want to run.
Hi There -- it looks like you've come across an awkward error message.
Really, the function should just fail with the warning:
Every year as defined by the yearType argument must be complete, the following years have missing data: 2015,2101
If you change
floodThresh <- get_peakThreshold(dailyQdf[c("date","discharge")], annualpeakflow[c("date","discharge")])
to
floodThresh <- get_peakThreshold(dailyQdf[c("date","discharge")], annualpeakflow[c("date","discharge")], yearType = "calendar")
It will function. If you want a yearType = "wateryear" to work, you'll have to provide complete data for the water year you want to run.
Hello, It works , in part. Is still occurring the error:
Error in get_peakThreshold(dailyQdf[c("date", "discharge")], annualpeakflow[c("date", : First column of peakValues must contain a vector of class date. Second column of peakValues must contain a vector of class numeric. In addition: Warning messages: 1: In col1_class != "Date" && col2_class != "numeric" : 'length(x) = 3 > 1' in coercion to 'logical(1)' 2: In col1_class != "Date" && col2_class != "numeric" : 'length(x) = 3 > 1' in coercion to 'logical(1)'
Do you mind constructing a reprex like below? I see it working with the reprex pasted further down.
reprex::reprex({
#code goes here
}, wd = "work/directory/", session_info = TRUE)
library(EflowStats)
#> Registered S3 method overwritten by 'quantmod':
#> method from
#> as.zoo.data.frame zoo
#> USGS Research Package: https://owi.usgs.gov/R/packages.html#research
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
f <- "ssp245eflowstats.csv"
Qdf = read.csv(f)
#column Date as class Date
Qdf["Date"] <- seq(as.Date("2015-01-01"), as.Date("2100-12-31"), by=1)
#Check data for completeness
dailyQdf <- validate_data(Qdf[c("Date","Numeric")], yearType="calendar")
annualpeakflow <- dailyQdf %>% group_by(year_val) %>% filter(discharge == max(discharge))
annualpeakflow <- annualpeakflow[-c(6,7,64),]
x <- dailyQdf[c("date","discharge")]
y <- as.data.frame(annualpeakflow[c("date","discharge")])
get_peakThreshold(x, y, yearType = "calendar")
#> [1] 607.41
Created on 2023-02-04 with reprex v2.0.2
Done! Thank you
Did someone have this error? I used peak flow values extracted with a code in R package and the columns are already with class Date and numeric, but the ERROR is still occurring.
CODE:
pasta.dados = "/Users/thamirisfontoura/Documents/RStudio/Eflowstats" setwd(pasta.dados) Qdf = read.csv("ssp245eflowstats.csv")
column Date as class Date
Qdf["Date"] <- seq(as.Date("2015-01-01"), as.Date("2100-12-31"), by=1) head(Qdf) tail(Qdf)
obtaining peakflow data
----message=FALSE, echo=TRUE, eval=FALSE--------------------------------
library(dataRetrieval) library(EflowStats)
Check data for completeness
dailyQdf <- validate_data(Qdf[c("Date","Numeric")],yearType="calendar")
annualpeakflow <- dailyQdf %>% group_by(year_val) %>% filter(discharge == max(discharge))
delete repeated data
annualpeakflow <- annualpeakflow[-c(6,7,64),] as.data.frame(annualpeakflow)
Get drainage area
drainageArea <- 139.77
annualpeakflow %>% mutate(date=as.Date(date, format = "%Y.%m.%d"))
Get flood recurence threshold
floodThresh <- get_peakThreshold(dailyQdf[c("date","discharge")], annualpeakflow[c("date","discharge")])
Calculate all hit stats
calc_allHITOut <- calc_allHIT(dailyQClean, drainArea=drainageArea, floodThreshold=floodThresh)
Calculate mag7 stats
magnifStatsOut <- calc_magnifSeven(dailyQClean,yearType="water",digits=3)
ERROR:
Error in get_peakThreshold(dailyQdf[c("date", "discharge")], annualpeakflow[c("date", : First column of peakValues must contain a vector of class date. Second column of peakValues must contain a vector of class numeric. In addition: Warning messages: 1: In validate_data(x, yearType) : Every year as defined by the yearType argument must be complete, the following years have missing data: 2015,2101 2: In col1_class != "Date" && col2_class != "numeric" : 'length(x) = 3 > 1' in coercion to 'logical(1)' 3: In col1_class != "Date" && col2_class != "numeric" : 'length(x) = 3 > 1' in coercion to 'logical(1)'