USGS-R/Rainmaker

RMevents based on time not rain

Closed this issue · 1 comments

We are trying to get Rainmaker to work with an input file that does not have zeros, just minute precipitation data where data rainfall was recorded.

Rainmaker's RMevents function currently uses 0's in the rainfall column between events (even during is fine) to determine the beginning and end of each event.

The narrative goes something like "if Rain is greater than 0 then start counting tips while looking for the next 0, if the time between that 0 and and the next tip is greater than the interevent period, stop the first storm and start the next." It goes on to check if the number of tips accumulated during a 'storm' meets the minimum requirement for a storm and edits out the small events depending on the "rainthresh".

Rainmaker doesn't know to start/stop storms when the file only has data when rainfall was recorded, so it isn't creating the 'storms' column when you run the PrecipEvents line.

We'd like rainmaker to use time instead of rain to determine the start and end of events.

Steve Attempted to fix this by modifying the following line in the RMevents function around lines 48-50:

      # Search for end of event period
      if(df[i,rain]==0 | difftime(df[i,time],df[StartDryRow,time],units="secs")>ieSec) {

While the fix seemed to mostly work, when I tested it with a file that does have zeroes, and did work with the older version, I did not get the same start times and the new version found a couple more events.

all the files needed to recreate this are in my FTP depot:

#' RMEVENTS TEST
#' Load files:
#' 
source("L:/Carvin/RRainmaker/RRainmaker.R") #loads the older version of RMEvents, and other rainmaker functions
setwd("L:/Carvin/RRainmaker")
site <- "PEACEFUL"
RDB <- read.csv(file = paste(site,".rdb",sep=""),sep = "",skip = 3,col.names = c("site.dd", "YEAR", "MONTH", "DAY", "MINUTE", "rain"))
#'
#'RMprep:        Prepare data: transform to proper date format and change column names
#'
PrecipPrep.v1 <- RMprep(df=RDB,prep.type = 1,date.type = 4) #For use with the older version of RMEvents
PrecipPrep.test <- RMprep(df=RDB,prep.type = 1,date.type = 4) #To test the new version
#'
#'RMevents:      Define events based on unit value rainfall and user defined parameters 
PrecipEvents.v1 <- as.data.frame(RMevents(df = PrecipPrep.v1,ieHr = 2,rainthresh = 0.1,rain = "rain",time = "pdate")[1])

source("L:/Carvin/RRainmaker/fxn_RMevents2.R") #loads the new version of RMEvents for testing
PrecipEvents.test <- as.data.frame(RMevents(df = PrecipPrep.test,ieHr = 2,rainthresh = 0.1,rain = "rain",time = "pdate")[1])

#'Compare the two data frames:
match(x=PrecipEvents.test$rain, table=PrecipEvents.v1$storms2.rain) #The NA's show where the two rain-depth columns do not match
match(x=PrecipEvents.test$StartDate, table=PrecipEvents.v1$storms2.StartDate) #The NA's show that the start time is always different
#'
#'The startdate and enddate times do not match. The number of observations and rain amounts also differ. 

The RMevents_sko function resolved this issue.