BoulderCodeHub / RWDataPlyr

R package to read and manipulate data from RiverWareTM
3 stars 5 forks source link

Add in an appendIC function #47

Open rabutler opened 7 years ago

rabutler commented 7 years ago

Need a function to append initial conditions onto the data frame.

Review Process-CRSS-Res, and the data request from 2017-02-23 for different use cases.

rabutler commented 7 years ago

After making this, we can edit BoulderCodeHub/Process-CRSS-Res to use this function

rabutler commented 7 years ago

appending the initial conditions is really simplistic once you have the i.c.: just use dplyr::bind_rows()

getting the i.c. is the more complex piece and depends on:

getting the i.c. is something that should be handled in CRSSIO

rabutler-usbr commented 5 years ago

This would still be helpful to have. It would be good to get the initial conditions once, and then be able to add them for all traces.

Ex:

mead_ond <- c(199.8733262, 252.8480009, 201.2420738)
mohave_ond <- c(81.7275338, 67.26763196, 48.04841081)
havasu_ond <- c(30.72901396, 24.5545258, 19.24265869)

mtom_ond <- data.frame(
  Year = 2019,
  Month = rep(month.name[10:12], 3),
  Scenario = "dnf_dcp",
  Variable = c(rep("mead_energy", 3), rep("mohave_energy", 3), rep("havasu_energy", 3)),
  Value = c(mead_ond, mohave_ond, havasu_ond)
)

n <- nrow(mtom_ond)

mtom_ond <- bind_rows(replicate(3, mtom_ond, simplify = FALSE))

mtom_ond$TraceNumber <- as.vector(t(replicate(n, 1:3 , simplify = TRUE)))

Also consider that you may want to add the same/different initial conditions for different Scenarios

rabutler-usbr commented 5 years ago

Also, see https://stackoverflow.com/questions/8753531/repeat-data-frame-n-times for different ways of doing this that may be faster than bind_rows()